Skip to content

MP4

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

mp4OutputExample.tsx
import Smelter from "@swmansion/smelter-node";
import { View } from "@swmansion/smelter";
async function run() {
const smelter = new Smelter();
await smelter.init();
await smelter.registerOutput("example", <View />, {
type: "mp4",
serverPath: "./output.mp4",
video: {
encoder: { type: "ffmpeg_h264" },
resolution: { width: 1920, height: 1080 },
}
});
}
void run();

RegisterMp4Output

import { Outputs, RegisterMp4Output } from "@swmansion/smelter"

Parameters for an output stream to MP4 file.

Type definitions

type RegisterMp4Output = {
serverPath: string;
video?: Outputs.Mp4VideoOptions;
audio?: Outputs.Mp4AudioOptions;
}

Properties

serverPath

Path to the MP4 file, specifying its location on the server where the Smelter is deployed.

  • Type: string

video

Video track configuration.


audio

Audio track configuration.

Outputs.Mp4VideoOptions

import { Outputs } from "@swmansion/smelter"

Video track configuration options.

Type definitions

type Mp4VideoOptions = {
resolution: {
width: number;
height: number;
};
sendEosWhen?: Outputs.OutputEndCondition;
encoder: Outputs.Mp4VideoEncoderOptions;
root: React.ReactElement;
}

Properties

resolution

Output resolution in pixels.

  • Type: { width: number; height: number;}

sendEosWhen

Condition for termination of the output stream based on the input streams states. If output includes both audio and video streams, then EOS needs to be sent for every type.


encoder

Video encoder options.


root

Root of a component tree/scene that should be rendered for the output.

  • Type: ReactNode

Outputs.Mp4VideoEncoderOptions

import { Outputs } from "@swmansion/smelter"

Configuration for the video encoder, based on the selected codec.

Type definitions

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

Properties (type: “ffmpeg_h264”)

preset

Video output encoder preset. Visit FFmpeg docs to learn more.

  • Type: "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" | "placebo"
  • Default value: fast
  • Supported values:
    • ultrafast
    • superfast
    • veryfast
    • faster
    • fast
    • medium
    • slow
    • slower
    • veryslow
    • placebo

ffmpegOptions

Raw FFmpeg encoder options. Visit FFmpeg docs to learn more.

  • Type: Map<string, string>

Outputs.Mp4AudioOptions

import { Outputs } from "@swmansion/smelter"

Parameters of an audio source included in the stream.

Type definitions

type Mp4AudioOptions = {
mixingStrategy?: "sum_clip" | "sum_scale";
sendEosWhen?: Outputs.OutputEndCondition;
encoder: Outputs.Mp4AudioEncoderOptions;
}

Properties

mixingStrategy

Specifies how audio should be mixed.

  • Type: "sum_clip" | "sum_scale"
  • Default value: "sum_clip"
  • Supported values:
    • sum_clip - First, the input samples are summed. If the result exceeds the i16 PCM range, it is clipped.
    • sum_scale - First, the input samples are summed. If the result exceeds the i16 PCM range, the summed samples are scaled down by a factor to fit within the range.

sendEosWhen

Condition for termination of the output stream based on the input streams states. If output includes both audio and video streams, then EOS needs to be sent for every type.


encoder

Audio encoder options.

Outputs.Mp4AudioEncoderOptions

import { Outputs } from "@swmansion/smelter"

Configuration for the audio encoder, based on the selected codec.

Type definitions

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

Properties(type: “aac”)

channels

Channels configuration

  • Type: "mono" | "stereo"
  • Supported values:
    • mono - Mono audio (single channel).
    • stereo - Stereo audio (two channels).

Outputs.OutputEndCondition

import { Outputs } from "@swmansion/smelter"

Defines when the output stream should end based on the state of the input streams. Only one of the nested fields can be set at a time.

By default, 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).
Type definitions

type OutputEndCondition =
| { anyOf: string[]; }
| { allOf: string[]; }
| { anyInput: boolean; }
| { allInputs: boolean; };

Properties

anyOf

List of the input streams. The output stream will terminate if any stream in the list finishes.

  • Type: string[]

allOf

List of the input streams. The output stream will terminate when all streams in the list finish.

  • Type: string[]

anyInput

Terminate the output stream if any of the input streams end, including streams added after the output was registered. Notably, the output stream will not terminate if no inputs were ever connected.

  • Type: boolean

allInputs

Terminate the output stream only when all input streams have finished. Notably, the output stream will terminate if no inputs were ever connected.

  • Type: boolean