0

I am trying to capture and save video from OpenAI Gymnasium.

In Google Collab, this code works:

!pip install gymnasium
!pip install moviepy

import gymnasium as gym
env = gym.make("CartPole-v1", render_mode='rgb_array')
env = gym.wrappers.RecordVideo(env, 'vidcap')

observation, info = env.reset(seed=42)
for step in range(100):
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)

    if terminated or truncated:
        observation, info = env.reset()
env.close()
env.reset

(although I get two videos, for some reason)

However, in Anaconda (2.1.4), the exact same code fails; it appears to start to write the video, but then throws an error. The error is lengthy, but shows the line ---> 88 '-r', '%.02f' % fps, and ends with: TypeError: must be real number, not NoneType.

Reading a previous answer here: Can't set the frame rate when recording a video with VecVideoRecorder

...I am suspicious that it wants (but is not getting) a framerate for the video. However, nothing I have tried has enabled me to set the framerate. I have tried each of these lines of code:

#env.metadata["video.frames_per_second"] = 4         #works in Colab
#env.metadata["render_fps"] = 4                      #works in Colab
#env.metadata['video.fps'] = 4
#env.metadata.get("render_fps", 4)
#env.metadata['video.frames_per_second']

...but although some of them work in Colab, none of them work in Anaconda.

If anyone knows how to make this work, I would be very thankful.

0 Answers0