This page shows you how to create Transcoder API jobs in batch mode. Use batch mode to submit many jobs for which the processing latency isn't as critical as jobs submitted in the default interactive mode. For more information on job modes, see the overview.
You can specify the
job processing priority
for a job in this mode. Jobs submitted in batch mode with the same priority
value are put in a first-in, first out queue and have a job state of PENDING
while they wait to be run.
Set up your Google Cloud project and authentication
If you have not created a Google Cloud project and credentials, see Before you begin.Set the job mode
To start a job in batch mode, set the job
mode
to
PROCESSING_MODE_BATCH
.
The following samples use the default job preset.
Before using any of the request data, make the following replacements:
: Your Google Cloud project ID listed in the IAM Settings.PROJECT_ID
: The location where your job will run. Use one of the supported regions.LOCATION Show locationsus-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
: The name of the Cloud Storage bucket you created.STORAGE_BUCKET_NAME
: The name of the video in your Cloud Storage bucket that you are transcoding, such asSTORAGE_INPUT_VIDEO my-vid.mp4
. This field should take into account any folders that you created in the bucket (for example,input/my-vid.mp4
).
: The Cloud Storage folder name where you want to save the encoded video outputs.STORAGE_OUTPUT_FOLDER
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF' { "inputUri": "gs://STORAGE_BUCKET_NAME /STORAGE_INPUT_VIDEO ", "outputUri": "gs://STORAGE_BUCKET_NAME /STORAGE_OUTPUT_FOLDER /", "templateId": "preset/web-hd", "mode": "PROCESSING_MODE_BATCH", "batchModePriority": 10 } EOF
Then execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://transcoder.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /jobs"
PowerShell (Windows)
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "inputUri": "gs://STORAGE_BUCKET_NAME /STORAGE_INPUT_VIDEO ", "outputUri": "gs://STORAGE_BUCKET_NAME /STORAGE_OUTPUT_FOLDER /", "templateId": "preset/web-hd", "mode": "PROCESSING_MODE_BATCH", "batchModePriority": 10 } '@ | Out-File -FilePath request.json -Encoding utf8
Then execute the following command to send your REST request:
$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://transcoder.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /jobs" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "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 }
Before using any of the command data below, make the following replacements:
: The location where your job will run. Use one of the supported regions.LOCATION Show locationsus-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
: The name of the Cloud Storage bucket you created.STORAGE_BUCKET_NAME
: The name of the video in your Cloud Storage bucket that you are transcoding, such asSTORAGE_INPUT_VIDEO my-vid.mp4
. This field should take into account any folders that you created in the bucket (for example,input/my-vid.mp4
).
: The Cloud Storage folder name where you want to save the encoded video outputs.STORAGE_OUTPUT_FOLDER
Execute the following command:
Linux, macOS, or 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
You should receive a response similar to the following:
Response
{ "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 }
Before trying this sample, follow the C# setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API C# API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Go setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Go API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Java setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Java API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Node.js setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Node.js API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the PHP setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API PHP API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Python setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Python API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Ruby setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Ruby API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.