我正在尝试使用
RecordVideo
包装器保存代理与其环境交互的视频。我无法让它与 render_mode
作为 rgb_array
或 rgb_array_list
一起工作。以下是我尝试保存视频的方式:
def record_video(env, agent, video_path):
env = gym.wrappers.RecordVideo(env, video_path)
state, _ = env.reset()
done = False
while not done:
action = agent.select_greedy_action(state)
next_state, reward, terminated, truncated, _ = env.step(action)
done = terminated or truncated
if terminated:
next_state = None
state = next_state
env.close()
env = gym.make("CartPole-v1", render_mode="rgb_array")
record_video(env, my_agent, "videos")
当使用任何一种模式时,我从 moviepy 中的 ffmpeg 得到以下错误:
77 self.ext = self.filename.split(".")[-1]
79 # order is important
80 cmd = [
81 get_setting("FFMPEG_BINARY"),
82 '-y',
83 '-loglevel', 'error' if logfile == sp.PIPE else 'info',
84 '-f', 'rawvideo',
85 '-vcodec', 'rawvideo',
86 '-s', '%dx%d' % (size[0], size[1]),
87 '-pix_fmt', 'rgba' if withmask else 'rgb24',
---> 88 '-r', '%.02f' % fps,
89 '-an', '-i', '-'
90 ]
91 if audiofile is not None:
92 cmd.extend([
93 '-i', audiofile,
94 '-acodec', 'copy'
95 ])
TypeError: must be real number, not NoneType
This stackover flow post 显示了一个类似的错误,该错误显然已在 moviepy 1.0.3 中修复,但是我目前安装了 moviepy 1.0.3。安装的gymnasium版本是0.28.1.
我也尝试过使用 Blackjack 环境并遇到同样的问题。
这是一个需要报告的错误还是我的实现不正确?