renderMediaOnLambda()
在 Remotion Lambda 上启动渲染过程。可以使用 getRenderProgress() 来跟踪进度。
需要已部署 function 来执行渲染。
需要指定一个 site 或 Serve URL 来确定将要渲染的内容。
示例
tsx
import {renderMediaOnLambda } from "@remotion/lambda/client";const {bucketName ,renderId } = awaitrenderMediaOnLambda ({region : "us-east-1",functionName : "remotion-render-bds9aab",composition : "MyVideo",serveUrl :"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",codec : "h264",});
tsx
import {renderMediaOnLambda } from "@remotion/lambda/client";const {bucketName ,renderId } = awaitrenderMediaOnLambda ({region : "us-east-1",functionName : "remotion-render-bds9aab",composition : "MyVideo",serveUrl :"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",codec : "h264",});
最好从 @remotion/lambda/client
中导入此函数,以避免在 无服务器函数 中出现问题。
参数
一个具有以下属性的对象:
region
Lambda 函数部署的区域。强烈建议您的 Remotion 站点也位于同一区域。
privacy
自 v3.2.27 起可选
其中之一:
"public"
(默认):渲染的媒体可以通过 S3 URL 公开访问。"private"
:渲染的媒体不是公开的,但可以 使用 presignUrl() 创建签名链接。"no-acl"
(从 v.3.1.7 起可用):不设置 ACL 选项,如果您要写入不支持 ACL 的另一个存储桶,可以使用outName
。
functionName
部署的 Lambda 函数的名称。
使用 deployFunction()
创建新函数,使用 getFunctions()
获取当前部署的 Lambdas。
framesPerLambda?
可选
视频渲染过程分布在多个 Lambda 函数中。此设置控制每个 Lambda 调用渲染多少帧。传递的数字越低,生成的 Lambda 就越多。
默认值:取决于视频长度
最小值:4
markdown
:::note`framesPerLambda` 参数不能导致生成超过 200 个函数。参见:[并发性](/docs/lambda/concurrency):::### `frameRange?`_number | [number, number] - 可选_指定单个帧(传递一个 `number`)或一系列帧(传递一个元组 `[number, number]`)以渲染视频的子集。例如:`[0, 9]` 选择前 10 帧。通过传递 `null`(默认)来渲染合成的所有帧。要渲染静态图,请使用 [`renderStillOnLambda()`](/docs/lambda/renderstillonlambda)。### `serveUrl`指向 Remotion 项目的 URL。使用 [`deploySite()`](/docs/lambda/deploysite) 部署 Remotion 项目。### `composition`您要渲染的[合成](/docs/composition)的 `id`。### `inputProps`_自 v3.2.27 起可选_[要传递给视频所选合成的输入属性。](/docs/passing-props#passing-input-props-in-the-cli)必须是 JSON 对象。从根组件中,可以使用 [`getInputProps()`](/docs/get-input-props) 读取属性。您可以使用 [`calculateMetadata()`](/docs/calculate-metadata) 转换输入属性。### `codec`应使用哪种编解码器来编码视频。支持视频编解码器 `h264` 和 `vp8`,自 `v3.2.0` 起支持 `prores`。`h265` 支持已在 `v4.0.32` 中添加。音频编解码器 `mp3`、`aac` 和 `wav` 也受支持。自 `v3.3.34` 起,选项 `h264-mkv` 已更名为 `h264`。使用 `h264` 可获得相同的行为。另请参见 [`renderMedia() -> codec`](/docs/renderer/render-media#codec)。### `audioCodec?`_可选__"pcm-16" | "aac" | "mp3" | "opus",自 v3.3.41 起可用_选择音频的编码方式。- 每个 Lambda 块实际上可能会选择一种无损编解码器,并在最终编码阶段将其转换为避免音频伪影。- 默认取决于所选的 `codec`。- 如果需要无损音频,请选择 `pcm-16`。- 并非所有视频容器都支持所有音频编解码器。- 如果 `codec` 选项还指定了音频编解码器,则此选项优先。
markdown
:::note`framesPerLambda` 参数不能导致生成超过 200 个函数。参见:[并发性](/docs/lambda/concurrency):::### `frameRange?`_number | [number, number] - 可选_指定单个帧(传递一个 `number`)或一系列帧(传递一个元组 `[number, number]`)以渲染视频的子集。例如:`[0, 9]` 选择前 10 帧。通过传递 `null`(默认)来渲染合成的所有帧。要渲染静态图,请使用 [`renderStillOnLambda()`](/docs/lambda/renderstillonlambda)。### `serveUrl`指向 Remotion 项目的 URL。使用 [`deploySite()`](/docs/lambda/deploysite) 部署 Remotion 项目。### `composition`您要渲染的[合成](/docs/composition)的 `id`。### `inputProps`_自 v3.2.27 起可选_[要传递给视频所选合成的输入属性。](/docs/passing-props#passing-input-props-in-the-cli)必须是 JSON 对象。从根组件中,可以使用 [`getInputProps()`](/docs/get-input-props) 读取属性。您可以使用 [`calculateMetadata()`](/docs/calculate-metadata) 转换输入属性。### `codec`应使用哪种编解码器来编码视频。支持视频编解码器 `h264` 和 `vp8`,自 `v3.2.0` 起支持 `prores`。`h265` 支持已在 `v4.0.32` 中添加。音频编解码器 `mp3`、`aac` 和 `wav` 也受支持。自 `v3.3.34` 起,选项 `h264-mkv` 已更名为 `h264`。使用 `h264` 可获得相同的行为。另请参见 [`renderMedia() -> codec`](/docs/renderer/render-media#codec)。### `audioCodec?`_可选__"pcm-16" | "aac" | "mp3" | "opus",自 v3.3.41 起可用_选择音频的编码方式。- 每个 Lambda 块实际上可能会选择一种无损编解码器,并在最终编码阶段将其转换为避免音频伪影。- 默认取决于所选的 `codec`。- 如果需要无损音频,请选择 `pcm-16`。- 并非所有视频容器都支持所有音频编解码器。- 如果 `codec` 选项还指定了音频编解码器,则此选项优先。
请参考编码指南查看默认值和支持的组合。
forceHeight?
可选,自 v3.2.40 起可用
覆盖默认合成高度。
forceWidth?
可选,自 v3.2.40 起可用
覆盖默认合成宽度。
muted?
可选
禁用音频输出。另请参阅renderMedia() -> muted
。
imageFormat
自 v3.2.27 起可选
参见renderMedia() -> imageFormat
。
crf?
可选
envVariables?
可选
参见renderMedia() -> envVariables
。
pixelFormat?
可选
参见renderMedia() -> pixelFormat
。
proResProfile?
可选
参见renderMedia() -> proResProfile
。
x264Preset?
可选
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
jpegQuality
参见renderMedia() -> jpegQuality
。
quality
quality
在 v4.0.0 中更名为 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.
maxRetries
自 v3.2.27 起可选,默认为 1
在渲染失败的情况下,一个块可以重试渲染的次数。
如果一个块的渲染失败,错误将在getRenderProgress()
对象中报告,并根据您使用此选项指定的次数重试。
只有当错误在易出错错误列表中时,才会执行重试。
scale?
可选
通过因子缩放输出尺寸。请参阅缩放以了解更多关于此功能的信息。
outName?
可选
媒体输出的文件名。
可以是:
undefined
- 默认为out
加上适当的文件扩展名,例如:renders/${renderId}/out.mp4
。- 一个
string
- 将保存到与您的站点相同的 S3 存储桶下的键renders/{renderId}/{outName}
。请确保在字符串末尾包含文件扩展名。 - 如果要渲染到不同的存储桶或云提供商,则为对象 - 请参阅此处获取详细说明。
timeoutInMilliseconds?
可选
描述渲染可能需要多长时间来解析所有 delayRender()
调用 在超时之前。默认值:30000
concurrencyPerLambda?
可选,自 v3.0.30 起可用
默认情况下,每个 Lambda 函数以并发 1(一个打开的浏览器选项卡)进行渲染。您可以使用此选项来自定义此值。
everyNthFrame?
可选,自 v3.1 起可用
仅渲染每第 n 帧。例如,仅每第二帧,每第三帧等。仅适用于渲染 GIF。请参阅此处获取更多详细信息。
numberOfGifLoops?
可选,自 v3.1 起可用
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.
downloadBehavior?
可选,自 v3.1.5 起可用
在通过浏览器中的 S3 输出链接访问输出文件时的行为。
要么:
{"type": "play-in-browser"}
- 默认选项。视频将在浏览器中播放。{"type": "download", fileName: null}
或{"type": "download", fileName: "download.mp4"}
- 将添加一个Content-Disposition
头,使浏览器下载文件。您可以选择性地覆盖文件名。
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 isswangle
(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"
overwrite?
从 v3.2.25 版本开始可用
如果指定了自定义输出名称,并且 S3 存储桶中已经存在该键对应的文件,则决定是否覆盖该文件。默认为 false
。
如果文件已存在且 overwrite
为 false
,则会抛出错误。
rendererFunctionName?
可选,从 v3.3.38 版本开始可用
如果 指定了此函数,将用于渲染单个块。如果要使用比主协调函数具有更高或更低权限的函数来渲染块,这将非常有用。
如果要使用此选项,函数必须与主函数在同一区域、同一帐户并且具有相同的版本。
webhook?
可选,从 v3.2.30 版本开始可用
如果指定了,Remotion 将向提供的端点发送 POST 请求,以通知您的应用程序 Lambda 渲染过程何时完成、出错或超时。
tsx
import {RenderMediaOnLambdaInput } from "@remotion/lambda";constwebhook :RenderMediaOnLambdaInput ["webhook"] = {url : "https://mapsnap.app/api/webhook",secret :process .env .WEBHOOK_SECRET as string,// Optionally pass up to 1024 bytes of custom datacustomData : {id : 42,},};
tsx
import {RenderMediaOnLambdaInput } from "@remotion/lambda";constwebhook :RenderMediaOnLambdaInput ["webhook"] = {url : "https://mapsnap.app/api/webhook",secret :process .env .WEBHOOK_SECRET as string,// Optionally pass up to 1024 bytes of custom datacustomData : {id : 42,},};
如果不想设置验证,可以将 secret
设置为 null:
tsx
import {RenderMediaOnLambdaInput } from "@remotion/lambda";constwebhook :RenderMediaOnLambdaInput ["webhook"] = {url : "https://mapsnap.app/api/webhook",secret : null,};
tsx
import {RenderMediaOnLambdaInput } from "@remotion/lambda";constwebhook :RenderMediaOnLambdaInput ["webhook"] = {url : "https://mapsnap.app/api/webhook",secret : null,};
forceBucketName?
可选,从 v3.3.42 版本开始可用
指定要使用的特定存储桶名称。不建议这样做,而是让 Remotion 自动发现正确的存储桶。
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
.
如果 logLevel
设置为 verbose
,Lambda 函数将不会清理工件,以帮助调试。除非您正在调试问题,否则不要使用它。
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.
deleteAfter?
v4.0.32
Automatically delete the render after a certain period. Accepted values are 1-day
, 3-days
, 7-days
and 30-days
.For this to work, your bucket needs to have lifecycles enabled.
preferLossless?
v4.0.123
Uses a lossless audio codec, if one is available for the codec. If you setaudioCodec
, it takes priority over preferLossless
.
forcePathStyle?
v4.0.202
将 forcePathStyle
传递给 AWS S3 客户端。如果您不知道这是什么,您可能不需要它。
dumpBrowserLogs?
dumpBrowserLogs?
可选 - 默认为 false
,在 v4.0 中已弃用
已弃用,建议使用 logLevel
。
返回值
返回一个解析为包含四个属性的对象的 Promise。其中,renderId
、bucketName
对于传递给 getRenderProgress()
是有用的。
renderId
此渲染的唯一字母数字标识符。用于获取状态并在 S3 存储桶中找到相关文件。
bucketName
正在保存所有文件的 S3 存储桶名称。
cloudWatchLogs
v3.2.10
一个指向 CloudWatch 的链接(如果您未禁用它),您可以访问以查看渲染的日志。
lambdaInsightsUrl
v4.0.61
一个指向 Lambda Insights 的链接,如果您已启用。
folderInS3Console
v3.2.43
一个指向 AWS 控制台中每个块和渲染所在文件夹的链接。