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

Add fps argument to RecordVideoV0 #503

Merged
merged 3 commits into from
May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions gymnasium/experimental/wrappers/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class RecordVideoV0(
then every 1000 episodes.
By default, the recording will be stopped once reset is called. However, you can also create recordings of fixed
length (possibly spanning several episodes) by passing a strictly positive value for ``video_length``.
This wrapper uses the value `fps` from metadata as the number of frames per second;
if `fps` is not defined in metadata, the default value 30 is used.
"""

def __init__(
Expand All @@ -112,6 +110,7 @@ def __init__(
step_trigger: Callable[[int], bool] | None = None,
video_length: int = 0,
name_prefix: str = "rl-video",
fps: int | None = None,
disable_logger: bool = False,
):
"""Wrapper records videos of rollouts.
Expand All @@ -124,6 +123,8 @@ def __init__(
video_length (int): The length of recorded episodes. If 0, entire episodes are recorded.
Otherwise, snippets of the specified length are captured
name_prefix (str): Will be prepended to the filename of the recordings
fps (int): The frame per second in the video. The default value is the one specified in the environment metadata.
If the environment metadata doesn't specify `render_fps`, the value 30 is used.
disable_logger (bool): Whether to disable moviepy logger or not
"""
gym.utils.RecordConstructorArgs.__init__(
Expand Down Expand Up @@ -172,9 +173,11 @@ def capped_cubic_video_schedule(episode_id: int) -> bool:
)
os.makedirs(self.video_folder, exist_ok=True)

if fps is None:
fps = self.metadata.get("render_fps", 30)
self.frames_per_sec: int = fps
self.name_prefix: str = name_prefix
self._video_name: str | None = None
self.frames_per_sec: int = self.metadata.get("render_fps", 30)
self.video_length: int = video_length if video_length != 0 else float("inf")
self.recording: bool = False
self.recorded_frames: list[RenderFrame] = []
Expand Down