本頁說明如何為直播設定 AI 生成字幕和翻譯字幕 (即翻譯)。
HLS 和 DASH 即時串流支援 AI 生成的字幕和翻譯。
事前準備
本頁面假設您已完成「開始前 」一節中的步驟,也就是「HTTP 即時串流快速入門 」或「MPEG-DASH 即時串流快速入門 」中的步驟。
支援的地區
系統支援為每個地點生成字幕,並提供語言代碼。
顯示地區
位置
支援的語言代碼
asia-northeast1
en-US
asia-south1
en-IN
en-GB
en-US
asia-southeast1
en-US
australia-southeast1
en-AU
europe-west1
da-DK
nl-NL
en-GB
en-US
fr-FR
de-DE
it-IT
es-ES
europe-west2
en-GB
europe-west3
da-DK
nl-NL
en-GB
en-US
fr-FR
de-DE
it-IT
es-ES
northamerica-northeast1
en-CA
fr-CA
us-central1
en-US
pt-BR
es-CO
es-MX
es-US
us-east1
en-US
pt-BR
es-CO
es-MX
es-US
us-west1
en-US
pt-BR
es-CO
es-MX
es-US
AI 生成翻譯功能僅支援 us-west1
和 europe-west1
。
請對這個頁面上的所有 API 要求使用 us-west1
或 europe-west1
。
如要建立輸入端點,請使用 projects.locations.inputs.create
方法。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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 要求主體:
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"type": "RTMP_PUSH"
}
EOF
接著,請執行下列指令來傳送 REST 要求:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /inputs?inputId=INPUT_ID "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"type": "RTMP_PUSH"
}
'@ | Out-File -FilePath request.json -Encoding utf8
接著,請執行下列指令來傳送 REST 要求:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /inputs?inputId=INPUT_ID " | Select-Object -Expand Content
您應該會收到如下的 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
}
複製傳回的 OPERATION_ID ,以便在下一節中使用。
查看結果
使用 projects.locations.operations.get
方法檢查輸入端點是否已建立。如果回應包含 "done: false"
,請重複執行指令,直到回應包含 "done: true"
為止。在區域中建立第一個輸入端點最多可能需要 10 分鐘。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /operations/OPERATION_ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /operations/OPERATION_ID " | Select-Object -Expand Content
您應該會收到如下的 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
方法。
請注意管道設定中的下列事項:
字幕會使用 ElementaryStream
,也就是 TextStream
。
{
"key" : "webvtt_english_ai" ,
"textStream" : {
"codec" : "webvtt" ,
"displayName" : "English (AI captioned)" ,
"languageCode" : "en-US" ,
"mapping" : [
{
"inputTrack" : 1 // audio track number
}
]
}
}
TextStream
codec
欄位必須設為 webvtt
。
TextStream
mapping
欄位會使用 inputTrack
指定要從哪個輸入音軌生成字幕。對應檔不得 包含 inputCeaChannel
欄位,這個欄位只用於使用者提供的隱藏式輔助字幕。
將 languageCode
設為音軌中使用的語言。
基本串流用於建立具有金鑰 vtt_english_ai
的 MuxStream
。
{
"key" : "vtt_english_ai" ,
"container" : "vtt" ,
"elementaryStreams" : [
"webvtt_english_ai"
],
"segmentSettings" : {
"segmentDuration" : "2s"
}
}
然後,HLS 和 DASH 資訊清單 都會參照這個多工串流。
{
"fileName" : "main.m3u8" ,
"type" : "HLS" ,
"muxStreams" : [
"mux_video_ts" ,
"vtt_english_ai"
],
"maxSegmentCount" : 5
}
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
:輸入端點的使用者定義 ID
BUCKET_NAME
:您建立的 Cloud Storage bucket 名稱,用於保存即時串流資訊清單和區隔檔案
JSON 要求主體:
{
"inputAttachments": [
{
"key": "my-input",
"input": "projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
}
],
"output": {
"uri": "gs://BUCKET_NAME "
},
"elementaryStreams": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai"
],
"maxSegmentCount": 5
}
]
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"inputAttachments": [
{
"key": "my-input",
"input": "projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
}
],
"output": {
"uri": "gs://BUCKET_NAME "
},
"elementaryStreams": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai"
],
"maxSegmentCount": 5
}
]
}
EOF
接著,請執行下列指令來傳送 REST 要求:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels?channelId=CHANNEL_ID "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"inputAttachments": [
{
"key": "my-input",
"input": "projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
}
],
"output": {
"uri": "gs://BUCKET_NAME "
},
"elementaryStreams": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai"
],
"maxSegmentCount": 5
}
]
}
'@ | Out-File -FilePath request.json -Encoding utf8
接著,請執行下列指令來傳送 REST 要求:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels?channelId=CHANNEL_ID " | Select-Object -Expand Content
您應該會收到如下的 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
方法查詢管道狀態。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID " | Select-Object -Expand Content
您應該會收到如下的 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": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai"
],
"maxSegmentCount": 5
}
],
"streamingState": "STOPPED"
}
完整回應包含下列欄位:
{
...
"streamingState": "STOPPED"
...
}
這項回應表示你現在可以啟動頻道。
啟動管道
使用 projects.locations.channels.start
方法啟動管道。頻道必須先啟動,才能接受輸入串流或產生輸出串流。
在區域中啟動第一個頻道約需 10 分鐘。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID :start"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID :start" | Select-Object -Expand Content
您應該會收到如下的 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
}
如要判斷頻道是否已啟動,請取得頻道 資訊,做法與先前相同。回應應包含下列內容:
{
...
"streamingState": "AWAITING_INPUT"
...
}
頻道準備就緒後,請將輸入串流傳送至輸入端點,產生直播串流。你可以下載附有字幕的 MP4 檔案 (或其他格式
TEST_VOD_FILE ),然後使用 ffmpeg
將檔案傳送至輸入端點。
開啟新的終端機視窗。使用「檢查結果 」一節中的 INPUT_STREAM_URI 執行下列指令:
ffmpeg -re -stream_loop -1 -i "TEST_VOD_FILE " \
-c:v copy -c:a aac -strict 2 -f "flv" "INPUT_STREAM_URI "
注意: 如果輸入端點使用 RTMP 協定,請使用 flv
格式。使用 mpegts
進行 SRT 通訊協定。
驗證輸出資訊清單中的說明文字
執行下列指令,查看產生的 HLS 資訊清單內容:
gcloud storage cat gs://BUCKET_NAME /main.m3u8
AI 生成的英文 WebVTT 字幕會顯示在輸出資訊清單中,如下所示:
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub",LANGUAGE="en-US",NAME="English (AI captioned)",AUTOSELECT=YES,DEFAULT=YES,FORCED=NO,URI="vtt_english_ai/index-1.m3u8"
停止管道
更新頻道設定前,請務必先停止頻道。
使用 projects.locations.channels.stop
方法停止頻道。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID :stop"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID :stop" | Select-Object -Expand Content
您應該會收到如下的 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
}
更新翻譯的頻道設定
更新頻道設定,加入翻譯字幕 (即翻譯)。
請注意頻道設定的下列新增項目 :
一個
ElementaryStream
,一個TextStream
,用於單一翻譯語言的字幕。
{
"key" : "webvtt_spanish_ai" ,
"textStream" : {
"codec" : "webvtt" ,
"displayName" : "Spanish (AI captioned)" ,
"languageCode" : "es-MX" ,
"mapping" : [
{
"inputTrack" : 1 , // audio track number
"fromLanguageCode" : "en-US" // original audio in English
}
]
}
}
將 languageCode
設為所選翻譯語言。
將 fromLanguageCode
設為音軌的原始語言。
基本串流用於建立具有金鑰 vtt_spanish_ai
的 MuxStream
。
{
"key" : "vtt_spanish_ai" ,
"container" : "vtt" ,
"elementaryStreams" : [
"webvtt_spanish_ai"
],
"segmentSettings" : {
"segmentDuration" : "2s"
}
}
然後,HLS 和 DASH 資訊清單 都會參照這個多工串流。
{
"fileName" : "main.m3u8" ,
"type" : "HLS" ,
"muxStreams" : [
"mux_video_ts" ,
"vtt_english_ai" ,
"vtt_spanish_ai"
],
"maxSegmentCount" : 5
}
如要更新頻道,請使用 projects.locations.channels.patch
方法。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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]
,且字元之間可包含破折號 (-)
JSON 要求主體:
{
"inputAttachments": [
{
"key": "my-input",
"input": "projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
}
],
"output": {
"uri": "gs://BUCKET_NAME "
},
"elementaryStreams": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
},
{
"key": "webvtt_spanish_ai",
"textStream": {
"codec": "webvtt",
"displayName": "Spanish (AI captioned)",
"languageCode": "es-MX",
"mapping": [
{
"inputTrack": 1,
"fromLanguageCode": "en-US"
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_spanish_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_spanish_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai",
"vtt_spanish_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai",
"vtt_spanish_ai"
],
"maxSegmentCount": 5
}
]
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"inputAttachments": [
{
"key": "my-input",
"input": "projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
}
],
"output": {
"uri": "gs://BUCKET_NAME "
},
"elementaryStreams": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
},
{
"key": "webvtt_spanish_ai",
"textStream": {
"codec": "webvtt",
"displayName": "Spanish (AI captioned)",
"languageCode": "es-MX",
"mapping": [
{
"inputTrack": 1,
"fromLanguageCode": "en-US"
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_spanish_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_spanish_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai",
"vtt_spanish_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai",
"vtt_spanish_ai"
],
"maxSegmentCount": 5
}
]
}
EOF
接著,請執行下列指令來傳送 REST 要求:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID ?updateMask=elementary_streams,mux_streams,manifests"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"inputAttachments": [
{
"key": "my-input",
"input": "projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
}
],
"output": {
"uri": "gs://BUCKET_NAME "
},
"elementaryStreams": [
{
"key": "es_video",
"videoStream": {
"h264": {
"profile": "high",
"widthPixels": 1280,
"heightPixels": 720,
"bitrateBps": 3000000,
"frameRate": 30
}
}
},
{
"key": "es_audio",
"audioStream": {
"codec": "aac",
"channelCount": 2,
"bitrateBps": 160000
}
},
{
"key": "webvtt_english_ai",
"textStream": {
"codec": "webvtt",
"displayName": "English (AI captioned)",
"languageCode": "en-US",
"mapping": [
{
"inputTrack": 1
}
]
}
},
{
"key": "webvtt_spanish_ai",
"textStream": {
"codec": "webvtt",
"displayName": "Spanish (AI captioned)",
"languageCode": "es-MX",
"mapping": [
{
"inputTrack": 1,
"fromLanguageCode": "en-US"
}
]
}
}
],
"muxStreams": [
{
"key": "mux_video_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_video"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_audio_fmp4",
"container": "fmp4",
"elementaryStreams": [
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "mux_video_ts",
"container": "ts",
"elementaryStreams": [
"es_video",
"es_audio"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_english_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_english_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
},
{
"key": "vtt_spanish_ai",
"container": "vtt",
"elementaryStreams": [
"webvtt_spanish_ai"
],
"segmentSettings": {
"segmentDuration": "2s"
}
}
],
"manifests": [
{
"key": "manifest_dash",
"fileName": "main.mpd",
"type": "DASH",
"muxStreams": [
"mux_video_fmp4",
"mux_audio_fmp4",
"vtt_english_ai",
"vtt_spanish_ai"
],
"maxSegmentCount": 5
},
{
"key": "manifest_hls",
"fileName": "main.m3u8",
"type": "HLS",
"muxStreams": [
"mux_video_ts",
"vtt_english_ai",
"vtt_spanish_ai"
],
"maxSegmentCount": 5
}
]
}
'@ | Out-File -FilePath request.json -Encoding utf8
接著,請執行下列指令來傳送 REST 要求:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID ?updateMask=elementary_streams,mux_streams,manifests" | Select-Object -Expand Content
您應該會收到如下的 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": "update",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
您可以使用新的作業 ID 檢查作業結果 。
如先前所述,啟動管道 ,然後再次傳送輸入串流 。
在輸出資訊清單中驗證翻譯
執行下列指令,查看產生的 HLS 資訊清單內容:
gcloud storage cat gs://BUCKET_NAME /main.m3u8
AI 生成的英文和西班牙文 WebVTT 字幕會顯示在輸出資訊清單中,類似以下內容:
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub",LANGUAGE="en-US",NAME="English (AI captioned)",AUTOSELECT=YES,DEFAULT=YES,FORCED=NO,URI="vtt_english_ai/index-1.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub",LANGUAGE="es-MX",NAME="Spanish (AI captioned)",AUTOSELECT=NO,DEFAULT=NO,FORCED=NO,URI="vtt_spanish_ai/index-1.m3u8"
設定要發布的 AI 生成轉錄稿
設定 AI 生成的字幕和翻譯以供發布前,請先熟悉如何將直播發布至遠端端點 。
如要將 AI 生成的字幕和翻譯內容發布至遠端端點,請勿參照先前建立含 AI 生成字幕的頻道 和更新頻道翻譯 時,以 webvtt
格式設定的文字串流。用於發布的文字串流必須是內嵌字幕,且 codec
設為 cea608
或 cea708
。
在管道設定中,請注意下列事項:
一個 ElementaryStream
(TextStream
) 用於字幕,另一個 ElementaryStream
(TextStream
) 則用於翻譯。
{
"key" : "embedded_english_ai" ,
"textStream" : {
"codec" : "cea608" ,
"displayName" : "English (AI captioned)" ,
"languageCode" : "en-US" ,
"outputCeaChannel" : "CC1" , // closed caption channel that will contain AI-generated English captions
"mapping" : [
{
"inputTrack" : 1 // audio track number
}
]
}
}
{
"key" : "embedded_spanish_ai" ,
"textStream" : {
"codec" : "cea608" ,
"displayName" : "Spanish (AI captioned)" ,
"languageCode" : "es-MX" ,
"outputCeaChannel" : "CC2" , // closed caption channel that will contain AI-generated Spanish captions
"mapping" : [
{
"inputTrack" : 1 , // audio track number
"fromLanguageCode" : "en-US" // original audio in English
}
]
}
}
TextStream
codec
欄位必須設為 cea608
或 cea708
。
TextStream
mapping
欄位會使用 inputTrack
指定要從哪個輸入音軌生成字幕。對應檔不得 包含 inputCeaChannel
欄位,這個欄位只用於使用者提供的隱藏式輔助字幕。
將 outputCeaChannel
設為字幕頻道,在發布串流中加入 AI 生成的轉錄稿。
將 languageCode
設為音軌中使用的語言。
基本串流會包含在 DistributionStream
物件的 elementaryStreams
欄位中。
{
"distributionStreams" : [
{
"key" : "ds1" ,
"container" : "ts" , // to be used with an SRT distribution
"elementaryStreams" : [
"es_video" ,
"es_audio" ,
"embedded_english_ai" , // distribute both English
"embedded_spanish_ai" // and Spanish captions
]
},
{
"key" : "ds2" ,
"container" : "flv" , // to be used with an RTMP distribution
"elementaryStreams" : [
"es_video" ,
"es_audio" ,
"embedded_spanish_ai" // only distribute Spanish captions
]
}
]
}
按照將直播內容發布至遠端端點指南 完成頻道建立程序。
進階設定
在頻道層級設定 AutoTranscriptionConfig
,進一步根據需求調整 AI 生成的文字串流。
字幕顯示時間碼
根據預設,AI 生成字幕會與音訊和影片非同步顯示。將 AutoTranscriptionConfig
中的 DisplayTiming
欄位設為 SYNC
,即可同步顯示這些欄位。
{
"autoTranscriptionConfig" : {
"displayTiming" : "SYNC"
}
}
同步顯示字幕會縮短音訊和文字之間的觀看延遲時間,但會增加整體端對端媒體延遲時間。
畫質預設
使用 AutoTranscriptionConfig
中的 QualityPreset
欄位,設定 AI 生成文字串流的品質偏好設定。
舉例來說,您可以設定以下項目,進一步縮短文字串流生成作業的延遲時間:
{
"autoTranscriptionConfig" : {
"qualityPreset" : "LOW_LATENCY"
}
}
清除所用資源
停止管道
使用 projects.locations.channels.stop
方法停止管道。你必須先停止頻道,才能刪除。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID :stop"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID :stop" | Select-Object -Expand Content
您應該會收到如下的 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
}
如果使用 ffmpeg
傳送輸入串流,停止頻道後,連線會自動中斷。
刪除頻道
使用 projects.locations.channels.delete
方法刪除頻道。您必須先刪除頻道,才能刪除頻道使用的輸入端點。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /channels/CHANNEL_ID " | Select-Object -Expand Content
您應該會收到如下的 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
}
使用 projects.locations.inputs.delete
方法刪除輸入端點。
使用任何要求資料之前,請先替換以下項目:
PROJECT_NUMBER
:您的 Google Cloud 專案編號;這位於「專案編號 」欄位,在「IAM 設定 」頁面上
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
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER /locations/LOCATION /inputs/INPUT_ID " | Select-Object -Expand Content
您應該會收到如下的 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
}
刪除 Cloud Storage 值區
前往 Google Cloud 控制台的 Cloud Storage 瀏覽器頁面。
前往 Cloud Storage 瀏覽器頁面
找出您建立的值區,並選取旁邊的核取方塊。
點選「刪除」。
在隨即顯示的對話方塊中,按一下「刪除」 ,即可刪除值區及其內容。