Skip to content

Commit

Permalink
Add fps argument to RecordVideoV0 (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
younik authored May 14, 2023
1 parent c4f67b9 commit 5ef3f86
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 5ef3f86

Please sign in to comment.