本页介绍了如何在 Transcoder API 资源上添加和查看标签。标签是可用于整理资源的键值对。您可以将标签附加到各个资源,然后根据其标签过滤资源。标签的相关信息将转发到结算系统,因此您可以根据标签细分结算费用。
您可以在创建 Transcoder API 作业和作业模板时添加标签。如果您根据包含标签的作业模板创建作业,则该作业将包含与作业模板相同的标签。如需替换作业模板中的标签,您可以直接在作业本身上指定标签。
您可以通过 REST 或 RPC API 使用标签。标签在 Google Cloud CLI 或 Google Cloud 控制台中不可用。
标签要求
应用于资源的标签必须符合以下要求:
- 每项资源可以有多个标签,但不能超过 64 个。
- 每个标签都必须采用键值对形式。
- 键至少有 1 个字符,最多有 63 个字符,且不能为空。值可以为空,且最多包含 63 个字符。
- 键和值只能包含小写字母、数字字符、下划线和短划线。所有字符必须使用 UTF-8 编码,允许使用国际字符。
- 标签的键在单个资源中必须是唯一的,但您可以将同一键用于多个资源。
- 键必须以小写字母或国际字符开头。
向作业添加标签
以下示例展示了如何在创建新作业时添加标签。
例如,您可以使用标签来表明作业将在测试环境中使用。标签的键为 environment
,值为 test
。
如需创建作业,请使用 projects.locations.jobs.create
方法。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 ID。LOCATION
:运行作业的位置。请使用其中一个受支持的区域。显示位置us-central1
us-west1
us-west2
us-east1
us-east4
southamerica-east1
northamerica-northeast1
asia-east1
asia-northeast1
asia-northeast3
asia-south1
asia-southeast1
australia-southeast1
europe-west1
europe-west2
europe-west4
STORAGE_BUCKET_NAME
:您创建的 Cloud Storage 存储分区的名称。STORAGE_INPUT_VIDEO
:您要对其进行转码的 Cloud Storage 存储分区中的视频的名称,例如my-vid.mp4
。此字段应考虑您在存储分区中创建的任何文件夹(例如input/my-vid.mp4
)。STORAGE_OUTPUT_FOLDER
:您要在其中保存已编码视频输出的 Cloud Storage 文件夹名称。
如需发送您的请求,请展开以下选项之一:
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID", "config": { "inputs": [ { "key": "input0", "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" } ], "editList": [ { "key": "atom0", "inputs": [ "input0" ], "startTimeOffset": "0s" } ], "elementaryStreams": [ { "videoStream": { "h264": { "widthPixels": 640, "heightPixels": 360, "frameRate": 30, "bitrateBps": 550000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 550000, "vbvFullnessBits": 495000, "entropyCoder": "cabac", "bFrameCount": 3, "aqStrength": 1, "profile": "high", "preset": "veryfast" } }, "key": "video-stream0" }, { "videoStream": { "h264": { "widthPixels": 1280, "heightPixels": 720, "frameRate": 30, "bitrateBps": 2500000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 2500000, "vbvFullnessBits": 2250000, "entropyCoder": "cabac", "bFrameCount": 3, "aqStrength": 1, "profile": "high", "preset": "veryfast" } }, "key": "video-stream1" }, { "audioStream": { "codec": "aac", "bitrateBps": 64000, "channelCount": 2, "channelLayout": [ "fl", "fr" ], "sampleRateHertz": 48000 }, "key": "audio-stream0" } ], "muxStreams": [ { "key": "sd", "fileName": "sd.mp4", "container": "mp4", "elementaryStreams": [ "video-stream0", "audio-stream0" ] }, { "key": "hd", "fileName": "hd.mp4", "container": "mp4", "elementaryStreams": [ "video-stream1", "audio-stream0" ] }, { "key": "media-sd", "fileName": "media-sd.ts", "container": "ts", "elementaryStreams": [ "video-stream0", "audio-stream0" ] }, { "key": "media-hd", "fileName": "media-hd.ts", "container": "ts", "elementaryStreams": [ "video-stream1", "audio-stream0" ] }, { "key": "video-only-sd", "fileName": "video-only-sd.m4s", "container": "fmp4", "elementaryStreams": [ "video-stream0" ] }, { "key": "video-only-hd", "fileName": "video-only-hd.m4s", "container": "fmp4", "elementaryStreams": [ "video-stream1" ] }, { "key": "audio-only", "fileName": "audio-only.m4s", "container": "fmp4", "elementaryStreams": [ "audio-stream0" ] } ], "manifests": [ { "fileName": "manifest.m3u8", "type": "HLS", "muxStreams": [ "media-sd", "media-hd" ] }, { "fileName": "manifest.mpd", "type": "DASH", "muxStreams": [ "video-only-sd", "video-only-hd", "audio-only" ] } ], "output": { "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/" } }, "state": "PENDING", "createTime": CREATE_TIME, "ttlAfterCompletionDays": 30, "labels": { "environment": "test" } }
要添加多个标签,请用逗号分隔每个标签。
按标签列出和过滤
您可以列出资源并按标签过滤资源。例如,向作业添加标签后,您可以列出给定位置中的作业,并按添加的标签进行过滤。以下示例列出了作业,并滤除了不包含标签 "environment": "test"
的作业。
如需列出作业,请使用 projects.locations.jobs.list
方法。系统会将以下过滤条件附加到网址:?filter=labels.environment:test
。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:您的 Google Cloud 项目 ID。LOCATION
:您的作业的位置。请使用其中一个受支持的区域。us-central1
us-west1
us-west2
us-east1
us-east4
southamerica-east1
northamerica-northeast1
asia-east1
asia-northeast1
asia-northeast3
asia-south1
asia-southeast1
australia-southeast1
europe-west1
europe-west2
europe-west4
如需发送您的请求,请展开以下选项之一:
您应该收到类似以下内容的 JSON 响应:
{ "jobs": [ { "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/MY_JOB", "config": { .... }, "state": "PENDING", "createTime": CREATE_TIME, "ttlAfterCompletionDays": 30, "labels": { "environment": "test" } }, { "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/MY_OTHER_JOB", "config": { .... }, "state": "SUCCEEDED", "createTime": CREATE_TIME, "startTime": START_TIME, "endTime": END_TIME, "ttlAfterCompletionDays": 30, "labels": { "environment": "test" } } ] }