本頁面說明如何設定 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.
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Video Stitcher API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
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.
-
Ensure that you have the Create Service Accounts IAM role
(
-
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.
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Video Stitcher API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
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.
-
Ensure that you have the Create Service Accounts IAM role
(
-
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
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
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.
- 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 Live 設定檔urn:mpeg:dash:profile:isoff-live:2011
- 應為多個時段,每個時段包含一或多個 AdaptationSet
- 每個調適集都包含一或多個呈現內容
- Representation 包含或繼承具有
$Number$
或$Time$
ID 的SegmentTemplate
@segmentAlignment
將所有調整組設為 true- 表示法不得為空白
啟用服務帳戶
您將使用這個服務帳戶授權存取及呼叫 Video Stitcher API。
建立僅具備建立工作階段權限的服務帳戶
由於 OAuth 憑證會傳遞至用戶端應用程式,請另外建立服務帳戶,並僅授予建立工作階段的權限;這樣一來,即使 OAuth 憑證外洩,也不會危及 VOD/直播設定或 CDN 金鑰等資源。
Create a service account:
Create a service account key:
直播設定
如要在直播中插入廣告,請按照本節的步驟操作 (或參閱VOD 的步驟)。
將服務帳戶連結至 Ad Manager 帳戶
建立服務帳戶後,您必須將該服務帳戶連結至 Ad Manager 帳戶。這樣 Video Stitcher API 才能代表您建立直播活動。如要授予服務帳戶存取權,請按照這篇文章的步驟操作:
建立直播
你可以使用其中一個 Live Stream API 快速入門指南,設定直播。系統支援 HTTP 即時串流和 MPEG-DASH 即時串流 (請參閱來源資訊清單規定)。這項程序為選用步驟,你可以使用現有的直播影片。
Live Stream API 快速入門導覽會使用應用程式預設憑證進行驗證,但您可以使用已設定的服務帳戶。如要使用這個選項,請確認服務帳戶具有「直播編輯者」角色。
請務必保持直播活動有效,在直播結束前,請勿按照「清除」一節中的步驟操作。
來源資訊清單規定
Video Stitcher API 會剖析來源資訊清單,向 Ad Manager 註冊設定。來源資訊清單必須具備特定特徵,視格式而定。
HLS
MPEG-DASH
VOD 串流設定
如要在隨選影片串流中插入廣告,請按照本節的步驟操作 (或參閱直播的步驟)。
建立 VOD 來源檔案
這個工作流程需要 MPEG-DASH 資訊清單 (MPD) 檔案或 HTTP 即時串流 (HLS) 資訊清單 (M3U8) 檔案,以及相關聯的區隔檔案。你可以使用現有的 VOD 檔案,也可以使用 Transcoder API 建立 VOD 來源檔案。