开始前的准备工作

本页面介绍了如何设置 Google Cloud 项目并配置服务账号以访问该项目。

设置 Google Cloud 项目

按照以下步骤设置 Google Cloud 项目。

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud新手,请 创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Video Stitcher API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Video Stitcher Admin role to the service account.

      To grant the role, find the Select a role list, then select Video Stitcher Admin.

    7. Click Continue.
    8. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  6. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  7. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.

  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Video Stitcher API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  11. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Video Stitcher Admin role to the service account.

      To grant the role, find the Select a role list, then select Video Stitcher Admin.

    7. Click Continue.
    8. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  12. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  13. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.

  14. 安装 Google Cloud CLI。

  15. 如果您使用的是外部身份提供方 (IdP),则必须先 使用联合身份登录 gcloud CLI。

  16. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  17. 使用 gcloud CLI 测试您的身份验证环境。 检查以下命令是否输出无错误的文本字符串:
    gcloud auth application-default print-access-token

激活服务账号

  1. 在终端中,为 gcloud 命令设置活跃项目。将 YOUR_PROJECT_ID 替换为您的项目 ID。
    gcloud config set project YOUR_PROJECT_ID
  2. 激活服务账号。将 PATH_TO_YOUR_SERVICE_KEY 替换为您下载到本地计算机的 JSON 文件的路径。
    gcloud auth activate-service-account --key-file PATH_TO_YOUR_SERVICE_KEY

您将使用此服务账号来授权访问和调用 Video Stitcher API。

创建一个仅具有创建会话权限的服务账号

由于 OAuth 令牌将传递给客户端应用,因此请创建一个单独的服务账号,该账号仅具有创建会话的权限;这样一来,泄露的 OAuth 令牌就不会危及您的资源,例如 VOD/直播配置或 CDN 密钥。

创建服务账号:

  1. 确保您拥有 Create Service Accounts IAM 角色 (roles/iam.serviceAccountCreator) 和 Project IAM Admin 角色 (roles/resourcemanager.projectIamAdmin)。了解如何授予角色。
  2. 在 Google Cloud 控制台中,前往创建服务账号页面。

    转到“创建服务账号”
  3. 选择您的项目。
  4. 在服务账号名称字段中,输入一个名称。 Google Cloud 控制台会根据此名称填充服务账号 ID 字段。

    在服务账号说明字段中,输入说明。例如,Service account for quickstart。

  5. 点击创建并继续。
  6. 向服务账号授予 Video Stitcher User 角色。

    如需授予该角色,请找到选择角色列表,然后选择 Video Stitcher User。

  7. 点击继续。
  8. 点击完成以完成服务账号的创建过程。

    不要关闭浏览器窗口。您将在下一步骤中用到它。

创建服务账号密钥:

  1. 在 Google Cloud 控制台中,点击您创建的服务账号的电子邮件地址。
  2. 点击密钥。
  3. 点击添加密钥,然后点击创建新密钥。
  4. 点击创建。JSON 密钥文件将下载到您的计算机上。
  5. 点击关闭。

直播设置

如果您要在直播中插入广告,请按照本部分中的步骤操作(或参阅 VOD 的相关步骤)。

创建服务账号后,您必须将该服务账号与您的 Ad Manager 账号相关联。这样,Video Stitcher API 才能代表您创建直播活动。为此,请按以下步骤操作,以授予对服务账号的访问权限:

  1. 登录 Google Ad Manager (GAM)。
  2. 依次点击管理 > 全局设置。
  3. 确保已启用 API 访问权限。
  4. 点击添加服务账号用户。
  5. 填写表单,包括之前创建的服务账号的电子邮件地址。
  6. 选择一个角色,该角色必须包含通过 Google Cloud Video Stitcher 中的动态广告插播功能管理视频内容权限。您应该专门为管理此服务账号创建名为 Live Stream Manager 的自定义角色。自定义角色应至少具有以下权限:
    • 通过 Google Cloud 视频拼接器中的动态广告插播功能管理视频内容
    • 查看广告素材(前述权限所必需)
    • 查看视频内容、合集和元数据
    • 查看内容来源
  7. 如果您的 Ad Manager 广告资源网使用小组,您必须将“所有实体”小组分配给服务账号用户。
  8. 点击保存并确认添加此服务账号。

创建直播

您可以使用其中一个 Live Stream API 快速入门指南来设置直播。支持 HLS 和 MPEG-DASH 直播(请参阅来源清单要求)。此过程是可选的;您可以使用自己现有的直播。

Live Stream API 快速入门使用应用默认凭证进行身份验证,但您可以使用已设置的服务账号。对于此选项,请确保服务账号具有 直播 Editor 角色。

请务必保持直播活动处于有效状态;在完成直播之前,请勿按照清理部分中的步骤操作。

源清单要求

Video Stitcher API 通过解析源清单向 Ad Manager 注册配置。源清单必须具有某些特征,具体取决于格式。

HLS

  • 容器格式可以是以下任一格式:
    • 混合 MPEG-TS
    • 未分离的 MPEG-TS
    • 未复用的 FMP4
  • 清单中至少有一个包含以下(已正确填充)字段的媒体文件:
    • 编解码器
    • bandwidth

MPEG-DASH

  • MPD@type 设置为动态 (@type="dynamic")
  • MPD@profiles 包含 ISO 直播配置文件 urn:mpeg:dash:profile:isoff-live:2011
  • 应为多时段,每个时段包含一个或多个自适应集
  • 每个自适应集都包含一个或多个表示形式
  • 表示形式包含或继承了具有 $Number$ 或 $Time$ 标识符的 SegmentTemplate
  • 所有自适应集均将 @segmentAlignment 设置为 true
  • 表示形式不得为空

VOD 推流设置

如果您要将广告插入 VOD 直播,请按照本部分中的步骤操作(或参阅直播的步骤)。

创建 VOD 来源文件

此工作流程需要 MPEG-DASH 清单 (MPD) 文件或 HTTP Live Streaming (HLS) 清单 (M3U8) 文件,以及关联的段文件。您可以使用自己的现有 VOD 文件,也可以使用 Transcoder API 创建 VOD 源文件。