rohanpsingh / mujoco-python-viewer

Simple renderer for use with MuJoCo (>=2.1.2) Python Bindings.
BSD 2-Clause "Simplified" License
163 stars 24 forks source link

How to record simulation movies? #26

Open miyukin73 opened 1 year ago

miyukin73 commented 1 year ago

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.

rpapallas commented 1 year ago

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.
saneeeee commented 1 year ago

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