Skip to main content

renderMediaOnCloudrun()

EXPERIMENTAL

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

🌐 Kicks off a media rendering process on Remotion Cloud Run.

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

🌐 Requires a service to already be deployed to execute the render.
A site or a Serve URL needs to be specified to determine what will be rendered.

示例

🌐 Example

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 导入以避免加载整个渲染器,因为它无法被打包。

参数

🌐 Arguments

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

🌐 An object with the following properties:

cloudRunUrl?

如果未提供 serviceName,则为必填。用于执行渲染的 Cloud Run 服务的 URL。你必须设置 cloudRunUrlserviceName 中的一个,但不能同时设置两个。

🌐 Required if serviceName not supplied. The url of the Cloud Run service which should be used to perform the render. You must set either cloudRunUrl or serviceName, but not both.

serviceName?

如果未提供 cloudRunUrl,则为必填项。用于执行渲染的 Cloud Run 服务的名称。此名称与区域结合使用以确定服务端点,因为同一服务名称可以存在于多个区域。

🌐 Required if cloudRunUrl not supplied. The name of the Cloud Run service which should be used to perform the render. This is used in conjunction with the region to determine the service endpoint, as the same service name can exist across multiple regions.

region

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

🌐 In which GCP region your Cloud Run service is deployed. It's highly recommended that your Remotion site is also in the same region.

serveUrl

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

🌐 A URL pointing to a Remotion project. Use deploySite() to deploy a Remotion project.

composition

你想要呈现的作品id

🌐 The id of the composition you want to render.

codec

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

🌐 Which codec should be used to encode the video.

支持视频编解码器 h264vp8prores

🌐 Video codecs h264, vp8 and prores are supported.

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

🌐 Audio codecs mp3, aac and wav are also supported.

另请参见 renderMedia() -> codec

🌐 See also renderMedia() -> codec.

metadata?v4.0.216

An object containing metadata to be embedded in the video. See here for which metadata is accepted.

inputProps?

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

privacy?

其中之一:

🌐 One of:

  • "public" (默认): 渲染的媒体可以通过云存储 URL 公共访问。
  • "private":渲染的媒体不对公众开放,但对于拥有正确权限的人,在 GCP 项目内是可用的。

forceBucketName?

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

🌐 Specify a specific bucket name to be used for the output. The resulting Google Cloud Storage URL will be in the format gs://{bucket-name}/renders/{render-id}/{file-name}. If not set, Remotion will choose the right bucket to use based on the region.

updateRenderProgress?

import type {UpdateRenderProgress} from '@remotion/cloudrun/client';

const updateRenderProgress: UpdateRenderProgress = (progress: number, error: boolean) => {
  if (error) {
    console.error('Render failed');
  } else {
    console.log(`Render progress: ${progress * 100}%`);
  }
};

renderStatusWebhook?

你的 webhook URL,将在渲染进度更新时被调用。这将通过 POST 请求发送。

🌐 Your webhook URL that will be called with the progress of the render. This will be sent using a POST request.

参数

🌐 Arguments

  • url:Webhook URL 端点。
  • headers:要发送的头部。Content-Type: application/json 会自动添加。
  • data:你希望与进度数据一起发送的数据。
  • webhookProgressInterval (optional):调用 webhook 的间隔。默认值为 0.1(10%)。(最小值: 0.01, 最大值: 1)
Example Webhook URL Declaration
{ "url": "https://example.com/webhook", "headers": { "Authorization": "Bearer 1234567890" }, "data": { "projectId": "1234567890" }, "webhookProgressInterval": 0.1 }

示例 Webhook 响应

🌐 Example Webhook Response

Example Webhook Response
{ "progress": 0.1, "renderedFrames": 100, "encodedFrames": 100, "renderId": "1234567890", "projectId": "1234567890" }

renderIdOverride?

为渲染提供一个具体的渲染ID。否则将生成一个随机的ID。

🌐 Provide a specific render ID for the render. Otherwise a random one will be generated.

note

你将负责确保渲染 ID 是唯一的,否则它将覆盖具有相同配置渲染 ID 的现有渲染。

audioCodec?

选择你的音频编码。

🌐 Choose the encoding of your audio.

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

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

🌐 Refer to the Encoding guide to see defaults and supported combinations.

jpegQuality?

参见 renderMedia() -> jpegQuality

🌐 See 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

🌐 See 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

🌐 See renderMedia() -> crf.

pixelFormat?

参见 renderMedia() -> pixelFormat

🌐 See renderMedia() -> pixelFormat.

imageFormat?

参见 renderMedia() -> imageFormat

🌐 See renderMedia() -> imageFormat.

scale?

Scales the output dimensions by a factor. For example, a 1280x720px frame will become a 1920x1080px frame with a scale factor of 1.5. See Scaling for more details.

everyNthFrame?

只渲染每第 n 帧。例如,只渲染每第二帧、每第三帧等。仅适用于 GIF 渲染。更多详情请见这里。

🌐 Renders only every nth frame. For example only every second frame, every third frame and so on. Only works for rendering GIFs. See here for more details.

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.

downloadBehavior?v4.0.176

当通过浏览器中的云存储输出链接访问输出文件时,该文件应如何表现。

🌐 How the output file should behave when accessed through the Cloud Storage output link in the browser.

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

frameRange?

指定单个帧(一个数字)或一系列帧(一个元组 [数字, 数字])进行渲染。传递 [number, null] 从某一帧渲染到合成的末尾。v4.0.421

envVariables?

参见 renderMedia() -> envVariables

🌐 See renderMedia() -> envVariables.

chromiumOptions?

允许你设置某些 Chromium / Google Chrome 标志。见:Chromium 标志

🌐 Allows you to set certain Chromium / Google Chrome flags. See: Chromium flags.

disableWebSecurity

boolean - 默认 false

🌐 boolean - default false

这将尤其会禁用 CORS 以及其他安全功能。

🌐 This will most notably disable CORS among other security features.

ignoreCertificateErrors

boolean - 默认 false

🌐 boolean - default false

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

🌐 Results in invalid SSL certificates, such as self-signed ones, being ignored.

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

🌐 Disables audio output. See also renderMedia() -> muted.

forceWidth?

覆盖默认的合成宽度。

🌐 Overrides default composition width.

forceHeight?

覆盖默认的合成高度。

🌐 Overrides default composition height.

forceFps?v4.0.424

覆盖默认的合成帧率。

🌐 Overrides the default composition FPS.

forceDurationInFrames?v4.0.424

覆盖默认的合成帧数持续时间。

🌐 Overrides the default composition duration in frames.

logLevel?

One of trace, verbose, info, warn, error.
Determines how much info is being logged to the console.

Default info.

outName?

媒体输出的文件名。

🌐 The file name of the media output.

它可以是:

🌐 It can either be:

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

delayRenderTimeoutInMilliseconds?

一个数字,描述渲染可能花多长时间来解决所有 delayRender() 调用 在超时之前。默认值:30000

🌐 A number describing how long the render may take to resolve all delayRender() calls before it times out. Default: 30000

concurrency?

一个数字或字符串,用于描述应该打开多少个浏览器标签页。默认值是“50%”。

🌐 A number or a string describing how many browser tabs should be opened. Default "50%".

note

在 v4.0.76 之前,这默认是“100%”。现在它已与其他服务器端渲染 API 对齐。

enforceAudioTrack?

如果没有其他音轨,则渲染一个静音音轨。

🌐 Render a silent audio track if there wouldn't be any otherwise.

preferLossless?v4.0.123

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

mediaCacheSizeInBytes?v4.0.352

Specify the maximum size of the cache that <Video> and <Audio> from @remotion/media may use combined, in bytes.
The default is half of the available system memory when the render starts.

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

offthreadVideoThreadsv4.0.261

The number of threads that<OffthreadVideo> can start to extract frames. The default is 2. Increase carefully, as too many threads may cause instability.

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.

返回值

🌐 Return value

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

🌐 Returns a promise resolving to an object.

type

使用此来确定回应的结构。它可以是:

🌐 Use this to determine the structure of the response. It can either be:

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

当 type === 'success' 时返回

🌐 Return when type === 'success'

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

🌐 The resulting object contains the following:

type

'success' - 渲染已成功完成。

publicUrl?

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

🌐 The publicly accessible URL of the rendered file. Only available when the request had the privacy property set to 'public'.

renderId

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

🌐 A unique alphanumeric identifier for this render. Useful for obtaining status and finding the relevant files in the Cloud Storage bucket.

bucketName

用于保存所有文件的云存储桶名称。

🌐 The Cloud Storage bucket name in which all files are being saved.

privacy

输出文件的隐私,任选其一:

🌐 Privacy of the output file, either:

  • "public-read" - 可通过云存储 URL 公共访问。
  • “项目私有” - 不公开,但在 GCP 项目内对拥有正确权限的人可用。

publicUrl

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

🌐 If the privacy is set to public, this will be the publicly accessible URL of the rendered file. If the privacy is not public, this will be null.

cloudStorageUri

gs://{bucket-name} 开头的 Google 存储路径。可以与 gsutil 命令行工具一起使用。

🌐 Google Storage path, beginning with gs://{bucket-name}. Can be used with the gsutil CLI tool.

size

渲染媒体的大小(KB)。

🌐 Size of the rendered media in KB.

当 type === 'crash' 时返回

🌐 Return when type === 'crash'

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

🌐 The resulting object contains the following:

type

'crash' - Cloud Run 服务已崩溃且未响应。

cloudRunEndpoint

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

🌐 Endpoint that was called when executing the render. Used by the CLI to parse the service name to determine timeout and memory limit of the service. This can then be used when analysing the logs, to provide a hint as to the reason of the crash.

message

“服务在未发送响应的情况下崩溃。请在 GCP 控制台中检查日志。” 这是 CLI 用于显示错误消息时使用的文本。

requestStartTime

请求发出的日期时间,使用 UTC 格式 - "2020-01-01T00:00:00+02:00"。对于过滤服务日志可能很有用。

🌐 datetime of when the request was made, in UTC format - "2020-01-01T00:00:00+02:00". Can be useful for filtering the logs of the service.

requestCrashTime

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

🌐 datetime of when the crash was detected, in UTC format - "2020-01-01T00:00:00+02:00". Can be useful for filtering the logs of the service.

requestElapsedTimeInSeconds

从请求开始到崩溃时间经过的秒数。可以与超时限制进行对比,以了解这是否是导致崩溃的可能原因。

🌐 Seconds elapsed between the request start and crash time. Can be checked against the timeout limit to understand if this was the likely cause of the crash.

另请参阅

🌐 See also