Skip to main content

renderMediaOnCloudrun()

EXPERIMENTAL

Cloud Run 处于 Alpha 阶段,这意味着 API 可能会在任何版本中更改,文档尚未完成。请查看 更改日志 以了解最新的重大更改。

在 Remotion Cloud Run 上启动媒体渲染过程。

需要已部署 服务 才能执行渲染。
需要指定一个 站点Serve URL 来确定将要渲染的内容。

示例

tsx
import { renderMediaOnCloudrun } from "@remotion/cloudrun/client";
 
const result = await renderMediaOnCloudrun({
region: "us-east1",
serviceName: "remotion-render-bds9aab",
composition: "MyVideo",
serveUrl:
"https://storage.googleapis.com/remotioncloudrun-123asd321/sites/abcdefgh",
codec: "h264",
});
 
if (result.type === "success") {
console.log(result.bucketName);
console.log(result.renderId);
}
tsx
import { renderMediaOnCloudrun } from "@remotion/cloudrun/client";
 
const result = await renderMediaOnCloudrun({
region: "us-east1",
serviceName: "remotion-render-bds9aab",
composition: "MyVideo",
serveUrl:
"https://storage.googleapis.com/remotioncloudrun-123asd321/sites/abcdefgh",
codec: "h264",
});
 
if (result.type === "success") {
console.log(result.bucketName);
console.log(result.renderId);
}
note

@remotion/cloudrun/client 导入,以避免加载整个渲染器,因为它无法捆绑。

参数

一个具有以下属性的对象:

cloudRunUrl?

可选。如果未提供 serviceName,则必填

应用于执行渲染的 Cloud Run 服务的 URL。您必须设置 cloudRunUrl 或 serviceName,但不能同时设置两者

serviceName?

可选。如果未提供 cloudRunUrl,则必填

应用于执行渲染的 Cloud Run 服务的名称。这与区域一起用于确定服务端点,因为相同的服务名称可以存在于多个区域。

region

您的 Cloud Run 服务部署在哪个 GCP 区域。强烈建议您的 Remotion 站点也位于同一区域。

serveUrl

指向 Remotion 项目的 URL。使用 deploySite() 部署 Remotion 项目。

composition

要渲染的 compositionid

codec

应使用哪种编解码器来编码视频。

支持视频编解码器 h264vp8prores

音频编解码器 mp3aacwav 也受支持。

请参阅renderMedia() -> codec

inputProps?

可选

要传递给视频选定组合的输入属性。
必须是一个 JSON 对象。
从根组件可以使用getInputProps()读取属性。
您可以使用calculateMetadata()来转换输入属性。

privacy?

可选

其中之一:

  • "public"默认):渲染的媒体可以在 Cloud 存储 URL 下公开访问。
  • "private":渲染的媒体不是公开可用的,但对具有正确权限的 GCP 项目内的人员可用。

forceBucketName?

可选

指定要用于输出的特定存储桶名称。生成的 Google Cloud 存储 URL 将采用格式 gs://{bucket-name}/renders/{render-id}/{file-name}。如果未设置,Remotion 将根据区域选择要使用的正确存储桶。

updateRenderProgress?

可选

一个回调,用于呈现进度。

audioCodec?

可选

选择音频的编码方式。

  • 如果需要未压缩音频,请选择 pcm-16
  • 并非所有视频容器都支持所有音频编解码器。
  • 如果 codec 选项还指定了音频编解码器,则此选项优先。

请参阅编码指南以查看默认值和支持的组合。

jpegQuality?

可选

请参阅renderMedia() -> jpegQuality

audioBitrate?

可选

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?

可选

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.

proResProfile?

可选

请参阅renderMedia() -> proResProfile

可选

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

crf?

可选

查看renderMedia() -> crf

pixelFormat?

可选

查看renderMedia() -> pixelFormat

imageFormat?

可选

查看renderMedia() -> imageFormat

scale?

可选

通过因子缩放输出尺寸。查看缩放以了解更多关于此功能的信息。

everyNthFrame?

可选

仅渲染每第n帧。例如,仅每第二帧,每第三帧等。仅适用于渲染GIF。点击此处了解更多详情。

numberOfGifLoops?

可选

Allows you to set the number of loops as follows:
  • null (or omitting in the CLI) plays the GIF indefinitely.
  • 0 disables looping
  • 1 loops the GIF once (plays twice in total)
  • 2 loops the GIF twice (plays three times in total) and so on.

可选,自v3.1.5起可用

在浏览器中通过S3输出链接访问输出文件时的行为。
要么:

downloadBehavior?v4.0.176

在浏览器中通过云存储输出链接访问输出文件时的行为。

  • {"type": "play-in-browser"} - 默认行为。视频将在浏览器中播放。
  • {"type": "download", fileName: null}{"type": "download", fileName: "download.mp4"} - 将添加Content-Disposition头,使浏览器下载文件。您可以选择性地覆盖文件名。

frameRange?

可选

指定要渲染的单个帧(数字)或帧范围(元组 [数字, 数字])。

envVariables?

可选

查看renderMedia() -> envVariables

chromiumOptions?

可选

允许您设置某些Chromium / Google Chrome标志。查看:Chromium标志

disableWebSecurity

boolean - 默认 false

这将主要禁用CORS等安全功能。

ignoreCertificateErrors

boolean - 默认 false

导致无效的SSL证书(如自签名证书)被忽略。

gl

Changelog
  • From Remotion v2.6.7 until v3.0.7, the default for Remotion Lambda was swiftshader, but from v3.0.8 the default is swangle (Swiftshader on Angle) since Chrome 101 added support for it.
  • From Remotion v2.4.3 until v2.6.6, the default was angle, however it turns out to have a small memory leak that could crash long Remotion renders.

Select the OpenGL renderer backend for Chromium.
Accepted values:

  • "angle"
  • "egl"
  • "swiftshader"
  • "swangle"
  • "vulkan" (from Remotion v4.0.41)
  • "angle-egl" (from Remotion v4.0.51)

The default is null, letting Chrome decide, except on Lambda where the default is "swangle"

muted?

可选

禁用音频输出。另请参阅renderMedia() -> muted

forceWidth?

可选

覆盖默认合成宽度。

forceHeight?

可选

覆盖默认合成高度。

logLevel?

One of verbose, info, warn, error.
Determines how much is being logged to the console.
verbose will also log console.log's from the browser.
Default info.

outName?

可选

媒体输出文件名。

可以是:

  • undefined - 默认为 out 加上适当的文件扩展名,例如:renders/${renderId}/out.mp4
  • 一个 string - 将保存到与您的站点相同的云存储桶中,键为 renders/{renderId}/{outName}。请确保在字符串末尾包含文件扩展名。

delayRenderTimeoutInMilliseconds?

可选

描述渲染可能需要多长时间来解析所有 delayRender() 调用在超时之前。默认值:30000

concurrency?

描述应打开多少个浏览器选项卡的数字或字符串。默认值为 "50%"。

note

在 v4.0.76 之前,默认值为 "100%"。现在已与其他服务器端渲染 API 对齐。

enforceAudioTrack?

如果没有其他情况,则渲染静音音轨。

preferLossless?v4.0.123

Uses a lossless audio codec, if one is available for the codec. If you setaudioCodec, it takes priority over preferLossless.

offthreadVideoCacheSizeInBytes?v4.0.23

From v4.0, Remotion has a cache for <OffthreadVideo> frames. The default is null, corresponding to half of the system memory available when the render starts.
This option allows to override the size of the cache. The higher it is, the faster the render will be, but the more memory will be used.
The used value will be printed when running in verbose mode.
Default: null

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.

返回值

返回一个解析为对象的 Promise。

type

使用此项确定响应的结构。可以是:

  • 'success' - 渲染已成功执行。
  • 'crash - Cloud Run 服务已崩溃。

当 type === 'success' 时返回

结果对象包含以下内容:

type

'success' - 渲染已成功执行。

publicUrl?

可选

渲染文件的公共可访问 URL。仅当请求设置了 privacy 属性为 'public' 时可用。

renderId

此渲染的唯一字母数字标识符。用于获取状态并在云存储桶中找到相关文件。

bucketName

所有文件保存在其中的 Cloud Storage 存储桶名称。

privacy

输出文件的隐私设置,可以是:

  • "public-read" - 在 Cloud Storage URL 下公开访问。
  • "project-private" - 不公开,但在 GCP 项目中对具有正确权限的用户可用。

publicUrl

如果隐私设置为公开,则这将是渲染文件的公开访问 URL。如果隐私不是公开,则为 null。

cloudStorageUri

Google Storage 路径,以 gs://{bucket-name} 开头。可与 gsutil CLI 工具一起使用。

size

以 KB 为单位的渲染媒体的大小。

当 type === 'crash' 时返回

生成的对象包含以下内容:

type

'crash' - Cloud Run 服务在没有响应的情况下崩溃。

cloudRunEndpoint

执行渲染时调用的端点。CLI 用于解析服务名称以确定服务的超时和内存限制。这在分析日志时可以用来提供有关崩溃原因的提示。

message

'服务在没有发送响应的情况下崩溃。请检查 GCP 控制台中的日志。' 这用于 CLI 显示错误消息。

requestStartTime

请求发起的日期时间,采用 UTC 格式 - "2020-01-01T00:00:00+02:00"。可用于过滤服务的日志。

requestCrashTime

检测到崩溃的日期时间,采用 UTC 格式 - "2020-01-01T00:00:00+02:00"。可用于过滤服务的日志。

requestElapsedTimeInSeconds

请求开始和崩溃时间之间经过的秒数。可与超时限制进行比较,以了解这可能是崩溃的原因。

参见