Class RecordVideoVector<TObs, TAct>
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
TObsThe batched observation type, passed through.
TActThe 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
envVectorEnv<TObs, TAct>The vector env; it must render images.
videoFolderstringThe 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).recordFirstOnlyboolWhether only the first sub-env is recorded.
episodeTriggerFunc<long, bool>Whether to start recording at an episode; with no trigger at all, CappedCubicVideoSchedule(long).
stepTriggerFunc<long, bool>Whether to start recording at a step.
videoLengthlongThe frames per video; 0 records whole episodes.
namePrefixstringThe prefix of the video names.
fpsdouble?The frame rate; null takes
metadata["render_fps"], else 30.disableLoggerboolmoviepy's logger switch, kept for Gymnasium's signature.
gcTriggerFunc<long, bool>Whether to collect garbage after a video; null always does.
videoWriterIVideoWriterThe encoder; null for PngVideoWriter.
Exceptions
- ValueError
Thrown when the env renders no images, with Gymnasium's message.
- ArgumentNullException
Thrown when
videoFolderis null.- TypeError
Thrown when
envis null.
Properties
AutoresetMode
The env's autoreset mode (autoreset_mode).
public AutoresetMode AutoresetMode { get; }
Property Value
DisableLogger
moviepy's logger switch (disable_logger).
public bool DisableLogger { get; set; }
Property Value
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
EpisodeTrigger
When to start recording at an episode (episode_trigger).
public Func<long, bool>? EpisodeTrigger { get; set; }
Property Value
FrameCols
The mosaic's columns, -1 before the first frame (frame_cols).
public int FrameCols { get; }
Property Value
FrameRows
The mosaic's rows, -1 before the first frame (frame_rows).
public int FrameRows { get; }
Property Value
FramesPerSec
The videos' frame rate (frames_per_sec).
public double FramesPerSec { get; set; }
Property Value
GcTrigger
When to collect garbage after a video (gc_trigger).
public Func<long, bool>? GcTrigger { get; set; }
Property Value
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
NamePrefix
The prefix of the video names (name_prefix).
public string NamePrefix { get; set; }
Property Value
RecordFirstOnly
Whether only the first sub-env is recorded (record_first_only).
public bool RecordFirstOnly { get; set; }
Property Value
RecordedFrames
The mosaics of the video being recorded (recorded_frames), owned by the wrapper.
public List<NDArray> RecordedFrames { get; }
Property Value
Recording
Whether a video is being recorded (recording).
public bool Recording { get; }
Property Value
SavedKwargs
The recorded constructor arguments (Python's _saved_kwargs).
[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }
Property Value
StepId
The number of the last step, from 0 (step_id; -1 before the first).
public long StepId { get; }
Property Value
StepTrigger
When to start recording at a step (step_trigger).
public Func<long, bool>? StepTrigger { get; set; }
Property Value
VideoAspectRatio
The mosaic's target aspect, (width, height) (video_aspect_ratio).
public (int Width, int Height) VideoAspectRatio { get; set; }
Property Value
VideoFolder
The absolute folder of the videos (video_folder).
public string VideoFolder { get; }
Property Value
VideoLength
The frames per video, infinite for whole episodes (video_length).
public double VideoLength { get; set; }
Property Value
VideoName
The current video's name without extension (_video_name), or null.
[PyName("_video_name")]
public string? VideoName { get; }
Property Value
VideoWriter
The encoder the videos go through.
public IVideoWriter VideoWriter { get; set; }
Property Value
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
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
seedsIReadOnlyList<BigInteger?>The seeds, passed on.
optionsIReadOnlyDictionary<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
seedBigInteger?The seed, passed on.
optionsIReadOnlyDictionary<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
videoNamestringThe 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
actionsTActThe 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.