Table of Contents

Class FfmpegVideoWriter

Namespace
Gym.Utils
Assembly
Gym.dll

An IVideoWriter that pipes raw frames to an ffmpeg process and writes an H.264 mp4, as moviepy does for Gymnasium: libx264 at the medium preset, yuv420p when both sides are even.

public sealed class FfmpegVideoWriter : IVideoWriter
Inheritance
FfmpegVideoWriter
Implements
Inherited Members
Extension Methods

Remarks

ffmpeg must be installed; it is looked up on PATH unless Executable names it. Each video starts one process and waits for it; the frames stream through its standard input, so memory stays at one frame. The bytes differ from moviepy's (another encoder build and options), which DR-25 accepts: parity is on frames.

Properties

Codec

The video codec (-vcodec), libx264 as moviepy's default.

public string Codec { get; init; }

Property Value

string

Executable

The ffmpeg executable: a path, or a name looked up on PATH.

public string Executable { get; init; }

Property Value

string

Extension

.mp4.

public string Extension { get; }

Property Value

string

Preset

The encoder preset (-preset), medium as moviepy's default.

public string Preset { get; init; }

Property Value

string

Methods

Write(string, IReadOnlyList<NDArray>, double)

Encodes the frames into {path}.mp4, replacing an existing file.

public void Write(string path, IReadOnlyList<NDArray> frames, double fps)

Parameters

path string

The video's path without extension.

frames IReadOnlyList<NDArray>

The frames, all of one shape; they stay the caller's.

fps double

The frame rate.

Exceptions

ArgumentNullException

Thrown when path or frames is null.

ArgumentException

Thrown for no frames, frames of different shapes, or a frame that is not an image.

DependencyNotInstalled

Thrown when ffmpeg cannot be started.

Error

Thrown when ffmpeg fails, with its error output.