本页介绍了如何为直播配置 AI 生成的字幕和翻译字幕(即翻译)。
HLS 和 DASH 直播支持 AI 生成的字幕和翻译。
准备工作
本页假设您已完成 HLS 直播快速入门 或 MPEG-DASH 直播快速入门 的准备工作 部分中的步骤。
支持的位置
AI 生成的字幕的语言代码按位置提供支持。
显示位置
位置
支持的语言代码
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
:要创建的新输入端点(您将输入流发送到该端点)的用户定义标识符。此值必须为 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
:操作的标识符
如需发送您的请求,请展开以下选项之一:
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
:要创建的渠道的用户定义标识符;此值必须为 1-63 个字符,以 [a-z0-9]
开头和结尾,并且可以在字符之间包含短划线 (-)。
INPUT_ID
:输入端点的用户定义标识符
BUCKET_NAME
:您创建的用于存储直播清单和分段文件的 Cloud Storage 存储桶的名称
请求 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
:用户定义的渠道标识符
如需发送您的请求,请展开以下选项之一:
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
:用户定义的渠道标识符
如需发送您的请求,请展开以下选项之一:
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
:用户定义的渠道标识符
如需发送您的请求,请展开以下选项之一:
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
:要创建的渠道的用户定义标识符;此值必须为 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
:用户定义的渠道标识符
如需发送您的请求,请展开以下选项之一:
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
:用户定义的渠道标识符
如需发送您的请求,请展开以下选项之一:
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
:输入端点的用户定义标识符
如需发送您的请求,请展开以下选项之一:
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 浏览器”页面
选中所创建存储分区旁边的复选框。
点击删除 。
在随即显示的对话框窗口中,点击删除 以删除相应存储桶及其内容。