Skip to main content

combineChunks()v4.0.279

Combine multiple video or audio chunks into a single output file. This function is useful for decentralized rendering workflows where different parts of a video are rendered separately and need to be combined.

Remotion Lambda uses this API under the hood to combine chunks that were rendered on individual Lambda functions.

note

Advanced API: This is a hard-to-use API that most people should not use directly. Misusage of this API might lead to unpredictable behavior and potential audio and video artifacts. If you want a distributed rendering solution, use renderMediaOnLambda(). If you just want to render a video with multithreading enabled, use renderMedia().

Example

combine.mjs
tsx
import {combineChunks} from '@remotion/renderer';
 
// Video files rendered as separate chunks
const videoFiles = ['/path/to/chunk1.mp4', '/path/to/chunk2.mp4', '/path/to/chunk3.mp4'];
 
// Optional audio files corresponding to each video chunk
const audioFiles = ['/path/to/chunk1.aac', '/path/to/chunk2.aac', '/path/to/chunk3.aac'];
 
await combineChunks({
outputLocation: '/path/to/final-video.mp4',
videoFiles,
audioFiles,
codec: 'h264',
fps: 30,
framesPerChunk: 100,
audioCodec: 'aac',
preferLossless: false,
compositionDurationInFrames: 300,
});

Arguments

An object with the following properties:

outputLocation

string

Where to save the output media file. Must be an absolute path.

videoFiles

string[]

An array of absolute file paths pointing to the video chunks to be combined. These should be in the correct order for combining.

audioFiles

string[]

An array of absolute file paths pointing to the audio chunks to be combined. These should be in the correct order for combining.

codec

"h264" | "h265" | "vp8" | "vp9" | "mp3" | "aac" | "wav" | "prores" | "h264-mkv" | "gif"

The codec to use for the output file. See the distributed rendering guide to see which parameter to set.

fps

number

The frames per second of the video. Must be set to the fps value returned by selectComposition().

framesPerChunk

number

The number of frames in each chunk. All chunks must have the same number of frames, except the last one.

audioCodec

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

Audio codec to use for the output file. If not specified, it will be determined based on the video codec.

preferLossless

boolean

Must be the same value that you passed to each renderMedia() call.

compositionDurationInFrames

number

The total duration of the composition. Must be set to the durationInFrames value returned by selectComposition().
Do not change the value, even if you use the frameRange or everyNthFrame options.

frameRange?

number | [number, number] | null - optional

Like frameRange that you would pass to renderMedia() or renderMediaOnLambda(). The range of frames of which the video exists once all chunks are combined.

everyNthFrame?

number - optional

Like everyNthFrame that you would pass to renderMedia() or renderMediaOnLambda().

Must be the same value that you passed to each renderMedia() call.

onProgress?

function - optional

Callback function to track the progress of the combining operation.

tsx
import {CombineChunksOnProgress} from '@remotion/renderer';
 
const onProgress: CombineChunksOnProgress = ({totalProgress, frames}) => {
console.log(`Combining is ${totalProgress * 100}% complete`);
console.log(`Processed ${frames} frames`);
};

audioBitrate?

string | null - optional

Must be the same value that you passed to each renderMedia() call.

numberOfGifLoops?

number | null - optional

Must be the same value that you passed to each renderMedia() call.

logLevel?

"verbose" | "info" | "warn" | "error" - optional

Controls the verbosity of logging. Default is "info".

binariesDirectory?

string | null - optional

A directory containing FFmpeg binaries to use instead of the bundled or system-installed ones.

cancelSignal?

CancelSignal - optional

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

metadata?

Metadata to add to the output file, in the format of key-value pairs.

Return Value

The function returns a Promise that resolves when the combining process is complete.

See also