stitchFramesToVideo()
@remotion/renderer 包的一部分.
🌐 Part of the @remotion/renderer package.
获取由 renderFrames() 生成的一系列图片和音频信息,并将其编码为视频。
🌐 Takes a series of images and audio information generated by renderFrames() and encodes it to a video.
在 Remotion 3.0 中,我们添加了 renderMedia() API,它将 renderFrames() 和 stitchFramesToVideo() 合并为一个简化步骤,并加快了渲染速度。如果可以的话,优先使用 renderMedia()。
参数
🌐 Arguments
一个具有以下属性的对象:
🌐 An object with the following properties:
fps
一个 number,指定输出视频的期望帧率。
🌐 A number specifying the desired frame rate of the output video.
width
一个 number,指定视频所需的输出宽度(以像素为单位)。
🌐 A number specifying the desired output width in pixels for the video.
height
一个 number,指定视频所需的输出高度(以像素为单位)。
🌐 A number specifying the desired output height in pixels for the video.
metadatav4.0.216
object
An object containing metadata to be embedded in the video. See here for which metadata is accepted.assetsInfo
关于帧和音频混合的信息。这是 renderFrames() 的返回值的一部分。
该数据结构在不同的 Remotion 版本之间不稳定。
🌐 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.
如果未指定或设置为 null,文件将以内存缓冲区的形式返回。
🌐 If not specified or set to null, the file will be returned in-memory as a buffer.
force?
如果文件已存在,Remotion 是否应该覆盖 outputLocation 中的文件。默认为 true。
🌐 Whether Remotion should overwrite the file in outputLocation if it already exists. true by default.
pixelFormat?
设置像素格式。可用值请参见 这里。默认值为 yuv420p。
🌐 Sets the pixel format. See here for available values. The default is yuv420p.
codec?
设置编解码器。请参阅 编码指南 获取可用值以及选择哪个的指导。默认值是 h264。
🌐 Set a codec. See the encoding guide for available values and guidance on which one to choose. The default is h264.
audioCodec?v3.3.41
"pcm-16" | "aac" | "mp3" | "opus"
🌐 "pcm-16" | "aac" | "mp3" | "opus"
选择你的音频编码。
🌐 Choose the encoding of your audio.
- 默认值取决于所选择的
codec。 - 如果你需要未压缩的音频,请选择
pcm-16。 - 并非所有视频容器都支持所有音频编解码器。
- 如果
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?
输出的恒定速率因子,是一个控制质量的参数。有关此参数的更多信息,请参见这里。默认值取决于编解码器。
🌐 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?
设置 ProRes 配置文件。仅适用于使用 prores 编解码器渲染的视频。有关可能的选项,请参见 编码指南。
🌐 Sets a ProRes profile. Only applies to videos rendered with prores codec. See Encoding guide for possible options.
onProgress?
回调函数,用于通知编码进度。frameNumber 值是一个 number。
🌐 Callback function which informs about the encoding progress. The frameNumber value is a number.
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.
const onDownload = (src : string) => {
console .log (`Downloading ${src }...`);
};numberOfGifLoops?v3.1.0
Allows you to set the number of loops as follows:null(or omitting in the CLI) plays the GIF indefinitely.0disables looping1loops the GIF once (plays twice in total)2loops the GIF twice (plays three times in total) and so on.
muted?v3.2.1
禁用音频输出。此选项只能与视频编码器结合设置,并且也应传递给 renderFrames()。
🌐 Disables audio output. This option may only be set in combination with a video codec and should also be passed to renderFrames().
hardwareAcceleration?v4.0.228
One of
"disable", "if-possible", or "required"
. Default "disable". Encode using a hardware-accelerated encoder if
available. If set to "required" and no hardware-accelerated encoder is
available, then the render will fail.
verbose?
一个布尔值,当设置为 true 时,将记录各种调试信息。默认 false。
🌐 A boolean value that when set to true, will log all kinds of debug information. Default false.
cancelSignal?v3.0.15
一个允许取消渲染的令牌。参见:"makeCancelSignal()"
🌐 A token that allows the render to be cancelled. See: makeCancelSignal()
enforceAudioTrack?v3.2.1
如果没有其他音轨,则渲染一个静音音轨。
🌐 Render a silent audio track if there wouldn't be any otherwise.
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.
separateAudioTo?v4.0.123
If set, the audio will not be included in the main output but rendered as a separate file at the location you pass. It is recommended to use an absolute path. If a relative path is passed, it is relative to the Remotion Root.
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.
x264Preset?
Sets a x264 preset profile. Only applies to videos rendered with h264 codec.Possible values:
superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.Default:
medium
colorSpace?v4.0.28
Color space to use for the video. Acceptable values: "default"(default since 5.0), "bt601" (same as "default", since v4.0.424), "bt709" (since v4.0.28), "bt2020-ncl" (since v4.0.88), "bt2020-cl" (since v4.0.88), .For best color accuracy, it is recommended to also use
"png" as the image format to have accurate color transformations throughout.Only since v4.0.83, colorspace conversion is actually performed, previously it would only tag the metadata of the video.
ffmpegOverride?v3.2.22
修改 Remotion 在底层使用的 FFMPEG 命令。它的工作方式类似于 reducer,也就是说,你传入一个函数,该函数以命令作为参数并返回一个新的命令。
🌐 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.
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:要么"stitcher"要么"pre-stitcher"。如果有足够的内存和 CPU,可采用两遍处理的视频生成方式。pre-stitcher是编码阶段,stitcher是复用阶段。如果覆盖函数只调用一次stitcher,那么编码和复用将在同一步完成。你可以通过在渲染命令中添加--log=verbose来判断是否启用了并行编码。args:作为参数传递给 FFMPEG 命令的字符串数组。
你的函数必须返回一个修改过的字符串数组。
🌐 Your function must return a modified array of strings.
不建议使用此功能。在使用它之前,我们希望让你了解一些注意事项:
- 渲染命令可能会随任何新的 Remotion 版本而更改,即使是在补丁升级时。这可能会导致你使用此功能时出现问题。
- 根据所选的编解码器、可用的 CPU 和内存,Remotion 可能会使用或不使用“并行编码”,这将导致执行多个 FFMPEG 命令。你的函数必须能够处理被多次调用的情况。
- 使用 Remotion Lambda 时此功能不可用。
在使用此技巧之前,请通过 Discord 联系 Remotion 团队,并询问我们是否愿意以干净的方式实现你需要的功能——我们经常根据用户反馈快速实现新功能。
🌐 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在 v4.0 中移除
🌐 removed in v4.0
要使用自定义的 FFMPEG 可执行文件。默认情况下,会在你的 PATH 中搜索名为 ffmpeg 的二进制文件。
🌐 A custom FFMPEG executable to be used. By default, a binary called ffmpeg will be searched in your PATH.
ffprobeExecutable? v3.0.17
ffprobeExecutable?在 v4.0 中移除
🌐 removed in v4.0
用于覆盖 ffprobe 可执行文件的绝对路径。
🌐 An absolute path overriding the ffprobe executable to use.
返回值
🌐 Return value
stitchFramesToVideo() 返回一个不会解析任何内容的 promise。如果一切顺利,输出将被放置在 outputLocation 中。
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
另请参阅
🌐 See also