Skip to main content
Added in v0.3.0

MP4

An output type that allows saving video and audio from the compositor to MP4 file.

Mp4Output

type Mp4Output = {
path: string;
video?: OutputVideoOptions;
audio?: OutputMp4AudioOptions;
}

Properties

  • path - Path to output MP4 file.
  • video - Video track configuration.
  • audio - Audio track configuration.

OutputVideoOptions

type OutputVideoOptions = {
resolution: {
width: u32;
height: u32;
};
send_eos_when?: OutputEndCondition;
encoder: VideoEncoderOptions;
initial: { root: Component; };
}

Properties

  • resolution - Output resolution in pixels.
  • send_eos_when - Defines when output stream should end if some of the input streams are finished. If output includes both audio and video streams, then EOS needs to be sent on both.
  • encoder - Video encoder options.
  • initial - Root of a component tree/scene that should be rendered for the output. Use update_output request to update this value after registration. Learn more.

OutputMp4AudioOptions

type OutputMp4AudioOptions = {
mixing_strategy?: "sum_clip" | "sum_scale";
send_eos_when?: OutputEndCondition;
encoder: Mp4AudioEncoderOptions;
initial: { inputs: InputAudio[]; };
}

Properties

  • mixing_strategy - (default="sum_clip") Specifies how audio should be mixed.
    • "sum_clip" - Firstly, input samples are summed. If the result is outside the i16 PCM range, it gets clipped.
    • "sum_scale" - Firstly, input samples are summed. If the result is outside the i16 PCM range, nearby summed samples are scaled down by factor, such that the summed wave is in the i16 PCM range.
  • send_eos_when - Condition for termination of output stream based on the input streams states.
  • encoder - Audio encoder options.
  • initial - Initial audio mixer configuration for output.

OutputEndCondition

type OutputEndCondition = {
any_of?: string[];
all_of?: string[];
any_input?: bool;
all_inputs?: bool;
}

This type defines when end of an input stream should trigger end of the output stream. Only one of those fields can be set at the time. Unless specified otherwise the input stream is considered finished/ended when:

  • TCP connection was dropped/closed.
  • RTCP Goodbye packet (BYE) was received.
  • Mp4 track has ended.
  • Input was unregistered already (or never registered).

Properties

  • any_of - Terminate output stream if any of the input streams from the list are finished.
  • all_of - Terminate output stream if all the input streams from the list are finished.
  • any_input - Terminate output stream if any of the input streams ends. This includes streams added after the output was registered. In particular, output stream will not be terminated if no inputs were ever connected.
  • all_inputs - Terminate output stream if all the input streams finish. In particular, output stream will be terminated if no inputs were ever connected.

VideoEncoderOptions

type VideoEncoderOptions = 
| {
type: "ffmpeg_h264";
preset:
| "ultrafast"
| "superfast"
| "veryfast"
| "faster"
| "fast"
| "medium"
| "slow"
| "slower"
| "veryslow"
| "placebo";
ffmpeg_options?: Map<string, string>;
}

Properties (type: "ffmpeg_h264")

  • preset - (default="fast") Preset for an encoder. See FFmpeg docs to learn more.
  • ffmpeg_options - Raw FFmpeg encoder options. See docs for more.

Mp4AudioEncoderOptions

type Mp4AudioEncoderOptions = { type: "aac"; channels: "mono" | "stereo"; }

InputAudio

type InputAudio = {
input_id: string;
volume?: f32;
}

Properties

  • volume - (default=1.0) float in [0, 1] range representing input volume