编码指南
由 FFmpeg 提供支持,Remotion 允许你配置各种编码设置。本页的目的是帮助你浏览这些设置,并帮助你选择合适的设置。
🌐 Backed by FFmpeg, Remotion allows you to configure a variety of encoding settings. The goal of this page is to help you navigate through the settings and to help you choose the right one.
选择编解码器
🌐 Choosing a codec
Remotion 支持 5 种视频编解码器:h264(默认)、h265、vp8、vp9 和 prores。虽然 H264 在大多数情况下表现良好,但有时选择其他编解码器会更合适。请参考下表以查看每种编解码器的优缺点。
🌐 Remotion supports 5 video codecs: h264 (default), h265, vp8, vp9 and prores. While H264 will work well in most cases, sometimes it's worth going for a different codec. Refer to the table below to see the advantages and drawbacks of each codec.
| 视频编解码器 | 文件扩展名 | 文件大小 | 编码时间 | 浏览器兼容性 | 是否可硬件加速 |
|---|---|---|---|---|---|
H.264 也称为MPEG-4 | .mp4, .mov或.mkv | 中等 | 非常快 | 非常好 | 否 |
H.265 也称为HEVC | .mp4或.hevc | 中等 | 快 | 非常差 | 否 |
| VP8 | .webm | 小 | 慢 | 一般 | 否 |
| VP9 | .webm | 非常小 | 非常慢 | 一般 | 否 |
| ProRes | .mov | 大 | 快 | 无 | 在macOS上 |
点击浏览器兼容性链接以查看 caniuse.com 上支持的具体浏览器。
你可以使用配置文件中的 Config.setCodec() 设置配置,或使用 --codec 命令行标志。
🌐 You can set a config using Config.setCodec() in the config file or the --codec CLI flag.
硬件加速 从 Remotion 4.0.228 开始可用。
使用CRF设置控制质量
🌐 Controlling quality using the CRF setting
仅适用于 h264、h265、vp8 和 vp9。
🌐 Applies only to h264, h265, vp8 and vp9.
无论你最终使用哪种编解码器,文件大小和视频质量之间总是存在权衡。你可以通过设置所谓的 CRF(恒定速率因子)来控制。数值越低,质量越好,数值越高,文件越小——当然这是以牺牲质量为代价的。
🌐 No matter which codec you end up using, there's always a tradeoff between file size and video quality. You can control it by setting the so called CRF (Constant Rate Factor). The lower the number, the better the quality, the higher the number, the smaller the file is – of course at the cost of quality.
小心:每种编码器都有自己的可接受值范围和不同的默认值。因此,虽然 23 在 H264 视频上看起来非常好,但在 WebM 视频上看起来会很糟。使用此图表来确定使用哪个 CRF 值:
🌐 Be cautious: Every codec has it's own range of acceptable values and a different default. So while 23 will look very good on a H264 video, it will look terrible on a WebM video. Use this chart to determine which CRF value to use:
| 编解码器 | 最小值 - 最佳质量 | 最大值 - 最佳压缩 | 默认 |
|---|---|---|---|
| H264 | 1 | 51 | 18 |
| H265 | 0 | 51 | 23 |
| VP8 | 4 | 63 | 9 |
| VP9 | 0 | 63 | 28 |
你可以使用 Config.setCrf() 函数在配置文件中设置 CRF,或者使用命令行标志 --crf。
🌐 You can set a CRF in the config file using the Config.setCrf() function or use the --crf command line flag.
如果你启用硬件加速,你将无法设置crf。
使用 --video-bitrate 和 --audio-bitrate 控制质量
🌐 Controlling quality using --video-bitrate and --audio-bitrate
使用以下选项设置视频和音频比特率:
🌐 Use the following options to set the video and audio bitrate:
- 在工作室:在渲染对话框中设置视频和音频比特率
- 在 CLI 中:使用
--video-bitrate和--audio-bitrate标志 - 在 SSR、Lambda 和 Cloud Run API 中:使用
videoBitrate和audioBitrate选项。
此选项与其他质量选项不兼容。
🌐 This option is incompatible with other quality options.
使用 ProRes 配置文件控制质量
🌐 Controlling quality using ProRes profile
仅适用于 prores 编解码器。
🌐 Applies only to prores codec.
对于 ProRes,没有 CRF 选项,但可以使用 --prores-profile 标志 或 setProResProfile 配置文件选项设置配置文件。
🌐 For ProRes, there is no CRF option, but there are profiles which you can set using the --prores-profile flag or the setProResProfile config file option.
| 值 | FFmpeg 设置 | 比特率 | 支持 alpha 通道 |
|---|---|---|---|
"proxy" | 0 | ~45Mbps | 否 |
"light" | 1 | ~102Mbps | 否 |
| 2 | ~147Mbps | 否 |
"hq" | 3 | ~220Mbps | 否 |
"4444" | 4 | ~330Mbps | 是 |
"4444-xq" | 4 | ~500Mbps | 是 |
更高的比特率意味着更高的质量和更大的文件大小。
🌐 Higher bitrate means higher quality and higher file size.
仅音频导出
🌐 Audio-only export
你可以将 mp3、wav 或 aac 作为编解码器传入。如果你这样做,将会输出对应格式的音频文件。质量设置将被忽略。
🌐 You can pass mp3, wav or aac as a codec. If you do it, an audio file will be output in the corresponding format. Quality settings will be ignored.
动图
🌐 GIFs
你也可以将你的视频导出为 GIF。
🌐 You can also render your video as a GIF.
音频编解码器
🌐 Audio codec
从 v3.3.42 起可用
🌐 available from v3.3.42
使用 --audio-codec 标志,你可以设置嵌入视频中的音频格式。并非所有编解码器和音频编解码器组合都受支持,某些组合需要特定的文件扩展名和容器格式。
🌐 Using the --audio-codec flag, you can set the format of the audio that is embedded in the video. Not all codec and audio codec combinations are supported and certain combinations require a certain file extension and container format.
容器格式将根据文件扩展名自动推导。
🌐 The container format will be automatically derived based on the file extension.
| Video codec | Default | Supported audio codecs | Possible file extensions |
|---|---|---|---|
h264 | ✅ | aac | .mp4 (default), .mkv , .mov |
pcm-16 | .mkv (default), .mov | ||
mp3 | .mp4 (default), .mkv , .mov | ||
h264-ts | pcm-16 | .ts (default) | |
| ✅ | aac | .ts (default) | |
aac | ✅ | aac | .aac (default), .3gp , .m4a , .m4b , .mpg , .mpeg |
pcm-16 | .wav (default) | ||
h265 | ✅ | aac | .mp4 (default), .mkv , .hevc |
pcm-16 | .mkv (default) | ||
mp3 | ✅ | mp3 | .mp3 (default) |
pcm-16 | .wav (default) | ||
prores | * | aac | .mov (default), .mkv , .mxf |
| ✅ | pcm-16 | .mov (default), .mkv , .mxf | |
vp8 | ✅ | opus | .webm (default) |
pcm-16 | .mkv (default) | ||
vp9 | ✅ | opus | .webm (default) |
pcm-16 | .mkv (default) | ||
wav | ✅ | pcm-16 | .wav (default) |
GIF不支持音频。
🌐 GIFs don't support audio.
- 注意:在
v4.0.0之前的版本中,ProRes的默认音频编解码器是aac。现在是pcm-16。
文件扩展名
🌐 File extensions
在渲染媒体时指定文件扩展名将决定默认编解码器。只要上表中的组合受支持,你可以使用 --codec 覆盖编解码器。
🌐 Specifying a file extension when rendering media will determine the default codec. You may override the codec using --codec as long as the combination is supported in the table above.
| File extension | Default codec |
|---|---|
| .3gp | aac |
| .aac | aac |
| .gif | gif |
| .hevc | h265 |
| .m4a | aac |
| .m4b | aac |
| .mkv | h264-mkv |
| .mov | prores |
| .mp3 | mp3 |
| .mp4 | h264 |
| .mpeg | aac |
| .mpg | aac |
| .mxf | prores |
| .wav | wav |
| .webm | vp8 |
| .ts | h264-ts |
你还需要其他哪些设置?
🌐 What other settings do you need?
FFmpeg 支持的众多选项中,你希望在 Remotion 中看到哪些被公开?请通过在我们的问题追踪器上提交问题让我们知道!
🌐 Which of the dozens of options that FFmpeg supports would you like to see exposed in Remotion? Let us know by opening an issue on our issue tracker!
另请参阅
🌐 See also