mujoco-python-viewer icon indicating copy to clipboard operation
mujoco-python-viewer copied to clipboard

How to record simulation movies?

Open miyukin73 opened this issue 3 years ago • 2 comments

Hello,

I am new to Mujoco but I could take a screenshot by referring to your program! Thank you very much.

However, I did not know how to take a video and would like to know how to do so.

I am sorry to trouble you with this, but thank you in advance for your time.

Thank you in advance.

miyukin73 avatar Sep 30 '22 02:09 miyukin73

I don't think this is supported in this library currently. What I have been doing is to use an external tool that records my screen and just specify the MuJoCo window as the area to record. I know this can't be done asynchronously, but it's an option.

You could technically save multiple screenshots and bind them into a video (that's what a video is), but it will require some extra work on your part. But you could create a directory per video you want to record, save multiple screenshots (30fps for example) in there, then use ffmpeg to compile the pictures to a video. All this can be done in a bash script or even in Python if you wanted to:

  1. Save screenshots to dir
  2. Use subprocess.Popen to execute the ffmpeg command to compile to video.
  3. Delete the screenshots after the video is being created.

rpapallas avatar Dec 09 '22 09:12 rpapallas

You can collect frames to an array with offscreen rendering and produce a video from the array using cv2.

saneeeee avatar Mar 30 '23 05:03 saneeeee