MediaRecorder

namespace VideoKit {
    /// <summary>
    /// Media recorder for recording video and/or audio frames to a media file.
    /// </summary>
    class MediaRecorder { ... }
}

The MediaRecorder encodes PixelBuffer and AudioBuffer instances to a media file.


Creating a Recorder

INCOMPLETE

Creating a Recorder

/// <summary>
/// Create a media recorder.
/// </summary>
/// <param name="format">Recorder format.</param>
/// <param name="width">Video width.</param>
/// <param name="height">Video height.</param>
/// <param name="frameRate">Video frame rate.</param>
/// <param name="sampleRate">Audio sample rate.</param>
/// <param name="channelCount">Audio channel count.</param>
/// <param name="videoBitRate">Video bit rate in bits per second.</param>
/// <param name="keyframeInterval">Keyframe interval in seconds.</param>
/// <param name="compressionQuality">Image compression quality in range [0, 1].</param>
/// <param name="audioBitRate">Audio bit rate in bits per second.</param>
/// <param name="prefix">Subdirectory name to save recordings. This will be created if it does not exist.</param>
/// <returns>Created recorder.</returns>
static Task<MediaRecorder> Create (
    Format format,
    int width = 0,
    int height = 0,
    float frameRate = 0f,
    int sampleRate = 0,
    int channelCount = 0,
    int videoBitRate = 20_000_000,
    int keyframeInterval = 2,
    float compressionQuality = 0.8f,
    int audioBitRate = 64_000,
    string? prefix = null
);

INCOMPLETE

/// <summary>
/// Recording format.
/// </summary>
enum Format : int {
    /// <summary>
    /// MP4 video with H.264 AVC video codec and AAC audio codec.
    /// This format supports recording both video and audio frames.
    /// </summary>
    MP4 = 0,
    /// <summary>
    /// MP4 video with H.265 HEVC video codec and AAC audio codec.
    /// This format has better compression than `MP4`.
    /// This format supports recording both video and audio frames.
    /// </summary>
    HEVC = 1,
    /// <summary>
    /// WEBM video with VP8 or VP9 video codec.
    /// This format support recording both video and audio frames.
    /// </summary>
    WEBM = 2,
    /// <summary>
    /// Animated GIF image.
    /// This format only supports recording video frames.
    /// </summary>
    GIF = 3,
    /// <summary>
    /// JPEG image sequence.
    /// This format only supports recording video frames.
    /// </summary>
    JPEG = 4,
    /// <summary>
    /// Waveform audio.
    /// This format only supports recording audio frames.
    /// </summary>
    WAV = 5,
    /// <summary>
    /// MP4 video with AV1 video codec and AAC audio codec.
    /// This format supports recording both video and audio frames.
    /// </summary>
    AV1 = 6,
    /// <summary>
    /// Apple ProRes video.
    /// This format supports recording both video and audio frames.
    /// </summary>
    ProRes4444 = 7,
}

INCOMPLETE

Checking for Format Support

/// <summary>
/// Check whether the current device supports recording to this format.
/// </summary>
/// <param name="format">Recording format.</param>
/// <returns>Whether the current device supports recording to this format.</returns>
static bool CanCreate (Format format);

INCOMPLETE

FormatAndroidiOSmacOSWebGLWindows
Format.MP4
Format.HEVC
Format.WEBM
Format.GIF
Format.JPEG
Format.WAV
Format.AV1 1
Format.ProRes4444 2 2

1: This is experimental and is only supported on Android 14+.
2: This is experimental.


Inspecting the Recorder

INCOMPLETE

Inspecting the Encoding Format

/// <summary>
/// Get the encoding format.
/// </summary>
Format format { get; }

INCOMPLETE

Inspecting the Video Width

/// <summary>
/// Get the video width.
/// </summary>
int width { get; }

INCOMPLETE

Inspecting the Video Height

/// <summary>
/// Get the video height.
/// </summary>
int height { get; }

INCOMPLETE

Inspecting the Audio Sample Rate

/// <summary>
/// Get the audio sample rate.
/// </summary>
int sampleRate { get; }

INCOMPLETE

Inspecting the Audio Channel Count

/// <summary>
/// Get the audio channel count.
/// </summary>
int channelCount { get; }

INCOMPLETE


Appending Media Buffers

INCOMPLETE

Checking for Supported Buffers

/// <summary>
/// Check whether the media recorder supports appending sample buffers of the given type.
/// </summary>
/// <typeparam name="T">Sample buffer type.</typeparam>
/// <returns>Whether the media recorder supports appending sample buffers of the given type.</returns>
bool CanAppend<T> () where T : AudioBuffer | PixelBuffer;

INCOMPLETE

/// <summary>
/// Check whether the media recorder supports appending sample buffers of the given type.
/// </summary>
/// <typeparam name="T">Sample buffer type.</typeparam>
/// <param name="format">Media recorder format.</param>
/// <returns>Whether the media recorder supports appending sample buffers of the given type.</returns>
static bool CanAppend<T> (Format format) where T : AudioBuffer | PixelBuffer;

Appending Pixel Buffers

/// <summary>
/// Append a pixel buffer to the recorder.
/// </summary>
/// <param name="pixelBuffer">Pixel buffer to append.</param>
void Append (PixelBuffer pixelBuffer);

INCOMPLETE

Appending Audio Buffers

/// <summary>
/// Append an audio frame to the recorder.
/// </summary>
/// <param name="audioBuffer">Audio buffer to append.</param>
void Append (AudioBuffer audioBuffer);

INCOMPLETE


Finishing a Recording Session

/// <summary>
/// Finish writing.
/// </summary>
/// <returns>Recorded media asset.</returns>
Task<MediaAsset> FinishWriting ();

INCOMPLETE


Was this page helpful?