renderMediaOnLambda()
在 Remotion Lambda 上启动渲染过程。可以使用 getRenderProgress() 跟踪进度。
🌐 Kicks off a render process on Remotion Lambda. The progress can be tracked using getRenderProgress().
需要一个已经部署的函数来执行渲染。
需要指定一个站点或Serve URL以确定将要渲染的内容。
🌐 Requires a function 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 {renderMediaOnLambda } from '@remotion/lambda/client';
const {bucketName , renderId } = await renderMediaOnLambda ({
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 导入这个函数,以避免 在无服务器函数中 出现问题。
参数
🌐 Arguments
一个具有以下属性的对象:
🌐 An object with the following properties:
region
你的 Lambda 函数部署在哪个区域。强烈建议你的 Remotion 网站也部署在同一个区域。
🌐 In which region your Lambda function is deployed. It's highly recommended that your Remotion site is also in the same region.
privacy?
可选,自 v3.2.27起。
其中之一:
🌐 One of:
"public"(默认): 渲染的媒体可以通过 S3 URL 公共访问。"private":渲染的媒体不可公开访问,但可以使用 presignUrl() 创建签名链接。"no-acl"(从 v.3.1.7 开始可用):ACL 选项根本没有被设置,如果你使用outName写入另一个不支持 ACL 的存储桶时,此选项很有用。
functionName
已部署的 Lambda 函数的名称。使用 deployFunction() 创建新函数,使用 getFunctions() 获取当前已部署的 Lambda。
🌐 The name of the deployed Lambda function.
Use deployFunction() to create a new function and getFunctions() to obtain currently deployed Lambdas.
framesPerLambda?
视频渲染过程会分布到多个 Lambda 函数中。此设置控制每次 Lambda 调用渲染的帧数。你传入的数字越低,生成的 Lambda 就越多。
🌐 The video rendering process gets distributed across multiple Lambda functions. This setting controls how many frames are rendered per Lambda invocation. The lower the number you pass, the more Lambdas get spawned.
默认值:取决于视频长度
最小值: 4
framesPerLambda 参数不能导致生成超过 200 个函数。请参见:并发
concurrency?v4.0.322
指定用于渲染的 Lambda 函数数量。这是 framesPerLambda 的一种替代方法,允许你直接设置并发量,而无需知道视频时长。
🌐 Specify the number of Lambda functions to use for rendering. This is an alternative to framesPerLambda that allows you to set the concurrency directly without needing to know the video duration.
并发性被定义为 frameCount / framesPerLambda。Remotion 会根据你的并发设置自动计算适当的 framesPerLambda 值。
🌐 The concurrency is defined as frameCount / framesPerLambda. Remotion will automatically calculate the appropriate framesPerLambda value based on your concurrency setting.
最大值:200
最小值:取决于视频长度(必须结果为 framesPerLambda >= 4)
🌐 Maximum value: 200
Minimum value: Depends on video length (must result in framesPerLambda >= 4)
不能与 framesPerLambda 一起使用。只能使用其中之一。
frameRange?
指定单帧(传入 number)或帧范围(传入元组 [number, number])以渲染视频的子集。例如:[0, 9] 以选择前 10 帧。通过传入 null(默认)可渲染合成的所有帧。传入 [number, null] 可以从某一帧渲染到合成的结束。v4.0.421 要渲染静止图片,请使用 renderStillOnLambda()。
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.
metadata?v4.0.216
An object containing metadata to be embedded in the video. See here for which metadata is accepted.
inputProps?
可选,自 v3.2.27起。
传递给所选视频组合的输入属性。。
必须是一个 JSON 对象。
可以从根组件使用 getInputProps() 读取属性。
你可以使用 calculateMetadata() 转换输入属性。
codec
应该使用哪种编解码器来编码视频。
🌐 Which codec should be used to encode the video.
视频编解码器 h264 和 vp8 受到支持,prores 自 v3.2.0 起受到支持。h265 支持已在 v4.0.32 中添加。
🌐 Video codecs h264, and vp8 are supported, prores is supported since v3.2.0. h265 support has been added in v4.0.32.
音频编解码器 mp3、aac 和 wav 也受支持。
🌐 Audio codecs mp3, aac and wav are also supported.
自 v3.3.34 起,选项 h264-mkv 已重命名为 h264。使用 h264 可以获得相同的行为。
🌐 The option h264-mkv has been renamed to just h264 since v3.3.34. Use h264 to get the same behavior.
另请参见 renderMedia() -> codec。
🌐 See also renderMedia() -> codec.
audioCodec?v3.3.41
选择你的音频编码。
🌐 Choose the encoding of your audio.
- 每个 Lambda 块实际上可能会选择未压缩的编解码器,并在最终编码阶段将其转换,以防止音频伪影。
- 默认值取决于所选择的
codec。 - 如果你需要未压缩的音频,请选择
pcm-16。 - 并非所有视频容器都支持所有音频编解码器。
- 如果
codec选项也指定了音频编解码器,则此选项优先。
请参阅 编码指南 以查看默认设置和支持的组合。
🌐 Refer to the Encoding guide to see defaults and supported combinations.
forceHeight?v3.2.40
覆盖默认的合成高度。
🌐 Overrides default composition height.
forceWidth?v3.2.40
覆盖默认的合成宽度。
🌐 Overrides default composition width.
forceFps?v4.0.424
覆盖默认的合成帧率。
🌐 Overrides the default composition FPS.
forceDurationInFrames?v4.0.424
覆盖默认的合成帧数持续时间。
🌐 Overrides the default composition duration in frames.
muted?
禁用音频输出。另请参见 renderMedia() -> muted。
🌐 Disables audio output. See also renderMedia() -> muted.
imageFormat?
可选,自 v3.2.27起。
参见 renderMedia() -> imageFormat。
🌐 See renderMedia() -> imageFormat.
crf?
🌐 See renderMedia() -> crf.
envVariables?
参见 renderMedia() -> envVariables。
🌐 See renderMedia() -> envVariables.
pixelFormat?
参见 renderMedia() -> pixelFormat。
🌐 See renderMedia() -> pixelFormat.
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
jpegQuality?
参见 renderMedia() -> jpegQuality。
🌐 See renderMedia() -> jpegQuality.
quality
quality在 v4.0.0 中重命名为 jpegQuality。
🌐 Renamed to jpegQuality in v4.0.0.
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() 对象中报告,并根据你使用此选项指定的次数进行重试。
🌐 How often a chunk may be retried to render in case the render fails.
If a rendering of a chunk is failed, the error will be reported in the getRenderProgress() object and retried up to as many times as you specify using this option.
只有当错误在 不稳定错误列表 中时,才会执行重试。
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.
outName?
媒体输出的文件名。
🌐 The file name of the media output.
它可以是:
🌐 It can either be:
undefined- 它将默认为out加上适当的文件扩展名,例如:renders/${renderId}/out.mp4。- 一个
string- 它将被保存到与你的网站相同的 S3 存储桶下,键为renders/{renderId}/{outName}。确保在字符串末尾包含文件扩展名。 - 如果你想将对象渲染到不同的存储桶或云提供商,请参见此处的详细说明(/docs/lambda/custom-destination)。
timeoutInMilliseconds?
一个数字,描述渲染可能花多长时间来解决所有 delayRender() 调用 在超时之前。默认值:30000
🌐 A number describing how long the render may take to resolve all delayRender() calls before it times out. Default: 30000
concurrencyPerLambda?v3.0.30
默认情况下,每个 Lambda 函数的并发为 1(一个打开的浏览器标签)。你可以使用此选项自定义此值。
🌐 By default, each Lambda function renders with concurrency 1 (one open browser tab). You may use the option to customize this value.
everyNthFrame?v3.1
只渲染每第 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?v3.1
Allows you to set the number of loops as follows:null(or omitting in the CLI) plays the GIF indefinitely.0disables looping1loops the GIF once (plays twice in total)2loops the GIF twice (plays three times in total) and so on.
downloadBehavior?v3.1.5
当通过浏览器中的 S3 输出链接访问输出文件时,输出文件应如何表现。
可以是:
🌐 How the output file should behave when accessed through the S3 output link in the browser.
Either:
{"type": "play-in-browser"}- 默认设置。视频将在浏览器中播放。{"type": "download", fileName: null}或{"type": "download", fileName: "download.mp4"}- 将添加一个Content-Disposition头,使浏览器下载文件。你可以选择覆盖文件名。
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 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,将抛出错误。
🌐 If a custom out name is specified and a file already exists at this key in the S3 bucket, decide whether the file should be overwritten. Default false.
If the file exists and overwrite is false, an error will be thrown.
rendererFunctionName?v3.3.38
如果指定,将使用此函数来渲染各个块。如果你希望用于渲染块的函数比主协调函数的性能更高或更低,这非常有用。
🌐 If specified, this function will be used for rendering the individual chunks. This is useful if you want to use a function with higher or lower power for rendering the chunks than the main orchestration function.
如果你想使用此选项,该功能必须与主功能位于同一地区、同一账户并且具有相同版本。
🌐 If you want to use this option, the function must be in the same region, the same account and have the same version as the main function.
webhook?v3.2.30
如果指定,Remotion 将向提供的端点发送 POST 请求,以在 Lambda 渲染进程完成、出错或超时后通知你的应用。
🌐 If specified, Remotion will send a POST request to the provided endpoint to notify your application when the Lambda rendering process finishes, errors out or times out.
import {RenderMediaOnLambdaInput } from '@remotion/lambda';
const webhook : RenderMediaOnLambdaInput ['webhook'] = {
url : 'https://mapsnap.app/api/webhook',
secret : process .env .WEBHOOK_SECRET as string,
// Optionally pass up to 1024 bytes of custom data
customData : {
id : 42,
},
};如果你不想设置验证,可以将 secret 设置为 null:
🌐 If you don't want to set up validation, you can set secret to null:
import {RenderMediaOnLambdaInput } from '@remotion/lambda';
const webhook : RenderMediaOnLambdaInput ['webhook'] = {
url : 'https://mapsnap.app/api/webhook',
secret : null,
};forceBucketName?v3.3.42
指定要使用的特定存储桶名称。这不推荐,最好让 Remotion 自动发现正确的存储桶。
🌐 Specify a specific bucket name to be used. This is not recommended, instead let Remotion discover the right bucket automatically.
logLevel?
One of trace, verbose, info, warn, error.Determines how much info is being logged to the console.
Default
info.
如果将 logLevel 设置为 verbose,Lambda 函数将不会清理生成的工件,以便进行调试。除非你在调试问题,否则不要使用它。
🌐 If the logLevel is set to verbose, the Lambda function will not clean up artifacts, to aid debugging. Do not use it unless you are debugging a problem.
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
offthreadVideoThreads?v4.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.
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 客户端。如果你不知道这是什么,你很可能用不到它。
🌐 Passes forcePathStyle to the AWS S3 client. If you don't know what this is, you probably don't need it.
storageClass?v4.0.305
用于渲染媒体的 S3 存储类的 标识符。默认值:undefined(即 STANDARD)。
🌐 An identifier for the S3 storage class of the rendered media. Default: undefined (which is STANDARD).
licenseKey?v4.0.409
License key for sending a usage event using @remotion/licensing.
isProduction?v4.0.409
默认 true
🌐 default true
false if this a development render to not count it as a billable render on remotion.pro. Only can be used in conjuction with licenseKey.
apiKey?v4.0.253
apiKey?v4.0.253在 v4.0.409 中已弃用
🌐 deprecated in v4.0.409
API key for sending a usage event using@remotion/licensing.
dumpBrowserLogs?
dumpBrowserLogs?在 v4.0 中被弃用,取而代之的是 logLevel。
🌐 Deprecated in v4.0 in favor of logLevel.
返回值
🌐 Return value
返回一个 Promise,该 Promise 解析为包含四个属性的对象。其中,renderId、bucketName 对传递给 getRenderProgress() 有用。
🌐 Returns a promise resolving to an object containing four properties. Of these, renderId, bucketName are useful for passing to getRenderProgress().
renderId
此渲染的唯一字母数字标识符。用于获取状态和在 S3 存储桶中查找相关文件。
🌐 A unique alphanumeric identifier for this render. Useful for obtaining status and finding the relevant files in the S3 bucket.
bucketName
用于保存所有文件的 S3 存储桶名称。
🌐 The S3 bucket name in which all files are being saved.
cloudWatchLogsv3.2.10
一个指向 CloudWatch 的链接(如果你没有禁用它),你可以访问该链接查看渲染的日志。
🌐 A link to CloudWatch (if you haven't disabled it) that you can visit to see the logs for the render.
lambdaInsightsUrlv4.0.61
如果你启用了它,以下是 Lambda Insights 的链接。
🌐 A link to the Lambda Insights, if you enabled it.
folderInS3Consolev3.2.43
AWS 控制台中每个分块和渲染所在文件夹的链接。
🌐 A link to the folder in the AWS console where each chunk and render is located.
另请参阅
🌐 See also