本页介绍了如何设置 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 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.
-
Make sure 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.
-
To initialize the gcloud CLI, run the following command:
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
您将使用此服务账号授予访问权限并调用 Video Stitcher API。
创建一个仅具有创建会话权限的服务账号
由于 OAuth 令牌将传递给客户端应用,因此请创建一个单独的服务账号,并仅向其授予创建会话的权限;这样,泄露的 OAuth 令牌就无法危害您的资源,例如 VOD/直播配置或 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 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.
直播设置
如果您要在直播中插入广告,请按照本部分中的步骤操作(或参阅适用于 VOD 的步骤)。
将服务账号与 Ad Manager 账号相关联
创建服务账号后,您必须将该服务账号与您的 Ad Manager 账号相关联。这样,Video Stitcher API 就可以代表您创建直播活动。为此,请按照相应步骤授予对服务账号的访问权限:
- 登录 Google Ad Manager (GAM)。
- 依次点击管理 > 全局设置。
- 确保已启用 API 访问权限。
- 点击添加服务账号用户。
- 填写表单,包括之前创建的服务账号的电子邮件地址。
- 选择一个角色,该角色必须具有通过 Google Cloud 视频拼接器中的动态广告插播功能管理视频内容权限。您应专门为管理此服务账号创建一个名为“直播管理员”的自定义角色。自定义角色应至少具有以下权限:
- 通过 Google Cloud 视频拼接器中的动态广告插播功能管理视频内容
- 查看广告素材(上述权限所需)
- 查看视频内容、内容集和元数据
- 查看内容来源
- 如果您的 Ad Manager 广告资源网使用了小组,您必须向服务账号用户分配“所有实体”小组。
- 点击保存并确认添加此服务账号。
创建直播
您可以使用某个 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 源文件。