Table of Contents

Class RecordVideoVector<TObs, TAct>

Namespace
Gym.Wrappers.Vector
Assembly
Gym.dll

Records videos of a vector env's episodes, the sub-envs' frames tiled into one frame, as Gymnasium's vector RecordVideo does: episodes are counted on the first sub-env, the grid's shape is the one closest to video_aspect_ratio, and each video goes through an IVideoWriter (DR-25).

[PyName("RecordVideo")]
public class RecordVideoVector<TObs, TAct> : VectorWrapper<TObs, TAct>, IVectorEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The batched observation type, passed through.

TAct

The batched action type, passed through.

Inheritance
VectorEnv<TObs, TAct>
VectorWrapper<TObs, TAct, TObs, TAct>
VectorWrapper<TObs, TAct>
RecordVideoVector<TObs, TAct>
Implements
Inherited Members
Extension Methods

Remarks

With record_first_only only the first sub-env is recorded. With SAME_STEP autoreset an episode's last frame is not recorded (Gymnasium's warning). The triggers, names, lengths and frame rate are Gymnasium's; see the single-env RecordVideo<TObs, TAct> for the writer, gc_trigger and closing. Gymnasium records only some of its arguments for a spec; so does this wrapper, plus video_writer.

Reference: gymnasium/wrappers/vector/rendering.py.

Constructors

RecordVideoVector(VectorEnv<TObs, TAct>, string, (int Width, int Height)?, bool, Func<long, bool>?, Func<long, bool>?, long, string, double?, bool, Func<long, bool>?, IVideoWriter?)

Wraps env, creating videoFolder.

public RecordVideoVector(VectorEnv<TObs, TAct> env, string videoFolder, (int Width, int Height)? videoAspectRatio = null, bool recordFirstOnly = false, Func<long, bool>? episodeTrigger = null, Func<long, bool>? stepTrigger = null, long videoLength = 0, string namePrefix = "rl-video", double? fps = null, bool disableLogger = true, Func<long, bool>? gcTrigger = null, IVideoWriter? videoWriter = null)

Parameters

env VectorEnv<TObs, TAct>

The vector env; it must render images.

videoFolder string

The folder of the videos, created if needed (a warning when it exists).

videoAspectRatio (int Width, int Height)?

The mosaic's target (width, height) aspect; null is (1, 1).

recordFirstOnly bool

Whether only the first sub-env is recorded.

episodeTrigger Func<long, bool>

Whether to start recording at an episode; with no trigger at all, CappedCubicVideoSchedule(long).

stepTrigger Func<long, bool>

Whether to start recording at a step.

videoLength long

The frames per video; 0 records whole episodes.

namePrefix string

The prefix of the video names.

fps double?

The frame rate; null takes metadata["render_fps"], else 30.

disableLogger bool

moviepy's logger switch, kept for Gymnasium's signature.

gcTrigger Func<long, bool>

Whether to collect garbage after a video; null always does.

videoWriter IVideoWriter

The encoder; null for PngVideoWriter.

Exceptions

ValueError

Thrown when the env renders no images, with Gymnasium's message.

ArgumentNullException

Thrown when videoFolder is null.

TypeError

Thrown when env is null.

Properties

AutoresetMode

The env's autoreset mode (autoreset_mode).

public AutoresetMode AutoresetMode { get; }

Property Value

AutoresetMode

DisableLogger

moviepy's logger switch (disable_logger).

public bool DisableLogger { get; set; }

Property Value

bool

EpisodeId

The number of the first sub-env's current episode, from 0 (episode_id; -1 before the first reset).

public long EpisodeId { get; }

Property Value

long

EpisodeTrigger

When to start recording at an episode (episode_trigger).

public Func<long, bool>? EpisodeTrigger { get; set; }

Property Value

Func<long, bool>

FrameCols

The mosaic's columns, -1 before the first frame (frame_cols).

public int FrameCols { get; }

Property Value

int

FrameRows

The mosaic's rows, -1 before the first frame (frame_rows).

public int FrameRows { get; }

Property Value

int

FramesPerSec

The videos' frame rate (frames_per_sec).

public double FramesPerSec { get; set; }

Property Value

double

GcTrigger

When to collect garbage after a video (gc_trigger).

public Func<long, bool>? GcTrigger { get; set; }

Property Value

Func<long, bool>

HasAutoreset

Whether the first sub-env ended at the last step, so the next step starts its episode (has_autoreset).

public bool HasAutoreset { get; }

Property Value

bool

NamePrefix

The prefix of the video names (name_prefix).

public string NamePrefix { get; set; }

Property Value

string

RecordFirstOnly

Whether only the first sub-env is recorded (record_first_only).

public bool RecordFirstOnly { get; set; }

Property Value

bool

RecordedFrames

The mosaics of the video being recorded (recorded_frames), owned by the wrapper.

public List<NDArray> RecordedFrames { get; }

Property Value

List<NDArray>

Recording

Whether a video is being recorded (recording).

public bool Recording { get; }

Property Value

bool

SavedKwargs

The recorded constructor arguments (Python's _saved_kwargs).

[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }

Property Value

Info

StepId

The number of the last step, from 0 (step_id; -1 before the first).

public long StepId { get; }

Property Value

long

StepTrigger

When to start recording at a step (step_trigger).

public Func<long, bool>? StepTrigger { get; set; }

Property Value

Func<long, bool>

VideoAspectRatio

The mosaic's target aspect, (width, height) (video_aspect_ratio).

public (int Width, int Height) VideoAspectRatio { get; set; }

Property Value

(int Width, int Height)

VideoFolder

The absolute folder of the videos (video_folder).

public string VideoFolder { get; }

Property Value

string

VideoLength

The frames per video, infinite for whole episodes (video_length).

public double VideoLength { get; set; }

Property Value

double

VideoName

The current video's name without extension (_video_name), or null.

[PyName("_video_name")]
public string? VideoName { get; }

Property Value

string

VideoWriter

The encoder the videos go through.

public IVideoWriter VideoWriter { get; set; }

Property Value

IVideoWriter

Methods

Close()

Closes the env, then writes the video still being recorded.

public override void Close()

Dispose(bool)

Releases the recorded mosaics, then closes (writing a video still recording) and disposes as every vector wrapper does.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

Reset(IReadOnlyList<BigInteger?>, IReadOnlyDictionary<string, object?>?)

Resets the env with one seed per sub-env, as Reset(BigInteger?, IReadOnlyDictionary<string, object?>?) does.

public override VectorResetResult<TObs> Reset(IReadOnlyList<BigInteger?> seeds, IReadOnlyDictionary<string, object?>? options = null)

Parameters

seeds IReadOnlyList<BigInteger?>

The seeds, passed on.

options IReadOnlyDictionary<string, object>

The options, passed on.

Returns

VectorResetResult<TObs>

The env's reset.

Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)

Resets the env; a full reset (or one masking the first sub-env) counts an episode and may start a recording.

public override VectorResetResult<TObs> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)

Parameters

seed BigInteger?

The seed, passed on.

options IReadOnlyDictionary<string, object>

The options, passed on.

Returns

VectorResetResult<TObs>

The env's reset.

StartRecording(string)

Starts a video (start_recording), first writing the one being recorded.

public void StartRecording(string videoName)

Parameters

videoName string

The new video's name without extension.

Step(TAct)

Steps the env, counts the first sub-env's episodes by the autoreset mode, starts recordings and captures a frame.

public override VectorStepResult<TObs> Step(TAct actions)

Parameters

actions TAct

The actions, passed on.

Returns

VectorStepResult<TObs>

The env's transition.

StopRecording()

Writes the video being recorded and stops (stop_recording); a video without frames is skipped with a warning.

public void StopRecording()

Exceptions

AssertionError

Thrown when nothing is being recorded: stop_recording was called, but no recording was started.