本页介绍了如何在批处理模式下创建 Transcoder API 作业。使用 批处理模式提交许多处理延迟时间没有 因为在默认交互模式下提交作业时非常重要。有关 请参阅 概览。
您可以指定
作业处理优先级
指定作业 ID。通过批处理模式提交的具有相同优先级的作业
值放在先进先出队列中,且作业状态为 PENDING
运行代码。
设置您的 Google Cloud 项目和身份验证
如果您尚未创建 Google Cloud 项目和凭据,请参阅开始前须知。设置作业模式
要以批量模式启动作业,请设置作业
mode
更改为
PROCESSING_MODE_BATCH
。
以下示例使用默认作业预设。
REST
在使用任何请求数据之前,请先进行以下替换:
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 }
gcloud
在使用下面的命令数据之前,请先进行以下替换:
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 文件夹名称。
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud transcoder jobs create \ --input-uri="gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" \ --location=LOCATION \ --output-uri="gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/" \ --template-id="preset/web-hd" \ --batch-mode-priority=10
Windows (PowerShell)
gcloud transcoder jobs create ` --input-uri="gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" ` --location=LOCATION ` --output-uri="gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/" ` --template-id="preset/web-hd" ` --batch-mode-priority=10
Windows (cmd.exe)
gcloud transcoder jobs create ^ --input-uri="gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" ^ --location=LOCATION ^ --output-uri="gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/" ^ --template-id="preset/web-hd" ^ --batch-mode-priority=10
您应该会收到类似如下所示的响应:
响应
{ "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 }
C#
在尝试此示例之前,请按照C# Transcoder API 快速入门:使用 客户端库。 如需了解详情,请参阅 Transcoder API C# API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
Go
在试用此示例之前,请按照 Transcoder API 快速入门:使用客户端库中的 Go 设置说明进行操作。 如需了解详情,请参阅 Transcoder API Go API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
Java
在尝试此示例之前,请按照Java Transcoder API 快速入门:使用 客户端库。 有关详情,请参阅 Transcoder API Java API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
在尝试此示例之前,请按照Node.js Transcoder API 快速入门:使用 客户端库。 有关详情,请参阅 Transcoder API Node.js API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
在尝试此示例之前,请按照PHP Transcoder API 快速入门:使用 客户端库。 如需了解详情,请参阅 Transcoder API PHP API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
Python
在尝试此示例之前,请按照Python Transcoder API 快速入门:使用 客户端库。 有关详情,请参阅 Transcoder API Python API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
Ruby
在试用此示例之前,请按照 Transcoder API 快速入门:使用客户端库中的 Ruby 设置说明进行操作。 如需了解详情,请参阅 Transcoder API Ruby API 参考文档。
如需向 Transcoder API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。