Skip to main content

在编辑器中渲染入门

使用 Remotion Lambda,一个在 AWS Lambda 上的分布式渲染器,将视频渲染为 MP4 是可行的。

🌐 Rendering videos to MP4 works using Remotion Lambda, a distributed renderer on AWS Lambda.

设置

🌐 Setup

按照Remotion Lambda 设置说明逐步操作,以设置你的 AWS 账户。

🌐 Follow the Remotion Lambda setup instructions step-by-step to set up your AWS account.

note

如果你已经设置了资源上传,你应该跳过 Remotion Lambda 设置说明的第 4 步和第 5 步。
不要创建新用户,而是选择你之前创建的用户。

之后,在 .env 文件中填写以下数值:

🌐 After that, fill in the following values in the .env file:

REMOTION_AWS_REGION=
REMOTION_AWS_ACCESS_KEY_ID=
REMOTION_AWS_SECRET_ACCESS_KEY=
REMOTION_AWS_BUCKET_NAME=

现在,你可以通过运行以下命令来部署 Lambda 函数并创建站点:

🌐 Now, you can deploy a Lambda function and create a site by running:

bun deploy.ts
note

如果你收到错误 'MemorySize' value failed to satisfy constraint: Member must have value less than or equal to 3008,你需要通过将 MEM_SIZE_IN_MB 变量改为较低的值来降低你的 Lambda 函数的内存大小。你可能在使用 AWS 免费套餐或有较低的并发限制,这可能会阻碍你渲染大量视频的能力。

或者,运行构建命令也会构建站点并将其部署到你的 S3 存储桶:

🌐 Alternatively, running the build command will also build the site and deploy it to your S3 bucket:

npm run build

如果未设置所需的 AWS 环境变量,构建仍将成功并且不会抛出错误——只是将跳过部署到 S3。

🌐 If the required AWS environment variables are not set, the build will still succeed and not throw an error—the deployment to S3 will simply be skipped.

每当出现以下情况时,你应重新执行部署:

🌐 You should re-execute the deployment whenever:

  • 你改变了状态的结构,例如添加新的字段或条目
  • 你改变视频的视觉呈现方式
  • 你升级到新的 Remotion 版本

如果基础设施已经存在,运行部署脚本不会有任何效果。因此,你可以随意运行它。

🌐 Running the deployment script if the infrastructure already exists will not do anything.
Therefore, you can run it as often as you want.

AWS基础设施的自动部署

🌐 Auto-deployment of AWS infrastructure

默认情况下,Lambda 也会部署在你的部署管道中,因此每当你部署应用时,它都会执行。 这意味着无论你何时部署到例如 Vercel,S3 上的网站也会被更新,并且如果不存在具有你指定配置的 Lambda 函数,则会创建一个。

🌐 By default, the Lambda will be deployed in your deployment pipeline as well, so that it executes whenever you deploy your app.
That means whenever you deploy to e.g. Vercel, the site on S3 will be updated as well and a Lambda function will be created if none exists with your specified configuration.

这可以防止你在进行更改时忘记部署。

🌐 This prevents you from forgetting to deploy whenever you make a change.

为了使部署更稳健,我们建议将站点的生产部署与开发部署分开,例如根据 VERCEL_ENV 环境变量为站点赋予不同的名称:

🌐 To make the deployment more robust, we recommend to separate production deployments from development deployments of the site, for example by giving the site a different name based on the VERCEL_ENV environment variable:

export const SITE_NAME = process.env.VERCEL_ENV === 'production' ? 'remotion-editor-starter' : 'remotion-editor-starter-dev';

你不需要在生产和开发之间分开部署功能

渲染

🌐 Rendering

非常简单:当在编辑器启动器中没有选择任何项目时,检查器(即组合检查器)中会显示一个渲染按钮。

🌐 Is very simple: When no item is selected in the Editor Starter, a Render button shows up in the inspector (i.e., composition inspector).

调用后端端点 /api/render 以触发渲染。 触发后,轮询 /api/progress 以检查渲染进度。

🌐 The backend endpoint /api/render is invoked to trigger a render.
Once triggered, /api/progress is polled to check the progress of the render.

一旦渲染完成,它将被上传到你的 S3 存储桶,并且是公开可用的。 调整你传递给 renderMediaOnLambda() 的参数以更改各种设置——例如隐私设置、输出格式、质量等。

🌐 Once the render is done, it is being uploaded to your S3 bucket and is publicly available.
Tweak the params you pass to renderMediaOnLambda() to change various settings - for example the privacy settings, the output format, quality, etc.

另请参阅

🌐 See also