From 8e0998dcbd396dd13e6b0e3e83a112f431906e7c Mon Sep 17 00:00:00 2001 From: Jan Margeta Date: Wed, 6 Mar 2024 01:36:13 +0100 Subject: [PATCH 1/8] Fix docs for the record command Renames the non-existent "render" command to "record" --- doc/programming/samples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index c62d6987..cd21511f 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -156,7 +156,7 @@ command-line arguments. For example, a 5 second animation at 60 frames per secon .. code-block:: Shell - render humanoid.xml 5 60 rgb.out + record humanoid.xml 5 60 rgb.out The default humanoid.xml model specifies offscreen rendering with 800x800 resolution. With this information in hand, we can compress the (large) raw date file into a playable movie file: From b475337e02387fe31cdbc6aa163aa204205a6ae9 Mon Sep 17 00:00:00 2001 From: Jan Margeta Date: Wed, 6 Mar 2024 14:34:15 +0100 Subject: [PATCH 2/8] Update docs of ffmpeg raw video conversion Makes it work well with the given humanoid example --- doc/programming/samples.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index cd21511f..f12c1124 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -162,9 +162,8 @@ The default humanoid.xml model specifies offscreen rendering with 800x800 resolu can compress the (large) raw date file into a playable movie file: .. code-block:: Shell - - ffmpeg -f rawvideo -pixel_format rgb24 -video_size 800x800 - -framerate 60 -i rgb.out -vf "vflip" video.mp4 + ffmpeg -f rawvideo -pixel_format rgb24 -video_size 2560x1440 + -framerate 60 -i rgb.out -vf "vflip,format=yuv420p" video.mp4 This sample can be compiled in three ways which differ in how the OpenGL context is created: using GLFW with an invisible window, using OSMesa, or using EGL. The latter two options are only available on Linux and are envoked by From fe2215384b1955ede1161e0134526a712b20b10a Mon Sep 17 00:00:00 2001 From: Jan Margeta Date: Wed, 6 Mar 2024 18:32:15 +0100 Subject: [PATCH 3/8] Update docs on the video recordings's resolution This fixes the the ffmpeg command to correspond to the default humanoid.xml resolution (2560x1440). --- doc/programming/samples.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index f12c1124..88cf07ca 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -150,16 +150,17 @@ This code sample simulates the passive dynamics of a given model, renders it off values, and saves them into a raw data file that can then be converted into a movie file with tools such as ffmpeg. The rendering is simplified compared to :ref:`simulate.cc ` because there is no user interaction, visualization options or timing; instead we simply render with the default settings as fast as possible. The dimensions and number of -multi-samples for the offscreen buffer are specified in the MuJoCo model, while the simulation duration, frames-per- -second to be rendered (usually much less than the physics simulation rate), and output file name are specified as -command-line arguments. For example, a 5 second animation at 60 frames per second is created with: +multi-samples for the offscreen buffer are specified in the MuJoCo model with the visual/global/{offwidth,offheight} +attributes, while the simulation duration, frames-per-second to be rendered (usually much less than the physics +simulation rate), and output file name are specified as command-line arguments. + .. code-block:: Shell record humanoid.xml 5 60 rgb.out -The default humanoid.xml model specifies offscreen rendering with 800x800 resolution. With this information in hand, we -can compress the (large) raw date file into a playable movie file: +The default humanoid.xml model specifies offscreen rendering with 2560x1440 resolution. With this information in hand, +we can compress the (large) raw date file into a playable movie file: .. code-block:: Shell ffmpeg -f rawvideo -pixel_format rgb24 -video_size 2560x1440 From be68f90190a5273328048fb1201f505c73b1c5b8 Mon Sep 17 00:00:00 2001 From: Jan Margeta Date: Wed, 6 Mar 2024 18:41:17 +0100 Subject: [PATCH 4/8] Make depth overlay in video recording optional Add docs for the record arguments --- doc/programming/samples.rst | 32 ++++++++++++++++++++++++++++++++ sample/record.cc | 23 +++++++++++++++-------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index 88cf07ca..34692ea5 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -154,6 +154,38 @@ multi-samples for the offscreen buffer are specified in the MuJoCo model with th attributes, while the simulation duration, frames-per-second to be rendered (usually much less than the physics simulation rate), and output file name are specified as command-line arguments. +.. code-block:: Shell + + record modelfile duration fps rgbfile [adddepth] + +Where the command line arguments are + +.. list-table:: + :width: 95% + :align: left + :widths: 1 1 5 + :header-rows: 1 + + * - Argument + - Default + - Meaning + * - ``modelfile`` + - (required) + - path to model + * - ``duration`` + - (required) + - duration of the recording in seconds + * - ``fps`` + - (required) + - number of frames per second + * - ``rgbfile`` + - (required) + - path to raw recording file + * - ``adddepth`` + - 1 + - add a depth image overlay to the lower left corner (0 for no overlay) + +For example, a 5 second animation at 60 frames per second is created with: .. code-block:: Shell diff --git a/sample/record.cc b/sample/record.cc index dd07411a..a445488a 100644 --- a/sample/record.cc +++ b/sample/record.cc @@ -217,8 +217,8 @@ void closeOpenGL(void) { int main(int argc, const char** argv) { // check command-line arguments - if (argc!=5) { - std::printf(" USAGE: record modelfile duration fps rgbfile\n"); + if (argc < 5 || argc > 6) { + std::printf(" USAGE: record modelfile duration fps rgbfile [adddepth]\n"); return 0; } @@ -255,6 +255,11 @@ int main(int argc, const char** argv) { mju_error("Could not open rgbfile for writing"); } + int adddepth = 1; + if (argc > 5 && std::sscanf(argv[5], "%d", &adddepth) != 1) { + mju_error("Invalid adddepth argument"); + } + // main loop double frametime = 0; int framecount = 0; @@ -276,12 +281,14 @@ int main(int argc, const char** argv) { mjr_readPixels(rgb, depth, viewport, &con); // insert subsampled depth image in lower-left corner of rgb image - const int NS = 3; // depth image sub-sampling - for (int r=0; r Date: Wed, 6 Mar 2024 19:01:25 +0100 Subject: [PATCH 5/8] Add an explicit note on recording resolution --- doc/programming/samples.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index 34692ea5..3f8fe8e6 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -198,6 +198,8 @@ we can compress the (large) raw date file into a playable movie file: ffmpeg -f rawvideo -pixel_format rgb24 -video_size 2560x1440 -framerate 60 -i rgb.out -vf "vflip,format=yuv420p" video.mp4 +Note that the offscreen rendering resolution of the model and ffmpeg's video_size must be the identical. + This sample can be compiled in three ways which differ in how the OpenGL context is created: using GLFW with an invisible window, using OSMesa, or using EGL. The latter two options are only available on Linux and are envoked by defining the symbols MJ_OSMESA or MJ_EGL when compiling record.cc. The functions ``initOpenGL`` and ``closeOpenGL`` From 548177d46c7938b6eaea4b2c5ca130c36a15a096 Mon Sep 17 00:00:00 2001 From: Jan Margeta Date: Wed, 6 Mar 2024 19:14:32 +0100 Subject: [PATCH 6/8] Rename depthoverlay argument --- doc/programming/samples.rst | 4 ++-- sample/record.cc | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index 3f8fe8e6..20ed86d7 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -156,7 +156,7 @@ simulation rate), and output file name are specified as command-line arguments. .. code-block:: Shell - record modelfile duration fps rgbfile [adddepth] + record modelfile duration fps rgbfile [depthoverlay] Where the command line arguments are @@ -181,7 +181,7 @@ Where the command line arguments are * - ``rgbfile`` - (required) - path to raw recording file - * - ``adddepth`` + * - ``depthoverlay`` - 1 - add a depth image overlay to the lower left corner (0 for no overlay) diff --git a/sample/record.cc b/sample/record.cc index a445488a..67aece09 100644 --- a/sample/record.cc +++ b/sample/record.cc @@ -218,7 +218,7 @@ void closeOpenGL(void) { int main(int argc, const char** argv) { // check command-line arguments if (argc < 5 || argc > 6) { - std::printf(" USAGE: record modelfile duration fps rgbfile [adddepth]\n"); + std::printf(" USAGE: record modelfile duration fps rgbfile [depthoverlay]\n"); return 0; } @@ -255,9 +255,9 @@ int main(int argc, const char** argv) { mju_error("Could not open rgbfile for writing"); } - int adddepth = 1; - if (argc > 5 && std::sscanf(argv[5], "%d", &adddepth) != 1) { - mju_error("Invalid adddepth argument"); + int depthoverlay = 1; + if (argc > 5 && std::sscanf(argv[5], "%d", &depthoverlay) != 1) { + mju_error("Invalid depthoverlay argument"); } // main loop @@ -281,7 +281,7 @@ int main(int argc, const char** argv) { mjr_readPixels(rgb, depth, viewport, &con); // insert subsampled depth image in lower-left corner of rgb image - if (adddepth) { + if (depthoverlay) { const int NS = 3; // depth image sub-sampling for (int r=0; r Date: Wed, 6 Mar 2024 19:46:51 +0100 Subject: [PATCH 7/8] Add url to relevant offscreen buffer attributes --- doc/programming/samples.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index 20ed86d7..5bd27e7f 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -150,7 +150,10 @@ This code sample simulates the passive dynamics of a given model, renders it off values, and saves them into a raw data file that can then be converted into a movie file with tools such as ffmpeg. The rendering is simplified compared to :ref:`simulate.cc ` because there is no user interaction, visualization options or timing; instead we simply render with the default settings as fast as possible. The dimensions and number of -multi-samples for the offscreen buffer are specified in the MuJoCo model with the visual/global/{offwidth,offheight} +multi-samples for the offscreen buffer are specified in the MuJoCo model with the +visual/global/{`offwidth `_, +`offheight `_} and +visual/quality/`offsamples `_ attributes, while the simulation duration, frames-per-second to be rendered (usually much less than the physics simulation rate), and output file name are specified as command-line arguments. @@ -191,8 +194,8 @@ For example, a 5 second animation at 60 frames per second is created with: record humanoid.xml 5 60 rgb.out -The default humanoid.xml model specifies offscreen rendering with 2560x1440 resolution. With this information in hand, -we can compress the (large) raw date file into a playable movie file: +The default `humanoid.xml `_ model specifies offscreen rendering with 2560x1440 resolution. With this information in hand, +we can compress the (large) raw data file into a playable movie file: .. code-block:: Shell ffmpeg -f rawvideo -pixel_format rgb24 -video_size 2560x1440 From 32dc89b425850dcf0208571365632617d276b121 Mon Sep 17 00:00:00 2001 From: Jan Margeta Date: Wed, 6 Mar 2024 21:17:43 +0100 Subject: [PATCH 8/8] Rename depthoverlay to adddepth --- doc/programming/samples.rst | 4 ++-- sample/record.cc | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/programming/samples.rst b/doc/programming/samples.rst index 5bd27e7f..2504b840 100644 --- a/doc/programming/samples.rst +++ b/doc/programming/samples.rst @@ -159,7 +159,7 @@ simulation rate), and output file name are specified as command-line arguments. .. code-block:: Shell - record modelfile duration fps rgbfile [depthoverlay] + record modelfile duration fps rgbfile [adddepth] Where the command line arguments are @@ -184,7 +184,7 @@ Where the command line arguments are * - ``rgbfile`` - (required) - path to raw recording file - * - ``depthoverlay`` + * - ``adddepth`` - 1 - add a depth image overlay to the lower left corner (0 for no overlay) diff --git a/sample/record.cc b/sample/record.cc index 67aece09..a445488a 100644 --- a/sample/record.cc +++ b/sample/record.cc @@ -218,7 +218,7 @@ void closeOpenGL(void) { int main(int argc, const char** argv) { // check command-line arguments if (argc < 5 || argc > 6) { - std::printf(" USAGE: record modelfile duration fps rgbfile [depthoverlay]\n"); + std::printf(" USAGE: record modelfile duration fps rgbfile [adddepth]\n"); return 0; } @@ -255,9 +255,9 @@ int main(int argc, const char** argv) { mju_error("Could not open rgbfile for writing"); } - int depthoverlay = 1; - if (argc > 5 && std::sscanf(argv[5], "%d", &depthoverlay) != 1) { - mju_error("Invalid depthoverlay argument"); + int adddepth = 1; + if (argc > 5 && std::sscanf(argv[5], "%d", &adddepth) != 1) { + mju_error("Invalid adddepth argument"); } // main loop @@ -281,7 +281,7 @@ int main(int argc, const char** argv) { mjr_readPixels(rgb, depth, viewport, &con); // insert subsampled depth image in lower-left corner of rgb image - if (depthoverlay) { + if (adddepth) { const int NS = 3; // depth image sub-sampling for (int r=0; r