开始前的准备工作

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

设置 Google Cloud 项目

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

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  4. Enable the Video Stitcher API.

    Enable the API

  5. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. 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.

    6. Click Continue.
    7. 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.

    Go to project selector

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

  10. Enable the Video Stitcher API.

    Enable the API

  11. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. 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.

    6. Click Continue.
    7. 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. Install the Google Cloud CLI.

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

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

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

    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 密钥。

  19. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. Grant the Video Stitcher User role to the service account.

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

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

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

  20. 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.
  21. 直播设置

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

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

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

    创建直播

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

    Live Stream API 快速入门使用应用默认凭据进行身份验证,但您可以使用已设置的服务账号。对于此选项,请确保服务账号具有 Live Stream 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 源文件