在 Lambda 上渲染
如果你想更快地渲染长视频,或者想同时渲染你视频的不同版本,你可以利用 @remotion/lambda。
🌐 If you want to render long videos faster or you want to render different versions of your videos at the same time, you can take advantage of @remotion/lambda.
设置 Lambda
🌐 Setup Lambda
首先,你需要设置 Remotion Lambda。 按照 这里 显示的说明的第1到第7步进行操作。
🌐 First you need to set up Remotion Lambda.
Follow steps 1-7 of the instructions shown here.
部署和呈现
🌐 Deploy and render
你的网站将获得一个公开可访问的 URL。请确保将其保密,并且不要与任何人分享。
将以下函数和站点部署命令以及渲染命令添加到一个 shell 脚本中,每次想要渲染视频时都可以执行它:
🌐 Add the following function and site deployment commands as well as the render command into a shell script you can execute each time you want to render a video:
bunx remotion lambda functions deploy --memory=3009
bunx remotion lambda sites create --site-name=remotion-recorder --enable-folder-expiry
bunx remotion lambda render remotion-recorder <composition-id> --delete-after="7-days"解释:
🌐 Explanation:
- 部署 一个 Lambda 函数。将内存设置为 3009MB 将为你提供 3 个 vCPU。如果函数已经存在,则不会发生任何事情,因此每次运行该命令都是安全的。
- 上传 录音机和你的录音到 S3。给网站命名为
remotion-recorder,如果你愿意可以选择其他名字。--enable-folder-expiry标志将使自动删除的视频可以被渲染。如果已经存在同名网站,它将会更新该网站。 - 渲染视频。将网站名称和合成 ID传递给命令。
--delete-after标志将在指定时间后删除视频,如果你想保留视频,可以移除此标志。
针对特定平台的渲染
🌐 Rendering for a specific platform
你可以使用--props来覆盖你在组合中设置的默认属性。
这里有一个用于在所有平台上渲染视频的脚本:
🌐 You may use --props to override the default props that you set in your composition.
Here is a script to render a video for all platforms:
bunx remotion lambda render --props='{"platform": "youtube", "layout": "landscape"}' remotion-recorder <composition-id>
bunx remotion lambda render --props='{"platform": "x", "layout": "square"}' remotion-recorder <composition-id>
bunx remotion lambda render --props='{"platform": "linkedin", "layout": "square"}' remotion-recorder <composition-id>我们的脚本
🌐 Our script
为了渲染我们的视频,我们创建一个 TypeScript 文件并使用 bun lambda.ts 运行它。
🌐 For rendering our videos, we create a TypeScript file and run it with bun lambda.ts.
lambda.tsimport {$} from 'bun'; const siteName = 'our-recorder'; const compositionId = 'installwhispercpp'; const configs = [ { canvasLayout: 'square', platform: 'linkedin', }, { canvasLayout: 'square', platform: 'x', }, { canvasLayout: 'landscape', platform: 'youtube', }, ]; await $`bunx remotion lambda sites create --site-name=${siteName}`; for (const config of configs) { await $`bunx remotion lambda render ${siteName} ${compositionId} --props='${JSON.stringify(config)}'`; }