Table of Contents

Class Video

Namespace
Gym.Utils
Assembly
Gym.dll

Gymnasium's gymnasium.utils.save_video: the default recording schedule, and saving videos from a list of frames by episode and step triggers.

public static class Video
Inheritance
Video
Inherited Members

Methods

CappedCubicVideoSchedule(long)

The default episode trigger (capped_cubic_video_schedule): episodes 0, 1, 8, 27, ..., 729 (the cubes below 1000), then every 1000th.

public static bool CappedCubicVideoSchedule(long episodeId)

Parameters

episodeId long

The episode number.

Returns

bool

Whether to record that episode.

Remarks

int(round(episode_id ** (1.0 / 3))) ** 3 == episode_id in Python's float arithmetic: a negative id gives a complex power, which Python's round refuses, so it raises TypeError here too. Reference: gymnasium/utils/save_video.py.

Exceptions

TypeError

Thrown for a negative episode id (type complex doesn't define round method).

SaveVideo(IReadOnlyList<NDArray>, string, Func<long, bool>?, Func<long, bool>?, long?, string, long, long, string?, double?, IVideoWriter?)

Saves videos from an episode's frames (save_video): the whole episode (up to videoLength frames) when the episode trigger fires, and from every step whose step trigger fires a clip of videoLength frames (to the end without it), the reset's frame skipped.

public static void SaveVideo(IReadOnlyList<NDArray> frames, string videoFolder, Func<long, bool>? episodeTrigger = null, Func<long, bool>? stepTrigger = null, long? videoLength = null, string namePrefix = "rl-video", long episodeIndex = 0, long stepStartingIndex = 0, string? saveLogger = null, double? fps = null, IVideoWriter? videoWriter = null)

Parameters

frames IReadOnlyList<NDArray>

The episode's frames, the reset's first; they stay the caller's.

videoFolder string

The folder, created if needed.

episodeTrigger Func<long, bool>

Whether to save the episode; with no trigger at all, CappedCubicVideoSchedule(long).

stepTrigger Func<long, bool>

Whether to save a clip from a step.

videoLength long?

The frames per video, a Python slice end (negative counts from the end); null for all.

namePrefix string

The file name prefix.

episodeIndex long

The episode's number, for the trigger and the name.

stepStartingIndex long

The step number of the first frame after the reset's.

saveLogger string

moviepy's progress logger ("bar"); kept for Gymnasium's signature, the writers report nothing.

fps double?

The frame rate; moviepy needs it (or durations, which Gym.NET does not take).

videoWriter IVideoWriter

The encoder; null for PngVideoWriter.

Remarks

The paths are Gymnasium's, {abspath(video_folder)}/{name_prefix}-episode-{i} and ...-step-{i}, with the writer's extension instead of .mp4. Reference: gymnasium/utils/save_video.py.

Exceptions

ArgumentNullException

Thrown when frames or videoFolder is null.

ValueError

Thrown when a video is due and fps is null, with moviepy's message.