stitchFramesToVideo()
属于 @remotion/renderer
包的一部分。
将由 renderFrames()
生成的一系列图像和音频信息编码为视频。
在 Remotion 3.0 中,我们添加了 renderMedia()
API,它将 renderFrames()
和 stitchFramesToVideo()
结合为一个简化的步骤,并且执行渲染速度更快。如果可以的话,请优先使用 renderMedia()
。
参数
具有以下属性的对象:
fps
指定输出视频的期望帧率的 number
。
width
指定视频的输出宽度(以像素为单位)的 number
。
height
指定视频的输出高度(以像素为单位)的 number
。
assetsInfo
关于帧和音频混音的信息。这是 renderFrames()
的返回值的一部分。
数据结构在 Remotion 版本之间不稳定。
outputLocation?
自 v3.0.26 起可选
指定输出文件应写入的绝对路径。
如果未指定或设置为 null
,则文件将以内存中的缓冲区形式返回。
force?
可选
Remotion 是否应在 outputLocation
中的文件已存在时覆盖该文件。默认为 true
。
pixelFormat?
可选
设置像素格式。有关可用值,请参阅此处。默认值为 yuv420p
。
codec?
可选
设置编解码器。有关可用值和选择哪个值的指导,请参阅编码指南。默认值为 h264
。
audioCodec?
"pcm-16" | "aac" | "mp3" | "opus",自 v3.3.41 起可用
选择音频的编码方式。
- 默认值取决于所选的
codec
。 - 如果需要无损音频,请选择
pcm-16
。 - 并非所有视频容器都支持所有音频编解码器。
- 如果
codec
选项还指定了音频编解码器,则此选项优先。
请参考编码指南查看默认值和支持的组合。
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?
可选
输出的恒定速率因子,控制质量的参数。有关此参数的更多信息,请参见此处。默认值取决于编解码器。
proResProfile?
可选
设置ProRes配置文件。仅适用于使用prores
编解码器渲染的视频。有关可能选项,请参见编码指南。
onProgress?
可选
通知有关编码进度的回调函数。frameNumber
值为number
。
ts
constonProgress = (frameNumber : number) => {console .log (`编码进度:在第 ${frameNumber } 帧`);};
ts
constonProgress = (frameNumber : number) => {console .log (`编码进度:在第 ${frameNumber } 帧`);};
onDownload?
可选
在需要下载远程资产以提取音轨时发出通知。
ts
constonDownload = (src : string) => {console .log (`正在下载 ${src }...`);};
ts
constonDownload = (src : string) => {console .log (`正在下载 ${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.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
可选
禁用音频输出。此选项只能与视频编解码器结合使用,并且还应传递给renderFrames()
。
verbose?
可选
一个布尔值,当设置为true
时,将记录各种调试信息。默认为false
。
cancelSignal?
v3.0.15
可选
允许取消渲染的令牌。请参见:makeCancelSignal()
enforceAudioTrack?
v3.2.1
如果没有音轨,则渲染一个静音音轨。
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?
string - optional
Sets a x264 preset profile. Only applies to videos rendered withh264
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), "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
function - optional
修改 Remotion 在后台使用的 FFMPEG 命令。它的工作方式类似于 reducer,这意味着您传递一个接受命令作为参数并返回新命令的函数。
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'];};
您传递的函数必须接受一个对象作为唯一参数,该对象包含以下属性:
type
:为"stitcher"
或"pre-stitcher"
。如果有足够的内存和 CPU 可用,Remotion 可能会使用并行渲染和编码,这意味着在渲染所有帧之前会生成一个预缝合器进程。您可以通过在渲染命令中添加--log=verbose
来确定是否启用了并行编码。args
:作为 FFMPEG 命令参数传递的字符串数组。
您的函数必须返回修改后的字符串数组。
不建议使用此功能。在使用之前,我们想让您了解一些注意事项:
- 渲染命令可能会随着任何新的 Remotion 版本更改,即使是补丁升级也可能会破坏您对此功能的使用。
- 根据所选的编解码器、可用的 CPU 和 RAM,Remotion 可能会或可能不会使用 "并行编码",这将导致执行多个 FFMPEG 命令。您的函数必须能够处理多次调用。
- 当使用 Remotion Lambda 时,此功能不可用。
在使用此 hack 之前,请在 Discord 上联系 Remotion 团队,并询问我们是否愿意以清晰的方式实现您需要的功能 - 我们经常根据用户反馈快速实现新功能。
ffmpegExecutable
ffmpegExecutable
在v4.0中已移除,可选
用于自定义使用的 FFMPEG 可执行文件。默认情况下,将在您的 PATH
中搜索名为 ffmpeg
的二进制文件。
ffprobeExecutable?
v3.0.17
ffprobeExecutable?
在v4.0中已移除,可选
一个绝对路径,用于覆盖要使用的 ffprobe
可执行文件。
返回值
stitchFramesToVideo()
返回一个解析为 nothing
的 Promise。如果一切顺利,输出将放置在 outputLocation
中。