Skip to main content

设置

EXPERIMENTAL

1. 安装 @remotion/cloudrun

🌐 1. Install @remotion/cloudrun

npx remotion add @remotion/cloudrun

2. 创建一个 GCP 项目

🌐 2. Create a GCP project

在 Google Cloud 控制台中导航到 管理资源 页面。

🌐 Navigate to the Manage Resources screen in Google Cloud Console.

  • 在页面顶部的“选择组织”下拉列表中,选择你要创建项目的组织资源。如果你是免费试用用户,请跳过此步骤,因为此列表不会出现。
  • 点击创建项目。
  • 在出现的新建项目窗口中,输入项目名称并根据需要选择一个结算账户。项目名称只能包含字母、数字、单引号、连字符、空格或感叹号,并且长度必须在4到30个字符之间。
  • 在“位置”框中输入父组织或文件夹资源。该资源将成为新项目的层级父项。如果“无组织”是一个选项,你可以选择它,将新项目创建为其自身资源层级的顶层。
  • 当你完成输入新项目详情后,点击创建。

3. 在 GCP 项目中启用计费

🌐 3. Enable billing in the GCP Project

为了启用 Cloud Run API,必须在此项目中启用结算。请导航到 Google Cloud 控制台中的 结算 页面。按照屏幕上的提示创建结算账户,然后将新项目链接到此结算账户。

🌐 In order to enable the Cloud Run API, billing must be enabled in this project. Navigate to the Billing screen in Google Cloud Console. Follow the on-screen prompts to create a billing account, and then link the new project to this billing account.

4. 在 GCP 中设置权限 / API / 服务账户

🌐 4. Setup Permissions / APIs / Service Account in GCP

info

Google Cloud Shell 是一个基于浏览器的命令行接口 (CLI),用于管理托管在 GCP 上的资源和应用。它提供了一台预装了命令行工具和实用程序的虚拟机,包括 Google Cloud SDK 和 Terraform。通过此 Shell,你可以直接在浏览器中访问你的项目、资源和服务。以下步骤将导入一个脚本,以在你的项目中启用必要的 API、资源和权限。

  1. 导航到 仪表板,并确保在顶部下拉菜单中选择了你的新项目。然后,在屏幕的右上角,点击激活云 Shell 图标

  2. 在 Cloud Shell 中,输入以下命令并按照提示操作。

    curl -L https://github.com/remotion-dev/remotion/raw/main/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar | tar -x -C . && node install.mjs
  • 选择
    1
    来为 Remotion Cloud Run 设置此项目,或重新运行设置以进行更新。
  • 选择
    2
    生成一个新的 .env 文件,或管理已创建的密钥,并改为按照这些步骤操作
  1. 当提示应用计划时,输入 yes。当提示生成 .env 文件时,输入 yes

  2. 运行以下命令以查看环境变量。将它们复制到本地的 .env 文件中(如果不存在则创建它):

    cat .env
  3. 从虚拟机中删除 .env 文件:

    rm .env

5. 可选:验证权限设置

🌐 5. Optional: Validate the permission setup

在你的代码库中,运行以下命令以验证 GCP 中的权限是否设置正确。只要你的 GCP 项目是使用匹配的 Remotion 版本设置的,这应该会通过。

🌐 From within your code base, run the following command to validate the permissions are setup correctly in GCP. As long as your GCP project was setup with a matching Remotion version, this should pass.

npx remotion cloudrun permissions

对于以下步骤,你可以在命令行接口上执行它们,或者使用 Node.JS API 以编程方式执行。

🌐 For the following steps, you may execute them on the CLI, or programmatically using the Node.JS APIs.

6. 部署服务

🌐 6. Deploy a service

通过执行以下命令,在你的 GCP 项目中部署一个可以渲染视频的服务:

🌐 Deploy a service that can render videos into your GCP project by executing the following command:

npx remotion cloudrun services deploy

该服务由必要的二进制文件和 JavaScript 代码组成,可以获取一个 服务 URL 并从中进行渲染。服务与 Remotion 版本绑定,如果你升级了 Remotion,你需要部署一个新的服务。服务不包含你的 Remotion 代码,它将在下一步中部署。

🌐 The service consists of necessary binaries and JavaScript code that can take a serve URL and make renders from it. A service is bound to the Remotion version, if you upgrade Remotion, you need to deploy a new service. A service does not include your Remotion code, it will be deployed in the next step instead.

将打印出一个 Cloud Run URL,提供访问已部署服务并执行渲染的唯一端点。或者,你也可以使用打印出的 Service Name 来访问已部署服务并执行渲染。

🌐 A Cloud Run URL will be printed, providing unique endpoint for accessing the deployed service and performing a render. Alternatively you can use the Service Name, that is also printed, for accessing the deployed service and performing a render.

7. 部署一个网站

🌐 7. Deploy a site

运行以下命令将你的 Remotion 项目部署到云存储桶。将项目的入口点作为最后一个参数传入。

🌐 Run the following command to deploy your Remotion project to a Cloud Storage bucket. Pass as the last argument the entry point of the project.

npx remotion cloudrun sites create src/index.ts --site-name=my-video

将打印一个 serveUrl,指向已部署的项目。

🌐 A serveUrl will be printed pointing to the deployed project.

当你将来更新你的 Remotion 代码时,请重新部署你的网站。传递相同的 --site-name 以覆盖之前的部署。如果你不传递 --site-name,每次部署都会生成一个唯一的 URL。

🌐 When you update your Remotion code in the future, redeploy your site. Pass the same --site-name to overwrite the previous deploy. If you don't pass --site-name, a unique URL will be generated on every deploy.

8. 渲染视频或静态图片

🌐 8. Render a video or still

  • <serve-url | site-name> 在第7步网站部署期间返回了服务 URL。如果使用来自云存储桶的服务 URL,你可以改为传递网站名称。
  • <composition-id> 传入你想要渲染的 作品 ID
  • <cloud-run-url> 云运行 URL 在第 6 步服务部署期间返回。
npx remotion cloudrun render <serve-url | site-name> <composition-id> --cloud-run-url=<cloud-run-url>

在视频渲染完成之前,将会打印进度。恭喜!你已使用 Remotion Cloudrun 渲染了你的第一个视频 🚀

🌐 Progress will be printed until the video finished rendering. Congrats! You rendered your first video using Remotion Cloudrun 🚀

下一步

🌐 Next steps