opendilab / DI-engine

OpenDILab Decision AI Engine
https://di-engine-docs.readthedocs.io
Apache License 2.0
2.79k stars 348 forks source link

record a video #770

Closed zhixiongzh closed 5 months ago

zhixiongzh commented 5 months ago

I follow the tutorial to record a video using the following code

from easydict import EasyDict
from dizoo.mujoco.envs import MujocoEnv
env = MujocoEnv(EasyDict({'env_id': 'Hoopper-v3' }))
env.enable_save_replay(replay_path='./video')
obs = env.reset()
while True:
    action = env.random_action()
    timestep = env.step(action)
    if timestep.done:
        print('Episode is over, eval episode return is: {}'.format(timestep.info['eval_episode_return']))
        break

but met the error below

Traceback (most recent call last):
  File "store_video_mujoco.py", line 20, in <module>
    env = MujocoEnv(EasyDict({'env_id': 'Hoopper-v3' }))
  File "/home/myuser/.conda/envs/si_mujoco/lib/python3.8/site-packages/dizoo/mujoco/envs/mujoco_env.py", line 37, in __init__
    self._action_clip = cfg.action_clip
AttributeError: 'EasyDict' object has no attribute 'action_clip'

so I modify the code such that

config = MujocoEnv.default_config()
config.env_id="Hopper-v3"
env = MujocoEnv(config)
env.enable_save_replay(replay_path='./video')
obs = env.reset()
while True:
    action = env.random_action()
    timestep = env.step(action)
    if timestep.done:
        print('Episode is over, eval episode return is: {}'.format(timestep.info['eval_episode_return']))
        break

there is still an error

Unknown encoder 'libx264'
ERROR: VideoRecorder encoder failed: None
ERROR: VideoRecorder encoder failed: None
ERROR: VideoRecorder encoder failed: None
ERROR: VideoRecorder encoder failed: None
ERROR: VideoRecorder encoder exited with status 1
Episode is over, eval episode return is: 15.903695570099208

Could I ask how to fix this?

zhixiongzh commented 5 months ago

I solve this by removing the ffmpeg packge from conda environment, refer to this

zjowowen commented 5 months ago

Hi, thanks for your information. We will fix the errors in the document soon.

For installing rendering related dependencies, please use 'pip install -e .[common_env,video]'. For installing OpenGL related dependencies, please refer to installation guide in dockerfile https://github.com/opendilab/DI-engine/blob/main/docker/Dockerfile.env#L14.