stitchFramesToVideo()
Part of the @remotion/renderer
package.
Takes a series of images and audio information generated by renderFrames()
and encodes it to a video.
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:
dir
A string
containing the absolute path of the directory where the frames are located. This will be the directory where the ffmpeg
command will be executed.
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.
assetsInfo
Information about the audio mix. This is part of the return value of renderFrames().
outputLocation?
optional since v3.0.26
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?
optional
Whether Remotion should overwrite the file in outputLocation
if it already exists. true
by default.
pixelFormat?
optional
Sets the pixel format. See here for available values. The default is yuv420p
.
codec?
optional
Set a codec. See the encoding guide for available values and guidance on which one to choose. The default is h264
.
audioCodec?
"pcm-16" | "aac" | "mp3" | "opus", available from v3.3.41
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?
v3.2.32
Specify the target bitrate for the generated video. The syntax for FFmpeg's -b:a
parameter should be used. FFmpeg may encode the video in a way that will not result in the exact audio bitrate specified. Example values: 512K
for 512 kbps, 1M
for 1 Mbps. Default: 320k
videoBitrate?
v3.2.32
Specify the target bitrate for the generated video. The syntax for FFmpeg's-b:v
parameter should be used. FFmpeg may encode the video in a way that will not result in the exact video bitrate specified. Example values: 512K
for 512 kbps, 1M
for 1 Mbps.
bufferSize?
v4.0.78
The value for the -bufsize
flag of FFmpeg. Should be used in conjunction with the encoding max rate flag.
maxRate?
v4.0.78
The value for the -maxrate
flag of FFmpeg. Should be used in conjunction with the encoding buffer size flag.
crf?
optional
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?
optional
Sets a ProRes profile. Only applies to videos rendered with prores
codec. See Encoding guide for possible options.
onProgress?
optional
Callback function which informs about the encoding progress. The frameNumber
value is a number
.
ts
constonProgress = (frameNumber : number) => {console .log (`Encoding progress: on ${frameNumber } frame`);};
ts
constonProgress = (frameNumber : number) => {console .log (`Encoding progress: on ${frameNumber } frame`);};
onDownload?
optional
Notifies when a remote asset needs to be downloaded in order to extract the audio track.
ts
constonDownload = (src : string) => {console .log (`Downloading ${src }...`);};
ts
constonDownload = (src : string) => {console .log (`Downloading ${src }...`);};
numberOfGifLoops?
v3.1.0
optional
Allows you to set the number of loops as follows:null
(or omitting in the CLI) plays the GIF indefinitely.0
disables looping1
loops the GIF once (plays twice in total)2
loops the GIF twice (plays three times in total) and so on.
muted?
v3.2.1
optional
Disables audio output. This option may only be set in combination with a video codec and should also be passed to renderFrames()
.
verbose?
optional
A boolean value that when set to true
, will log all kinds of debug information. Default false
.
cancelSignal?
v3.0.15
optional
A token that allows the render to be cancelled. See: makeCancelSignal()
binariesDirectory?
v4.0.120
The directory where the platform-specific binaries and libraries that Remotion needs are located. Those include an ffmpeg
and ffprobe
binary, a Rust binary for various tasks, and various shared libraries. If the value is set to null
, which is the default, then the path of a platform-specific package located at node_modules/@remotion/compositor-*
is selected.This option is useful in environments where Remotion is not officially supported to run like bundled serverless functions or Electron.
forSeamlessAacConcatenation?
v4.0.123
If enabled, the audio is trimmed to the nearest AAC frame, which is required for seamless concatenation of AAC files. This is a requirement if you later want to combine multiple video snippets seamlessly.This option is used internally. There is currently no documentation yet for to concatenate the audio chunks.
ffmpegOverride?
v3.2.22
function - optional
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";constffmpegOverride :FfmpegOverrideFn = ({type ,args }) => {console .log (type ); // "stitcher" | "pre-stitcherreturn [...args , "-vf", "eq=brightness=0:saturation=1"];};
tsx
import type {FfmpegOverrideFn } from "@remotion/renderer";constffmpegOverride :FfmpegOverrideFn = ({type ,args }) => {console .log (type ); // "stitcher" | "pre-stitcherreturn [...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 parallel rendering and encoding, which means that a pre-stitcher process gets spawned before all frames are rendered. 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.
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
ffmpegExecutable
removed in v4.0, optional
A custom FFMPEG executable to be used. By default, a binary called ffmpeg
will be searched in your PATH
.
ffprobeExecutable?
v3.0.17
ffprobeExecutable?
removed in v4.0, optional
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
.