From 83bdef8254cd43e57f29dbc68cfae183e543f368 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Sat, 11 Jan 2020 12:19:42 -0800 Subject: [PATCH] add --mp4fps=30 command line parameter for ExampleBrowser (and using pybullet.connect(p.GUI, options="--mp4fps=30 --mp4=\"testvideo.mp4\"") --- .../CommonGraphicsAppInterface.h | 1 + .../ExampleBrowser/OpenGLExampleBrowser.cpp | 7 +++++++ examples/OpenGLWindow/SimpleOpenGL3App.cpp | 18 +++++++++++++----- examples/OpenGLWindow/SimpleOpenGL3App.h | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/CommonInterfaces/CommonGraphicsAppInterface.h b/examples/CommonInterfaces/CommonGraphicsAppInterface.h index acfaf478c..a3d9d3eac 100644 --- a/examples/CommonInterfaces/CommonGraphicsAppInterface.h +++ b/examples/CommonInterfaces/CommonGraphicsAppInterface.h @@ -93,6 +93,7 @@ struct CommonGraphicsApp if (blue) *blue = m_backgroundColorRGB[2]; } + virtual void setMp4Fps(int fps) {} virtual void setBackgroundColor(float red, float green, float blue) { m_backgroundColorRGB[0] = red; diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index fcfb1c05a..a76cdfe5b 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -921,6 +921,13 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) m_internalData->m_app = s_app; char* gVideoFileName = 0; args.GetCmdLineArgument("mp4", gVideoFileName); + int gVideoFps = 0; + args.GetCmdLineArgument("mp4fps", gVideoFps); + if (gVideoFps) + { + simpleApp->setMp4Fps(gVideoFps); + } + #ifndef NO_OPENGL3 if (gVideoFileName) simpleApp->dumpFramesToVideo(gVideoFileName); diff --git a/examples/OpenGLWindow/SimpleOpenGL3App.cpp b/examples/OpenGLWindow/SimpleOpenGL3App.cpp index 7293cc5b6..e3faf48d9 100644 --- a/examples/OpenGLWindow/SimpleOpenGL3App.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL3App.cpp @@ -66,6 +66,8 @@ struct SimpleInternalData int m_upAxis; //y=1 or z=2 is supported int m_customViewPortWidth; int m_customViewPortHeight; + int m_mp4Fps; + SimpleInternalData() : m_fontTextureId(0), m_largeFontTextureId(0), @@ -82,7 +84,8 @@ struct SimpleInternalData m_userPointer(0), m_upAxis(1), m_customViewPortWidth(-1), - m_customViewPortHeight(-1) + m_customViewPortHeight(-1), + m_mp4Fps(60) { } }; @@ -1089,6 +1092,11 @@ void SimpleOpenGL3App::swapBuffer() 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/ void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName) { @@ -1100,12 +1108,12 @@ void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName) #ifdef _WIN32 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", - width, height, mp4FileName); + m_data->m_mp4Fps, width, height, mp4FileName); - //sprintf(cmd, "ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - " - // "-y -crf 0 -b:v 1500000 -an -vcodec h264 -vf vflip %s", width, height, mp4FileName); + //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", m_data->m_mp4Fps, width, height, mp4FileName); #else sprintf(cmd, diff --git a/examples/OpenGLWindow/SimpleOpenGL3App.h b/examples/OpenGLWindow/SimpleOpenGL3App.h index cc9573c29..c90f47387 100644 --- a/examples/OpenGLWindow/SimpleOpenGL3App.h +++ b/examples/OpenGLWindow/SimpleOpenGL3App.h @@ -14,6 +14,7 @@ struct SimpleOpenGL3App : public CommonGraphicsApp class GLPrimitiveRenderer* m_primRenderer; class GLInstancingRenderer* m_instancingRenderer; 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);