-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Cannot record the video by Wrappers.Monitor #1925
Comments
I ran the following script and it worked fine, are you actually stepping the environment?
|
Hi, I do get the video under "recording" directory. However, this video cannot be played successfully. Is there any solution to it? openaigym.video.0.28612.video000000.mp4 |
I have the same problem. I get a video but it's only 1kb. |
same issue... been trying to investigate it with no success... First enable logging: gym.logger.set_level(gym.logger.DEBUG) Logs:
So 20 timesteps were supposed to be written. In the destination folder we have a bunch of files. The video file is only 1kb and is unplayable. The code used: env = gym.make('CartPole-v0')
env = gym.wrappers.Monitor(env, "./vid", force=True)
env.seed(0)
for i_episode in range(1):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample() # take a random action
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
env.close() I have been able to successfully use the try:
probe = ffmpeg.probe('some non gym video path here')
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
width = int(video_stream['width'])
height = int(video_stream['height'])
print(width)
print(height)
except ffmpeg.Error as e:
if e.stdout:
print(e.stdout.decode('utf8'))
if e.stderr:
print(e.stderr.decode('utf8'))
exit(0) works OK. So the issue must be somewhere in gym wrapper or the arguments it is using to encode the video..
|
Actually nevermind.. I found the issue. It's a bug in the code. To fix the issue temporary (until devs fix it in public repo) you have to edit the The condition to write frames to the video file is never executed in the current gym library version. |
FWIW downgrading to |
This was fixed and merged into the master branch in #2139 |
Is the latest fix available in pip? I tried with 0.18 and I could not make it work so I downgraded to 0.17.3 as mentioned in @mwilbz comment and it worked. |
Confirmed same issue on latest version in pip. Manually removing the indent fixes the issue. |
If anyone else is using VideoRecorder as part of a larger logging framework, the following code patches frame = env.render("rgb_array")
self.video_recorder.encoder = gym.wrappers.monitoring.video_recorder.ImageEncoder(self.video_recorder.path, frame.shape, self.video_recorder.frames_per_sec, self.video_recorder.output_frames_per_sec)
def capture_frame(self, frame):
if not isinstance(frame, (np.ndarray, np.generic)):
raise gym.error.InvalidFrame('Wrong type {} for {} (must be np.ndarray or np.generic)'.format(type(frame), frame))
if frame.shape != self.frame_shape:
raise gym.error.InvalidFrame("Your frame has shape {}, but the VideoRecorder is configured for shape {}.".format(frame.shape, self.frame_shape))
if frame.dtype != np.uint8:
raise gym.error.InvalidFrame("Your frame has data type {}, but we require uint8 (i.e. RGB values from 0-255).".format(frame.dtype))
self.proc.stdin.write(frame.tobytes())
self.video_recorder.encoder.capture_frame = types.MethodType(capture_frame, self.video_recorder.encoder) Looks like this is already fixed in an above-linked PR, so hopefully won't be long before this dirty hack is removed. |
Is the fix allready available by pip? |
I just install gym 0.18.3 via pip. The issue is resolved. |
Fix is in master |
I just had a similar issue today: for me .json files were generated, but videos were not created / saved. Setting them manually, such that it would include |
I am trying to record the performance by the wrappers.Monitor. However, only .json files were generated, not any video files. No error was reported. How can I get the video file?
system
ubuntu 16, version 0.17.2,
code
env = gym.make('CartPole-v0') env = gym.wrappers.Monitor(env, "recording",force=True)
Thank you very much!
The text was updated successfully, but these errors were encountered: