Class Video
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
episodeIdlongThe 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
framesIReadOnlyList<NDArray>The episode's frames, the reset's first; they stay the caller's.
videoFolderstringThe folder, created if needed.
episodeTriggerFunc<long, bool>Whether to save the episode; with no trigger at all, CappedCubicVideoSchedule(long).
stepTriggerFunc<long, bool>Whether to save a clip from a step.
videoLengthlong?The frames per video, a Python slice end (negative counts from the end); null for all.
namePrefixstringThe file name prefix.
episodeIndexlongThe episode's number, for the trigger and the name.
stepStartingIndexlongThe step number of the first frame after the reset's.
saveLoggerstringmoviepy's progress logger (
"bar"); kept for Gymnasium's signature, the writers report nothing.fpsdouble?The frame rate; moviepy needs it (or durations, which Gym.NET does not take).
videoWriterIVideoWriterThe 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
framesorvideoFolderis null.- ValueError
Thrown when a video is due and
fpsis null, with moviepy's message.