Skip to main content

硬件加速编码

编码是将一系列图片转换为视频文件的过程。
除了渲染帧之外,编码是创建视频所需的两个步骤之一。

🌐 Encoding is the process of converting a sequence of images into a video file.
Besides rendering frames, encoding is one of the two steps required to create a video.

从 Remotion v4.0.228 开始,Remotion 在某些情况下支持硬件加速编码。 由于编码是平台和编解码器特定的,目前仅支持少数几种情况。

🌐 From Remotion v4.0.228, Remotion supports hardware-accelerated encoding in some cases.
Since encoding is platform- and codec-specific, only a few scenarios are supported at the moment.

  • 目前,仅支持 macOS(使用 VideoToolbox 加速)
  • ProRes 从 v4.0.228 开始支持,H.264 和 H.265 从 v4.0.236 开始支持

启用硬件加速编码

🌐 Enable hardware accelerated encoding

默认情况下,硬件加速是 "disabled"
如果可用,你可以将 hardwareAcceleration 选项设置为 "if-possible" 来启用硬件加速。
如果你希望在无法进行硬件加速时渲染失败,将该选项设置为 "required"

🌐 By default, hardware acceleration is "disabled".
You can set the hardwareAcceleration option to "if-possible" to enable hardware acceleration if it is available.
If you want the render to fail if hardware acceleration is not possible, set the option to "required".

在 SSR API 中

🌐 In SSR APIs

renderMedia() 函数中使用 hardwareAcceleration 选项。

🌐 Use the hardwareAcceleration option in the renderMedia() function.


await renderMedia({
  composition,
  serveUrl,
  codec: 'prores',
  outputLocation,
  inputProps,
  hardwareAcceleration: 'if-possible',
});

在命令行接口

🌐 In the CLI

npx remotion studio 命令中使用 --hardware-acceleration 选项。

🌐 Use the --hardware-acceleration option in the npx remotion studio command.

npx remotion render MyComp --codec prores --hardware-acceleration if-possible

在工作室

🌐 In the Studio

Remotion Studio 中,你可以在渲染视频时的“高级”选项卡中设置硬件加速选项。

🌐 In the Remotion Studio, you can set the hardware acceleration option in the "Advanced" tab when rendering a video.

使用配置文件

🌐 With the config file

你可以在配置文件中设置setHardwareAcceleration()选项。

🌐 You can set the setHardwareAcceleration() option in the config file.

import {Config} from '@remotion/cli/config';

Config.setHardwareAcceleration('if-possible');

在 Remotion Lambda 和 Cloud Run 中

🌐 In Remotion Lambda and Cloud Run

这些选项在 Remotion Lambda 和 Cloud Run 中不受支持,因为这些云服务不支持硬件加速。

🌐 These options are not supported in Remotion Lambda and Cloud Run, because those cloud services do not support hardware acceleration.

使用 --video-bitrate 控制质量

🌐 Controlling quality using --video-bitrate

请注意,默认情况下使用硬件加速时文件大小显著增大,这可能是因为应用的压缩较少。 我们建议你使用 --video-bitrate 标志来控制文件大小。

🌐 Note that the file size is significantly larger by default when using hardware acceleration, likely because less compression is applied.
We recommend that you use the --video-bitrate flag to control the file size.

我们发现,当导出 H.264 全高清视频时,--video-bitrate=8M 达到的文件大小与软件编码相似。

🌐 We find that --video-bitrate=8M achieves a similar file size than software encoding when exporting a H.264 Full HD video.

crf 选项 与硬件加速编码器不兼容。相反,请使用 --video-bitrate 标志来控制输出视频的质量和文件大小。

🌐 The crf option is not compatible with hardware-accelerated encoders. Instead, use the --video-bitrate flag to control the quality and file size of the output video.

判断是否正在使用硬件加速

🌐 Tell if hardware acceleration is being used

用详细日志运行渲染。 如果渲染使用硬件加速,你会看到类似这样的日志信息:

Encoder: prores_videotoolbox, hardware accelerated: true

不要依赖日志消息的确切措辞来判断是否正在使用硬件加速。

🌐 Don't rely on the exact wording of the log message to determine if hardware acceleration is being used.

另请参阅

🌐 See also