Back to Remotion

stitchFramesToVideo()

packages/docs/docs/renderer/stitch-frames-to-video.mdx

4.0.4857.4 KB
Original Source

Part of the @remotion/renderer package.

Takes a series of images and audio information generated by renderFrames() and encodes it to a video.

:::info In Remotion 3.0, we added the renderMedia() API which combines renderFrames() and stitchFramesToVideo() into one simplified step and performs the render faster. Prefer renderMedia() if you can. :::

Arguments

An object with the following properties:

fps

A number specifying the desired frame rate of the output video.

width

A number specifying the desired output width in pixels for the video.

height

A number specifying the desired output height in pixels for the video.

metadata<AvailableFrom v="4.0.216" />

object

<Options id="metadata" />

assetsInfo

Information about the frames and audio mix. This is part of the return value of renderFrames().
The data structure is not stable between Remotion versions.

outputLocation?

An absolute path specify where the output file should be written to.

If not specified or set to null, the file will be returned in-memory as a buffer.

force?

Whether Remotion should overwrite the file in outputLocation if it already exists. true by default.

pixelFormat?

Sets the pixel format. See here for available values. The default is yuv420p.

codec?

Set a codec. See the encoding guide for available values and guidance on which one to choose. The default is h264.

audioCodec?<AvailableFrom v="3.3.41" />

"pcm-16" | "aac" | "mp3" | "opus"

Choose the encoding of your audio.

  • The default is dependent on the chosen codec.
  • Choose pcm-16 if you need uncompressed audio.
  • Not all video containers support all audio codecs.
  • This option takes precedence if the codec option also specifies an audio codec.

Refer to the Encoding guide to see defaults and supported combinations.

audioBitrate?<AvailableFrom v="3.2.32" />

<Options id="audio-bitrate" />

videoBitrate?<AvailableFrom v="3.2.32" />

<Options id="video-bitrate" />

bufferSize?<AvailableFrom v="4.0.78" />

<Options id="buffer-size" />

maxRate?<AvailableFrom v="4.0.78" />

<Options id="max-rate" />

crf?

The constant rate factor of the output, a parameter which controls quality. See here for more information about this parameter. Default is depending on the codec.

proResProfile?

Sets a ProRes profile. Only applies to videos rendered with prores codec. See Encoding guide for possible options.

onProgress?

Callback function which informs about the encoding progress. The frameNumber value is a number.

ts
const onProgress = (frameNumber: number) => {
  console.log(`Encoding progress: on ${frameNumber} frame`);
};

onDownload?

Notifies when a remote asset needs to be downloaded in order to extract the audio track.

ts
const onDownload = (src: string) => {
  console.log(`Downloading ${src}...`);
};

numberOfGifLoops?<AvailableFrom v="3.1.0" />

<Options id="number-of-gif-loops" />

muted?<AvailableFrom v="3.2.1" />

Disables audio output. This option may only be set in combination with a video codec and should also be passed to renderFrames().

hardwareAcceleration?<AvailableFrom v="4.0.228" />

<Options id="hardware-acceleration" />

verbose?

A boolean value that when set to true, will log all kinds of debug information. Default false.

cancelSignal?<AvailableFrom v="3.0.15" />

A token that allows the render to be cancelled. See: makeCancelSignal()

enforceAudioTrack?<AvailableFrom v="3.2.1" />

Render a silent audio track if there wouldn't be any otherwise.

binariesDirectory?<AvailableFrom v="4.0.120" />

<Options id="binaries-directory" />

separateAudioTo?<AvailableFrom v="4.0.123" />

<Options cli id="separate-audio-to" />

forSeamlessAacConcatenation?<AvailableFrom v="4.0.123" />

<Options id="for-seamless-aac-concatenation" />

x264Preset?

<Options id="x264-preset" />

gopSize?<AvailableFrom v="4.0.466" />

<Options id="gop" />

colorSpace?<AvailableFrom v="4.0.28"/>

<Options id="color-space" />

ffmpegOverride?<AvailableFrom v="3.2.22" />

Modifies the FFMPEG command that Remotion uses under the hood. It works reducer-style, meaning that you pass a function that takes a command as an argument and returns a new command.

tsx
import type {FfmpegOverrideFn} from '@remotion/renderer';

const ffmpegOverride: FfmpegOverrideFn = ({type, args}) => {
  console.log(type); // "stitcher" | "pre-stitcher
  return [...args, '-vf', 'eq=brightness=0:saturation=1'];
};

The function you pass must accept an object as it's only parameter which contains the following properties:

  • type: Either "stitcher" or "pre-stitcher". If enough memory and CPU is available, Remotion may use a two-pass process for the video generation. pre-stitcher is the encoding phase and stitcher is the muxing phase. If the override function is only called once with stitcher, then encoding and muxing is done in the same step. You can tell whether parallel encoding is enabled by adding --log=verbose to your render command.
  • args: An array of strings that is passed as arguments to the FFMPEG command.

Your function must return a modified array of strings.

:::warning Using this feature is discouraged. Before using it, we want to make you aware of some caveats:

  • The render command can change with any new Remotion version, even when it is a patch upgrade. This might break your usage of this feature.
  • Depending on the selected codec, available CPU and RAM, Remotion may or may not use "parallel encoding" which will result in multiple FFMPEG commands being executed. Your function must be able to handle being called multiple times.
  • This feature is not available when using Remotion Lambda.

Before you use this hack, reach out to the Remotion team on Discord and ask us if we are open to implement the feature you need in a clean way - we often do implement new features quickly based on users feedback. :::

ffmpegExecutable

removed in v4.0

A custom FFMPEG executable to be used. By default, a binary called ffmpeg will be searched in your PATH.

ffprobeExecutable? <AvailableFrom v="3.0.17" />

removed in v4.0

An absolute path overriding the ffprobe executable to use.

Return value

stitchFramesToVideo() returns a promise which resolves to nothing. If everything goes well, the output will be placed in outputLocation.

Compatibility

<CompatibilityTable chrome={false} firefox={false} safari={false} nodejs={true} bun={true} serverlessFunctions={false} clientSideRendering={false} serverSideRendering={true} player={false} studio={false} />

See also