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 在底层使用此 API 来合并在单个 Lambda 函数上渲染的片段。

note

高级 API: 这是一个难以使用的 API,大多数人不应该直接使用。错误使用此 API 可能会导致不可预测的行为以及潜在的音频和视频伪影。如果你想要一个分布式渲染解决方案,请使用 renderMediaOnLambda()。如果你只是想启用多线程渲染视频,请使用 renderMedia()

示例

🌐 Example

combine.mjs
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"

🌐 "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

视频的每秒帧数。必须设置为 selectComposition() 返回的 fps 值。

🌐 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

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

用于输出文件的音频编解码器。如果未指定,则将根据视频编解码器确定。

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

preferLossless

boolean

必须与你传递给每个 renderMedia() 调用的值相同。

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

compositionDurationInFrames

number

作品的总时长。必须设置为 selectComposition() 返回的 durationInFrames 值。
即使使用 frameRangeeveryNthFrame 选项,也不要更改该值。

🌐 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?

数字 | [数字, 数字] | [数字, null] | null

🌐 number | [number, number] | [number, null] | null

frameRange 那样,你会传递给 renderMedia()renderMediaOnLambda()。视频在所有片段合并后所存在的帧范围。从某一帧开始渲染到合成结束,传递 [number, null]v4.0.421

everyNthFrame?

number

就像 everyNthFrame 那样,你会传递给 renderMedia()renderMediaOnLambda() 一样。

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

必须与你传递给每个 renderMedia() 调用的值相同。

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

onProgress?

function

用于跟踪合并操作进度的回调函数。

🌐 Callback function to track the progress of the combining operation.

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

必须与你传递给每个 renderMedia() 调用的值相同。

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

numberOfGifLoops?

数字 | null

🌐 number | null

必须与你传递给每个 renderMedia() 调用的值相同。

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

logLevel?

"verbose" | "info" | "warn" | "error"

🌐 "verbose" | "info" | "warn" | "error"

控制日志记录的详细程度。默认值是 "info"

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

binariesDirectory?

字符串 | 空

🌐 string | null

包含 FFmpeg 二进制文件的目录,用于替代打包的或系统安装的版本。

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

cancelSignal?

取消信号

🌐 CancelSignal

一个允许取消组合过程的令牌。参见:"makeCancelSignal()"

🌐 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

该函数返回一个 Promise,当合并过程完成时该 Promise 会被解决。

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

兼容性

🌐 Compatibility

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

另请参阅

🌐 See also