本页面介绍如何设置 Google Cloud 项目并配置服务帐号以访问该项目。
设置 Google Cloud 项目
按照以下步骤设置一个 Google Cloud 项目。
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Video Stitcher and Live Stream APIs.
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
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
. - Click Create and continue.
-
Grant the following roles to the service account: Video Stitcher Admin, Live Stream Editor, Storage Admin.
To grant a role, find the Select a role list, then select the role.
To grant additional roles, click
Add another role and add each additional role. - Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
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. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Video Stitcher and Live Stream APIs.
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
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
. - Click Create and continue.
-
Grant the following roles to the service account: Video Stitcher Admin, Live Stream Editor, Storage Admin.
To grant a role, find the Select a role list, then select the role.
To grant additional roles, click
Add another role and add each additional role. - Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
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. - Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- 使用
gcloud
工具测试您的身份验证环境。检查以下命令是否输出了没有错误的文本字符串:gcloud auth application-default print-access-token
激活服务帐号
- 在您的终端中,为 gcloud 命令设置活跃项目。将 YOUR_PROJECT_ID 替换为您的项目 ID。
gcloud config set project YOUR_PROJECT_ID
- 激活服务帐号。将 PATH_TO_YOUR_SERVICE_KEY 替换为您下载到本地机器的 JSON 文件的路径。
gcloud auth activate-service-account --key-file PATH_TO_YOUR_SERVICE_KEY
您将使用此服务帐号授予访问权限并调用 Video Stitcher API。
将服务帐号与 Ad Manager 账号相关联
创建服务帐号后,您必须将该服务帐号关联到您的 Ad Manager 帐号。这样一来,Video Stitcher API 便可代表您创建直播活动。为此,请按照相应步骤授予对您的服务帐号的访问权限:
- 登录 Google Ad Manager (GAM)。
- 依次点击管理 > 全局设置。
- 确保已启用 API 访问权限。
- 点击添加服务帐号用户。
- 填写表单,包括之前创建的服务帐号的电子邮件地址。
- 选择一个角色,该角色必须包含通过 Google Cloud Video Stitcher 管理具有动态广告插入内容的视频内容权限。您应该创建一个名为直播管理员的自定义角色,专门用于管理此服务账号。该自定义角色应至少具有以下权限:
- 通过 Google Cloud 视频拼接器的动态广告插播管理视频内容
- 查看广告素材(需要前述权限)
- 查看视频内容、集合和元数据
- 查看内容来源
- 点击保存并确认添加此服务帐号。
创建仅拥有创建会话权限的服务帐号
由于 OAuth 令牌将传递到客户端应用,因此请创建一个仅具有创建会话权限的单独的服务帐号;因此,已泄露的 OAuth 令牌无法破坏您的资源,例如 CDN 密钥和直播活动。
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
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
. - Click Create and continue.
-
Grant the following roles to the service account: Video Stitcher User.
To grant a role, find the Select a role list, then select the role.
To grant additional roles, click
Add another role and add each additional role. - Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
创建直播
您可以使用其中一个 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 - 表示法不得为空