Creating jobs in batch mode

This page shows you how to create Transcoder API jobs in batch mode. Usebatch mode to submit many jobs for which the processing latency isn't ascritical as jobs submitted in the default interactive mode. For moreinformation on job modes, see theoverview.

You can specify thejob processing priorityfor a job in this mode. Jobs submitted in batch mode with the same priorityvalue are put in a first-in, first out queue and have a job state ofPENDINGwhile they wait to be run.

Set up your Google Cloud project and authentication

If you have not created aGoogle Cloud project and credentials, seeBefore you begin.

Set the job mode

To start a job in batch mode, set the jobmodetoPROCESSING_MODE_BATCH.

The following samples use thedefault job preset.

REST

Before using any of the request data, make the following replacements:

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.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)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.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}

gcloud

Before using any of the command data below, make the following replacements:

Execute the following command:

Linux, macOS, or Cloud Shell

Note: Ensure you have initialized the Google Cloud CLI with authentication and a project by running eithergcloud init; orgcloud auth login andgcloud config set project.
gcloudtranscoderjobscreate\--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)

Note: Ensure you have initialized the Google Cloud CLI with authentication and a project by running eithergcloud init; orgcloud auth login andgcloud config set project.
gcloudtranscoderjobscreate`--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)

Note: Ensure you have initialized the Google Cloud CLI with authentication and a project by running eithergcloud init; orgcloud auth login andgcloud config set project.
gcloudtranscoderjobscreate^--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}

C#

Before trying this sample, follow theC# setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APIC# API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

usingGoogle.Api.Gax.ResourceNames;usingGoogle.Cloud.Video.Transcoder.V1;publicclassCreateJobFromPresetBatchModeSample{publicJobCreateJobFromPresetBatchMode(stringprojectId,stringlocation,stringinputUri,stringoutputUri,stringpreset){// Create the client.TranscoderServiceClientclient=TranscoderServiceClient.Create();// Build the parent location name.LocationNameparent=newLocationName(projectId,location);// Build the job.JobnewJob=newJob{InputUri=inputUri,OutputUri=outputUri,TemplateId=preset,Mode=Job.Types.ProcessingMode.Batch,BatchModePriority=10};// Call the API.Jobjob=client.CreateJob(parent,newJob);// Return the result.returnjob;}}

Go

Before trying this sample, follow theGo setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APIGo API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

import("context""fmt""io"transcoder"cloud.google.com/go/video/transcoder/apiv1""cloud.google.com/go/video/transcoder/apiv1/transcoderpb")// createJobFromPresetBatchMode creates a batch mode job based on a given preset// template. See// https://cloud.google.com/transcoder/docs/how-to/create-batch-jobs// for more information.funccreateJobFromPresetBatchMode(wio.Writer,projectIDstring,locationstring,inputURIstring,outputURIstring)error{// projectID := "my-project-id"// location := "us-central1"// inputURI := "gs://my-bucket/my-video-file"// outputURI := "gs://my-bucket/my-output-folder/"preset:="preset/web-hd"ctx:=context.Background()client,err:=transcoder.NewClient(ctx)iferr!=nil{returnfmt.Errorf("NewClient: %w",err)}deferclient.Close()req:=&transcoderpb.CreateJobRequest{Parent:fmt.Sprintf("projects/%s/locations/%s",projectID,location),Job:&transcoderpb.Job{InputUri:inputURI,OutputUri:outputURI,JobConfig:&transcoderpb.Job_TemplateId{TemplateId:preset,},Mode:transcoderpb.Job_PROCESSING_MODE_BATCH,BatchModePriority:10,},}// Creates the job, Jobs take a variable amount of time to run.// You can query for the job state.response,err:=client.CreateJob(ctx,req)iferr!=nil{returnfmt.Errorf("createJobFromPresetBatchMode: %w",err)}fmt.Fprintf(w,"Job: %v",response.GetName())returnnil}

Java

Before trying this sample, follow theJava setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APIJava API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

importcom.google.cloud.video.transcoder.v1.CreateJobRequest;importcom.google.cloud.video.transcoder.v1.Job;importcom.google.cloud.video.transcoder.v1.Job.ProcessingMode;importcom.google.cloud.video.transcoder.v1.LocationName;importcom.google.cloud.video.transcoder.v1.TranscoderServiceClient;importjava.io.IOException;publicclassCreateJobFromPresetBatchMode{publicstaticvoidmain(String[]args)throwsException{// TODO(developer): Replace these variables before running the sample.StringprojectId="my-project-id";Stringlocation="us-central1";StringinputUri="gs://my-bucket/my-video-file";StringoutputUri="gs://my-bucket/my-output-folder/";// See https://cloud.google.com/transcoder/docs/concepts/overview#job_template// for information on this preset.Stringpreset="preset/web-hd";createJobFromPresetBatchMode(projectId,location,inputUri,outputUri,preset);}// Creates a job from a preset in batch mode.publicstaticvoidcreateJobFromPresetBatchMode(StringprojectId,Stringlocation,StringinputUri,StringoutputUri,Stringpreset)throwsIOException{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(TranscoderServiceClienttranscoderServiceClient=TranscoderServiceClient.create()){CreateJobRequestcreateJobRequest=CreateJobRequest.newBuilder().setJob(Job.newBuilder().setInputUri(inputUri).setOutputUri(outputUri).setTemplateId(preset).setMode(ProcessingMode.PROCESSING_MODE_BATCH).setBatchModePriority(10).build()).setParent(LocationName.of(projectId,location).toString()).build();// Send the job creation request and process the response.Jobjob=transcoderServiceClient.createJob(createJobRequest);System.out.println("Job: "+job.getName());}}}

Node.js

Before trying this sample, follow theNode.js setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APINode.js API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

/** * TODO(developer): Uncomment these variables before running the sample. */// projectId = 'my-project-id';// location = 'us-central1';// inputUri = 'gs://my-bucket/my-video-file';// outputUri = 'gs://my-bucket/my-output-folder/';// preset = 'preset/web-hd';// Imports the Transcoder libraryconst{TranscoderServiceClient}=require('@google-cloud/video-transcoder').v1;// Instantiates a clientconsttranscoderServiceClient=newTranscoderServiceClient();asyncfunctioncreateJobFromPresetBatchMode(){// Construct requestconstrequest={parent:transcoderServiceClient.locationPath(projectId,location),job:{inputUri:inputUri,outputUri:outputUri,templateId:preset,mode:'PROCESSING_MODE_BATCH',batchModePriority:10,},};// Run requestconst[response]=awaittranscoderServiceClient.createJob(request);console.log(`Job:${response.name}`);}createJobFromPresetBatchMode();

PHP

Before trying this sample, follow thePHP setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APIPHP API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient;use Google\Cloud\Video\Transcoder\V1\CreateJobRequest;use Google\Cloud\Video\Transcoder\V1\Job;/** * Creates a job in batch mode based on a job preset. * * @param string $projectId The ID of your Google Cloud Platform project. * @param string $location The location of the job. * @param string $inputUri Uri of the video in the Cloud Storage bucket. * @param string $outputUri Uri of the video output folder in the Cloud Storage bucket. * @param string $preset The preset template (for example, "preset/web-hd"). */function create_job_from_preset_batch_mode($projectId, $location, $inputUri, $outputUri, $preset){    // Instantiate a client.    $transcoderServiceClient = new TranscoderServiceClient();    $formattedParent = $transcoderServiceClient->locationName($projectId, $location);    $job = new Job();    $job->setInputUri($inputUri);    $job->setOutputUri($outputUri);    $job->setTemplateId($preset);    $job->setMode(Job\ProcessingMode::PROCESSING_MODE_BATCH);    $job->setBatchModePriority(10);    $request = (new CreateJobRequest())        ->setParent($formattedParent)        ->setJob($job);    $response = $transcoderServiceClient->createJob($request);    // Print job name.    printf('Job: %s' . PHP_EOL, $response->getName());}

Python

Before trying this sample, follow thePython setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APIPython API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

importargparsefromgoogle.cloud.videoimporttranscoder_v1fromgoogle.cloud.video.transcoder_v1.services.transcoder_serviceimport(TranscoderServiceClient,)defcreate_job_from_preset_batch_mode(project_id:str,location:str,input_uri:str,output_uri:str,preset:str,)->transcoder_v1.types.resources.Job:"""Creates a job in batch mode based on a job preset.    Args:        project_id: The GCP project ID.        location: The location to start the job in.        input_uri: Uri of the video in the Cloud Storage bucket.        output_uri: Uri of the video output folder in the Cloud Storage bucket.        preset: The preset template (for example, 'preset/web-hd').    Returns:        The job resource.    """client=TranscoderServiceClient()parent=f"projects/{project_id}/locations/{location}"job=transcoder_v1.types.Job()job.input_uri=input_urijob.output_uri=output_urijob.template_id=presetjob.mode=transcoder_v1.types.Job.ProcessingMode.PROCESSING_MODE_BATCHjob.batch_mode_priority=10response=client.create_job(parent=parent,job=job)print(f"Job:{response.name}")returnresponse

Ruby

Before trying this sample, follow theRuby setup instructions in theTranscoder API quickstart using client libraries. For more information, see theTranscoder APIRuby API reference documentation.

To authenticate to Transcoder API, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

# project_id  = "YOUR-GOOGLE-CLOUD-PROJECT"  # (e.g. "my-project")# location    = "YOUR-JOB-LOCATION"  # (e.g. "us-central1")# input_uri   = "YOUR-GCS-INPUT-VIDEO"  # (e.g. "gs://my-bucket/my-video-file")# output_uri  = "YOUR-GCS-OUTPUT-FOLDER/"  # (e.g. "gs://my-bucket/my-output-folder/")# preset      = "YOUR-JOB-PRESET"  # (e.g. "preset/web-hd")# Require the Transcoder client library.require"google/cloud/video/transcoder"# Create a Transcoder client.client=Google::Cloud::Video::Transcoder.transcoder_service# Build the resource name of the parent.parent=client.location_pathproject:project_id,location:location# Set the job fields.new_job={input_uri:input_uri,output_uri:output_uri,template_id:preset,mode:Google::Cloud::Video::Transcoder::V1::Job::ProcessingMode::PROCESSING_MODE_BATCH,batch_mode_priority:10}job=client.create_jobparent:parent,job:new_job# Print the job name.puts"Job:#{job.name}"

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.