MPEG-DASH 直播快速入門
本頁說明如何使用 Live Stream API 的預設設定,透過 curl
、PowerShell 或用戶端程式庫,建立基本的 MPEG-DASH 即時串流直播工作。
事前準備
- 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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Live Stream API:
gcloud services enable livestream.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/livestream.editor, roles/storage.admin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Live Stream API:
gcloud services enable livestream.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/livestream.editor, roles/storage.admin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information. To go to the next
step, click Continue.
-
In the Get started section, do the following:
- Enter a globally unique name that meets the bucket naming requirements.
- To add a
bucket label,
expand the Labels section ( ),
click add_box
Add label, and specify a
key
and avalue
for your label.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
In the Replication settings section, click Configure to configure settings for the replication job.
The Configure cross-bucket replication pane appears.
- To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
- To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
- Click Done.
-
In the Choose how to store your data section, do the following:
- In the Set a default class section, select the following: Standard.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
-
In the Choose how to protect object data section, do the
following:
- Select any of the options under Data protection that you
want to set for your bucket.
- To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
- To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
- To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
- To enable Object Retention Lock, click the Enable object retention checkbox.
- To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
- To choose how your object data will be encrypted, expand the Data encryption section (Data encryption method. ), and select a
- Select any of the options under Data protection that you
want to set for your bucket.
-
In the Get started section, do the following:
- Click Create.
建立 Cloud Storage 值區
建立 Cloud Storage bucket,用來保存即時串流資訊清單和區隔檔案。
Google Cloud 控制台
指令列
-
Create a Cloud Storage bucket:
gcloud storage buckets create gs://BUCKET_NAME
BUCKET_NAME
with a bucket name
that meets the bucket naming requirements.
安裝編碼器
如要使用 API,必須要有編碼器產生 API 處理的輸入串流。
安裝 ffmpeg
,因為本頁面說明如何使用 ffmpeg
產生輸入串流。您可以在 Cloud Shell 中使用下列指令安裝這項工具。
sudo apt install ffmpeg
建立輸入端點
如要開始直播,請先使用 projects.locations.inputs.create
方法建立輸入端點。您會將輸入串流傳送至這個端點。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:建立輸入端點的位置;請使用其中一個支援的區域顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
INPUT_ID
:為要建立的新輸入端點定義的 ID (您會將輸入串流傳送至該端點)。這個值必須介於 1 至 63 個字元之間,開頭和結尾須為[a-z0-9]
,且字元之間可包含破折號 (-)。例如:my-input
。
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
複製傳回的 OPERATION_ID,以便在下一節中使用。
查看結果
使用 projects.locations.operations.get
方法檢查輸入端點是否已建立。如果回應包含 "done: false"
,請重複執行指令,直到回應包含 "done: true"
為止。在區域中建立第一個輸入端點時,最多可能需要 10 分鐘。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:輸入端點所在位置;請使用其中一個支援的地區顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
OPERATION_ID
:作業的 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "endTime": END_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.Input", "name": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID", "createTime": CREATE_TIME, "updateTime": UPDATE_TIME, "type": "RTMP_PUSH", "uri": INPUT_STREAM_URI, # For example, "rtmp://1.2.3.4/live/b8ebdd94-c8d9-4d88-a16e-b963c43a953b", "tier": "HD" } }
找到 uri
欄位,然後複製傳回的 INPUT_STREAM_URI,以便稍後在「傳送輸入串流」一節中使用。
建立管道
如要將輸入串流轉碼為輸出串流,必須建立管道資源。
如要建立管道,請使用 projects.locations.channels.create
方法。以下範例會建立管道,產生由單一高畫質 (1280x720) 轉譯版本組成的 MPEG-DASH 直播串流。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:建立管道的位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 ID,用於建立管道;這個值必須介於 1 至 63 個字元之間,開頭和結尾須為[a-z0-9]
,且字元之間可包含破折號 (-)INPUT_ID
:使用者定義的輸入端點 IDBUCKET_NAME
:您建立的 Cloud Storage bucket 名稱,用於保存即時串流資訊清單和區隔檔案
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
取得頻道
您可以使用新的作業 ID,查看頻道建立作業的結果。
建立頻道後,請使用 projects.locations.channels.get
方法查詢頻道狀態。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:頻道所在位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID", "createTime": CREATE_TIME, "updateTime": UPDATE_TIME, "inputAttachments": [ { "key": "INPUT_ID", "input": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID" } ], "activeInput": "INPUT_ID", "output": { "uri": "gs://BUCKET_NAME" }, "elementaryStreams": [ { "videoStream": { "h264": { "widthPixels": 1280, "heightPixels": 720, "frameRate": 30, "bitrateBps": 3000000, "gopDuration": "2s", "vbvSizeBits": 3000000, "vbvFullnessBits": 2700000, "entropyCoder": "cabac", "profile": "high" } }, "key": "es_video" }, { "audioStream": { "codec": "aac", "bitrateBps": 160000, "channelCount": 2, "channelLayout": ["fl", "fr"], "sampleRateHertz": 48000 }, "key": "es_audio" } ], "muxStreams": [ { "key": "mux_video", "container": "fmp4", "elementaryStreams": ["es_video"], "segmentSettings": { "segmentDuration": "2s" } }, { "key": "mux_audio", "container": "fmp4", "elementaryStreams": ["es_audio"], "segmentSettings": { "segmentDuration": "2s" } } ], "manifests": [ { "key": "manifest_dash", "fileName": "main.mpd", "type": "DASH", "muxStreams": [ "mux_video", "mux_audio" ], "maxSegmentCount": 5, "segmentKeepDuration": "60s" } ], "streamingState": "STOPPED" }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
完整回應包含下列欄位。(上述部分程式碼範例只會傳回回應中的特定欄位,但可以修改為傳回完整回應)。
{
...
"streamingState": "STOPPED"
...
}
這項回應表示你現在可以啟動頻道。
啟動管道
請使用 projects.locations.channels.start
方法啟動管道。頻道必須先啟動,才能接受輸入串流或產生輸出串流。
在區域中啟動第一個頻道約需 10 分鐘。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:頻道所在位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID", "verb": "start", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
傳送輸入串流
如要判斷頻道是否已啟動,請取得頻道資訊,做法與先前相同。回應應包含下列內容:
{
...
"streamingState": "AWAITING_INPUT"
...
}
頻道準備就緒後,請將測試輸入串流傳送至輸入端點,以生成直播。
開啟新的終端機視窗。使用「檢查結果」一節中的 INPUT_STREAM_URI 執行下列指令:
ffmpeg -re -f lavfi -i "testsrc=size=1280x720 [out0]; sine=frequency=500 [out1]" \
-acodec aac -vcodec h264 -f flv INPUT_STREAM_URI
確認頻道正在直播
如要查看直播作業的狀態,請如先前所述取得頻道資訊。回覆應包含下列內容:
{
...
"streamingState": "STREAMING"
...
}
確認 Cloud Storage bucket 中的內容
開啟 Cloud Storage bucket。確認其中包含下列檔案和目錄:
main.mpd
mux_audio/
- 多個
segment-segment-number.m4s
檔案 - 單一
segment-initialization_segment_0000000000.m4s
檔案
- 多個
mux_video/
- 多個
segment-segment-number.m4s
檔案 - 單一
segment-initialization_segment_0000000000.m4s
檔案
- 多個
播放系統產生的即時串流內容
如要在 Shaka Player 中播放產生的媒體檔案,請完成下列步驟:
- 將您建立的 Cloud Storage bucket 設為可公開讀取。
- 如要在 Cloud Storage bucket 上啟用跨源資源共享 (CORS),請按照下列步驟操作:
- 建立包含下列內容的 JSON 檔案:
[ { "origin": ["https://shaka-player-demo.appspot.com/"], "responseHeader": ["Content-Type", "Range"], "method": ["GET", "HEAD"], "maxAgeSeconds": 3600 } ]
-
執行下列指令,並將
JSON_FILE_NAME
替換為您在上一個步驟中建立的 JSON 檔案名稱:gcloud storage buckets update gs://BUCKET_NAME --cors-file=JSON_FILE_NAME.json
- 建立包含下列內容的 JSON 檔案:
- 在 Cloud Storage bucket 中,找出系統產生的
main.mpd
檔案。在該檔案的「Public access」(公開存取權) 資料欄中,按一下「Copy URL」(複製網址)。 - 前往 Shaka Player (這是一個線上即時串流播放器)。
- 按一下頂端導覽列中的「Custom Content」(自訂內容)。
- 按一下「+」按鈕。
將檔案的公開網址貼到「Manifest URL」(資訊清單網址) 方塊中。
在「Name」(名稱) 方塊中輸入名稱。
按一下「Save」(儲存)。
按一下「Play」(播放)。
這時候應該就會看到即時串流內容以測試模式播放。
在直播中加入廣告插播時間點標記
如要在直播中加入廣告插播時間點標記,請使用 projects.locations.channels.events.create
方法。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:頻道所在位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 IDEVENT_ID
:使用者定義的事件 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID", "createTime": CREATE_TIME, "updateTime": UPDATE_TIME, "adBreak": { "duration": "100s" }, "executeNow": true, "state": "PENDING" }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
確認廣告插播時間點標記是否存在
在直播中插入廣告標記後,DASH 資訊清單中會顯示標示為<SpliceInfoSection>
的事件,表示指定廣告時間長度 (100 秒)。
執行下列指令,查看產生的 DASH 資訊清單內容:
gcloud storage cat gs://BUCKET_NAME/main.mpd
您可能需要多次執行 gcloud storage cat
指令,直到出現 <SpliceInfoSection>
區段為止:
<EventStream timescale="10000000" schemeIdUri="urn:scte:scte35:2013:xml">
<Event duration="100000000" id="809">
<SpliceInfoSection xmlns="urn:scte:scte35:2013:xml">
<SpliceInsert outOfNetworkIndicator="true" spliceImmediateFlag="true">
<BreakDuration autoReturn="true" duration="100000000"/>
</SpliceInsert>
</SpliceInfoSection>
</Event>
</EventStream>
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
停止管道
使用 projects.locations.channels.stop
方法停止頻道。你必須先停止頻道,才能刪除。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:頻道所在位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID", "verb": "stop", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
使用 OPERATION_ID 檢查作業狀態,直到結果中出現 "done":true
為止。
停止輸入串流
如果使用 ffmpeg
傳送輸入串流,停止頻道後,連線會自動中斷。
如果您使用其他具有重試機制的編碼器,可能需要手動停止輸入串流。
刪除活動
使用 projects.locations.channels.events.delete
方法刪除廣告插播事件。你必須先刪除頻道活動,才能刪除頻道。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:頻道所在位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 IDEVENT_ID
:使用者定義的事件 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{}
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
刪除頻道
使用 projects.locations.channels.delete
方法刪除頻道。你必須先刪除頻道,才能刪除頻道使用的輸入端點。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:頻道所在位置;請使用支援的區域之一顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
CHANNEL_ID
:使用者定義的管道 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID", "verb": "delete", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
使用 OPERATION_ID 檢查作業狀態,直到結果中出現 "done":true
為止。
刪除輸入端點
使用 projects.locations.inputs.delete
方法刪除輸入端點。
REST
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號,位於「IAM Settings」(IAM 設定) 頁面的「Project number」(專案編號) 欄位LOCATION
:輸入端點所在位置;請使用其中一個支援的地區顯示地區us-central1
us-east1
us-east4
us-west1
us-west2
northamerica-northeast1
southamerica-east1
asia-east1
asia-east2
asia-south1
asia-northeast1
asia-southeast1
australia-southeast1
europe-north1
europe-west1
europe-west2
europe-west3
europe-west4
INPUT_ID
:使用者定義的輸入端點 ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID", "verb": "delete", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
C#
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API C# API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Go API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Java API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Node.js API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API PHP API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Python API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Live Stream API 的用戶端程式庫,請參閱這篇文章。 詳情請參閱 Live Stream API Ruby API 參考說明文件。
如要向 Live Stream API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
刪除 Cloud Storage 值區
請注意,停止頻道後,Live Stream API 產生的儲存空間中所有檔案和資料夾都會遭到刪除。
前往 Google Cloud 控制台的 Cloud Storage 瀏覽器頁面。
找出您建立的值區,並選取旁邊的核取方塊。
點選「刪除」。
在出現的彈出式視窗中,按一下「刪除」,即可永久刪除值區及其內容。
撤銷憑證
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
後續步驟
- 請參閱 HTTP 即時串流直播的快速入門導覽課程。
- 瞭解如何設定備份輸入串流。