本页介绍了如何设置 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Video Stitcher API.
-
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 Video Stitcher Admin role to the service account.
To grant the role, find the Select a role list, then select Video Stitcher Admin.
- 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Video Stitcher API.
-
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 Video Stitcher Admin role to the service account.
To grant the role, find the Select a role list, then select Video Stitcher Admin.
- 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.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
- 使用 gcloud CLI 测试您的身份验证环境。检查以下命令是否输出无错误的文本字符串:
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
-
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 Video Stitcher User role to the service account.
To grant the role, find the Select a role list, then select Video Stitcher User.
- 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.
- 登录 Google Ad Manager (GAM)。
- 依次点击管理 > 全局设置。
- 确保已启用 API 访问权限。
- 点击添加服务账号用户。
- 填写表单,包括之前创建的服务账号的电子邮件地址。
- 选择一个角色,该角色必须包含通过 Google Cloud 视频拼接器中的动态广告插播功能管理视频内容权限。您应专门为管理此服务账号创建自定义角色,并将其命名为 Live Stream Manager。自定义角色应至少具有以下权限:
- 通过 Google Cloud 视频拼接器中的动态广告插播功能管理视频内容
- 查看广告素材(前述权限所必需)
- 查看视频内容、内容集和元数据
- 查看内容来源
- 如果您的 Ad Manager 广告资源网使用小组,您必须将“所有实体”小组分配给服务账号用户。
- 点击保存并确认添加此服务账号。
- 容器格式可以是以下任一格式:
- 混合 MPEG-TS
- 未分离的 MPEG-TS
- 非混合 FMP4
- 清单中至少有一个包含以下(已正确填充)字段的媒体文件:
- 编解码器
- bandwidth
MPD@type
设置为动态 (@type="dynamic"
)MPD@profiles
包含 ISO 直播配置文件urn:mpeg:dash:profile:isoff-live:2011
- 应为多时段,每个时段包含一个或多个自适应集
- 每个自适应集包含一个或多个媒体流
- 表示形式包含或继承了具有
$Number$
或$Time$
标识符的SegmentTemplate
- 所有自适应集的
@segmentAlignment
都设置为 true - 表示形式不得为空
激活服务账号
您将使用此服务账号来授权访问和调用 Video Stitcher API。
创建仅具有创建会话权限的服务账号
由于 OAuth 令牌将传递给客户端应用,因此请创建一个单独的服务账号,该账号仅具有创建会话的权限;这样一来,泄露的 OAuth 令牌就不会危及您的资源,例如 VOD/直播配置或 CDN 密钥。
直播设置
如果您要在直播中插入广告,请按照本部分中的步骤操作(或参阅 VOD 的步骤)。
将服务账号与 Ad Manager 账号相关联
创建服务账号后,您必须将该服务账号与您的 Ad Manager 账号相关联。这样,Video Stitcher API 就可以代表您创建直播活动。为此,请按照以下步骤授予访问权限以访问您的服务账号:
创建直播
您可以使用其中一个 Live Stream API 快速入门指南来设置直播。支持 HLS 和 MPEG-DASH 直播(请参阅源清单要求)。此步骤是可选的;您可以使用自己现有的直播。
Live Stream API 快速入门使用应用默认凭据进行身份验证,但您可以使用已设置的服务账号。对于此选项,请确保服务账号具有 Live Stream Editor 角色。
请务必保持直播处于有效状态;在完成直播之前,请勿按照清理部分中的步骤操作。
来源清单要求
Video Stitcher API 通过解析源清单向 Ad Manager 注册配置。源清单必须具有某些特征,具体取决于格式。
HLS
MPEG-DASH
VOD 视频流设置
如果您要将广告插入 VOD 视频流,请按照本部分中的步骤操作(或参阅直播的步骤)。
创建 VOD 源文件
此工作流需要 MPEG-DASH 清单 (MPD) 文件或 HTTP Live Streaming (HLS) 清单 (M3U8) 文件以及关联的段文件。您可以使用自己现有的 VOD 文件,也可以使用 Transcoder API 创建 VOD 源文件。