本頁說明如何以批次模式建立 Transcoder API 工作。如果處理延遲時間不像以預設互動模式提交的工作那麼重要,請使用批次模式提交多項工作。如要進一步瞭解工作模式,請參閱總覽。
您可以在這個模式中指定工作的工作處理優先順序。以批次模式提交且優先順序值相同的工作會放入先進先出佇列,並在等待執行時處於 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
me-west1
me-central1
me-central2
STORAGE_BUCKET_NAME
:您建立的 Cloud Storage bucket 名稱。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
me-west1
me-central1
me-central2
STORAGE_BUCKET_NAME
:您建立的 Cloud Storage bucket 名稱。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
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 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
在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Ruby API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。