Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--capture_video crashes because fps is not set #470

Open
3 tasks done
stefanbschneider opened this issue Jul 12, 2024 · 0 comments
Open
3 tasks done

--capture_video crashes because fps is not set #470

stefanbschneider opened this issue Jul 12, 2024 · 0 comments

Comments

@stefanbschneider
Copy link

stefanbschneider commented Jul 12, 2024

Problem Description

I'm trying to render a video as described in the docs, by running

python cleanrl/ppo.py \
    --seed 1 \
    --env-id CartPole-v0 \
    --total-timesteps 50000 \
    --capture_video

Unfortunately, it crashes with

Traceback (most recent call last):
  File "..../cleanrl/cleanrl/ppo.py", line 209, in <module>
    next_obs, reward, terminations, truncations, infos = envs.step(action.cpu().numpy())
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/gymnasium/vector/vector_env.py", line 203, in step
    return self.step_wait()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/gymnasium/vector/sync_vector_env.py", line 149, in step_wait
    ) = env.step(action)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/gymnasium/wrappers/record_episode_statistics.py", line 89, in step
    ) = self.env.step(action)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/gymnasium/wrappers/record_video.py", line 180, in step
    self.close_video_recorder()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/gymnasium/wrappers/record_video.py", line 193, in close_video_recorder
    self.video_recorder.close()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/gymnasium/wrappers/monitoring/video_recorder.py", line 161, in close
    clip.write_videofile(self.path, logger=moviepy_logger)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/moviepy/decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/moviepy/video/VideoClip.py", line 300, in write_videofile
    ffmpeg_write_video(self, filename, fps, codec,
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_writer.py", line 213, in ffmpeg_write_video
    with FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,
  File "/opt/homebrew/Caskroom/miniforge/base/envs/rl/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_writer.py", line 88, in __init__
    '-r', '%.02f' % fps,
TypeError: must be real number, not NoneType

I'm on MacOS (M1 Mac) and installed FFMPEG via brew.

Checklist

Current Behavior

Video rendering crashes with TypeError: must be real number, not NoneType when using --capture_video. See traceback above.

Expected Behavior

Video rendering works without crashing and renders the video.

Possible Solution

Apparently, fps defaults to None and crashes. Since the callstack is quite deep, I'm not sure where fps could be set. I did not find an argument in CleanRL - ideally, it should default to a sensible value without setting it manually.

At least in gym, there was a default of fps 30: https://github.com/openai/gym/blob/0.26.2/gym/wrappers/monitoring/video_recorder.py#L91
Not sure about gymnasium.

Steps to Reproduce

  1. Install CleanRL
  2. Run the command above, which is copied from the docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant