diff --git a/docs/wrappers.md b/docs/wrappers.md index 8f3ae1a85..639d96564 100644 --- a/docs/wrappers.md +++ b/docs/wrappers.md @@ -69,8 +69,39 @@ Gym includes numerous wrappers for environments that include preprocessing and v `RecordEpisodeStatistic(env)` [text] * Needs review (including for good assertion messages and test coverage) -`RecordVideo(env, ...)` [text] -* https://github.com/openai/gym/pull/2300 +`RecordVideo(env, video_folder, record_video_trigger, video_length=0, name_prefix="rl-video")` [text] + +The `RecordVideo` is a lightweight `gym.Wrapper` that helps recording videos. See the following +code as an example. + +```python +import gym +env = gym.make("CartPole-v1") +env = gym.wrappers.RecordVideo(env, "videos", record_video_trigger=lambda x: x % 100 == 0) +observation = env.reset() +for _ in range(1000): + env.render() + action = env.action_space.sample() # your agent here (this takes random actions) + observation, reward, done, info = env.step(action) + + if done: + observation = env.reset() +env.close() +``` + +To use it, you need to specify the `video_folder` as the storing location and +`record_video_trigger` as a frequency at which you want to record. + +There are two modes of video the recording: +1. Episodic mode. + * By default `video_length=0` means the wrapper will record *episodic* videos: it will keep + record the frames until the env returns `done=True`. +2. Fixed-interval mode. + * By tuning `video_length` such as `video_length=100`, the wrapper will record exactly 100 frames + for every videos the wrapper creates. + +Lastly the `name_prefix` allows you to customize the name of the videos. + `TimeLimit(env, max_episode_steps)` [text] * Needs review (including for good assertion messages and test coverage) diff --git a/gym/wrappers/monitor.py b/gym/wrappers/monitor.py index 0e7d76ae5..fceeb538d 100644 --- a/gym/wrappers/monitor.py +++ b/gym/wrappers/monitor.py @@ -4,6 +4,7 @@ import os import numpy as np import gym +import warnings from gym import Wrapper from gym import error, version, logger from gym.wrappers.monitoring import stats_recorder, video_recorder @@ -27,6 +28,9 @@ class Monitor(Wrapper): mode=None, ): super(Monitor, self).__init__(env) + warnings.warn( + "The Monitor wrapper is being deprecated in favor of gym.wrappers.RecordVideo and gym.wrappers.RecordEpisodeStatistics (see https://github.com/openai/gym/issues/2297)" + ) self.videos = []