add --mp4fps=30 command line parameter for ExampleBrowser (and using pybullet.connect(p.GUI, options="--mp4fps=30 --mp4=\"testvideo.mp4\"")

This commit is contained in:
Erwin Coumans
2020-01-11 12:19:42 -08:00
parent 8ebdf7862c
commit 83bdef8254
4 changed files with 22 additions and 5 deletions

View File

@@ -93,6 +93,7 @@ struct CommonGraphicsApp
if (blue) if (blue)
*blue = m_backgroundColorRGB[2]; *blue = m_backgroundColorRGB[2];
} }
virtual void setMp4Fps(int fps) {}
virtual void setBackgroundColor(float red, float green, float blue) virtual void setBackgroundColor(float red, float green, float blue)
{ {
m_backgroundColorRGB[0] = red; m_backgroundColorRGB[0] = red;

View File

@@ -921,6 +921,13 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
m_internalData->m_app = s_app; m_internalData->m_app = s_app;
char* gVideoFileName = 0; char* gVideoFileName = 0;
args.GetCmdLineArgument("mp4", gVideoFileName); args.GetCmdLineArgument("mp4", gVideoFileName);
int gVideoFps = 0;
args.GetCmdLineArgument("mp4fps", gVideoFps);
if (gVideoFps)
{
simpleApp->setMp4Fps(gVideoFps);
}
#ifndef NO_OPENGL3 #ifndef NO_OPENGL3
if (gVideoFileName) if (gVideoFileName)
simpleApp->dumpFramesToVideo(gVideoFileName); simpleApp->dumpFramesToVideo(gVideoFileName);

View File

@@ -66,6 +66,8 @@ struct SimpleInternalData
int m_upAxis; //y=1 or z=2 is supported int m_upAxis; //y=1 or z=2 is supported
int m_customViewPortWidth; int m_customViewPortWidth;
int m_customViewPortHeight; int m_customViewPortHeight;
int m_mp4Fps;
SimpleInternalData() SimpleInternalData()
: m_fontTextureId(0), : m_fontTextureId(0),
m_largeFontTextureId(0), m_largeFontTextureId(0),
@@ -82,7 +84,8 @@ struct SimpleInternalData
m_userPointer(0), m_userPointer(0),
m_upAxis(1), m_upAxis(1),
m_customViewPortWidth(-1), m_customViewPortWidth(-1),
m_customViewPortHeight(-1) m_customViewPortHeight(-1),
m_mp4Fps(60)
{ {
} }
}; };
@@ -1089,6 +1092,11 @@ void SimpleOpenGL3App::swapBuffer()
m_window->startRendering(); m_window->startRendering();
} }
void SimpleOpenGL3App::setMp4Fps(int fps)
{
m_data->m_mp4Fps = fps;
}
// see also http://blog.mmacklin.com/2013/06/11/real-time-video-capture-with-ffmpeg/ // see also http://blog.mmacklin.com/2013/06/11/real-time-video-capture-with-ffmpeg/
void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName) void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName)
{ {
@@ -1100,12 +1108,12 @@ void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName)
#ifdef _WIN32 #ifdef _WIN32
sprintf(cmd, sprintf(cmd,
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - " "ffmpeg -r %d -f rawvideo -pix_fmt rgba -s %dx%d -i - "
"-threads 0 -y -b:v 50000k -c:v libx264 -preset slow -crf 22 -an -pix_fmt yuv420p -vf vflip %s", "-threads 0 -y -b:v 50000k -c:v libx264 -preset slow -crf 22 -an -pix_fmt yuv420p -vf vflip %s",
width, height, mp4FileName); m_data->m_mp4Fps, width, height, mp4FileName);
//sprintf(cmd, "ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - " //sprintf(cmd, "ffmpeg -r %d -f rawvideo -pix_fmt rgba -s %dx%d -i - "
// "-y -crf 0 -b:v 1500000 -an -vcodec h264 -vf vflip %s", width, height, mp4FileName); // "-y -crf 0 -b:v 1500000 -an -vcodec h264 -vf vflip %s", m_data->m_mp4Fps, width, height, mp4FileName);
#else #else
sprintf(cmd, sprintf(cmd,

View File

@@ -14,6 +14,7 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
class GLPrimitiveRenderer* m_primRenderer; class GLPrimitiveRenderer* m_primRenderer;
class GLInstancingRenderer* m_instancingRenderer; class GLInstancingRenderer* m_instancingRenderer;
virtual void setBackgroundColor(float red, float green, float blue); virtual void setBackgroundColor(float red, float green, float blue);
virtual void setMp4Fps(int fps);
SimpleOpenGL3App(const char* title, int width, int height, bool allowRetina = true, int windowType = 0, int renderDevice = -1, int maxNumObjectCapacity = 128 * 1024, int maxShapeCapacityInBytes = 128 * 1024 * 1024); SimpleOpenGL3App(const char* title, int width, int height, bool allowRetina = true, int windowType = 0, int renderDevice = -1, int maxNumObjectCapacity = 128 * 1024, int maxShapeCapacityInBytes = 128 * 1024 * 1024);