Creating and managing jobs

This page shows you how to create and manage Transcoder API jobs.

A job represents the basic unit for managing work with the Transcoder API. When you submit a job to the Transcoder API, you specify the geographic location it should be processed in. You can list all jobs in a region.

To learn more about working with jobs and related Google Cloud resources across geographic regions, see Regions.

Set up your GCP project and authentication

Creating jobs

You can create jobs using either a preset job template or a custom job template you have created. To learn how to create a job template, see Creating and managing job templates. Instead of using a template, you can also create a job and directly send the configuration of the job in the request.

Creating jobs based on presets

To create a job, use the projects.locations.jobs.create method. The job transcodes a media file that is stored as an object in Cloud Storage.

REST & CMD LINE

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

  • PROJECT_ID: Your Google Cloud project ID listed in the IAM Settings.
  • LOCATION: The location where your job will run. Use a location from the following list:
    • us-central1
    • us-west1
    • us-east1
    • southamerica-east1
    • asia-east1
    • europe-west1
  • GCS_BUCKET_NAME: The name of the Cloud Storage bucket you created.
  • GCS_INPUT_VIDEO: The name of the video in your Cloud Storage bucket that you are transcoding, such as my-vid.mp4. This field should take into account any folders that you created in the bucket (for example, input/my-vid.mp4).
  • GCS_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.

Request JSON body:

{
  "inputUri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO",
  "outputUri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/",
  "templateId": "preset/web-hd"
}

To send your request, expand one of these options:

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://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
      }
    ],
    "editList": [
      {
        "key": "atom0",
        "inputs": [
          "input0"
        ],
        "startTimeOffset": "0s"
      }
    ],
    "elementaryStreams": [
      {
        "videoStream": {
          "codec": "h264",
          "profile": "high",
          "preset": "veryfast",
          "heightPixels": 360,
          "widthPixels": 640,
          "pixelFormat": "yuv420p",
          "bitrateBps": 550000,
          "rateControlMode": "vbr",
          "crfLevel": 21,
          "vbvSizeBits": 550000,
          "vbvFullnessBits": 495000,
          "gopDuration": "3s",
          "entropyCoder": "cabac",
          "bFrameCount": 3,
          "frameRate": 30,
          "aqStrength": 1
        },
        "key": "video-stream0"
      },
      {
        "videoStream": {
          "codec": "h264",
          "profile": "high",
          "preset": "veryfast",
          "heightPixels": 720,
          "widthPixels": 1280,
          "pixelFormat": "yuv420p",
          "bitrateBps": 2500000,
          "rateControlMode": "vbr",
          "crfLevel": 21,
          "vbvSizeBits": 2500000,
          "vbvFullnessBits": 2250000,
          "gopDuration": "3s",
          "entropyCoder": "cabac",
          "bFrameCount": 3,
          "frameRate": 30,
          "aqStrength": 1
        },
        "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://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
    }
  },
  "createTime": CREATE_TIME,
  "ttlAfterCompletionDays": 30
}

gcloud

  1. Make the following replacements for the gcloud command:
    • GCS_BUCKET_NAME: The name of the Cloud Storage bucket you created.
    • GCS_INPUT_VIDEO: The name of the video in your Cloud Storage bucket that you are transcoding, such as my-vid.mp4. This field should take into account any folders that you created in the bucket (for example, input/my-vid.mp4).
    • LOCATION: The location where your job will run. Use a location from the following list:
      • us-central1
      • us-west1
      • us-east1
      • southamerica-east1
      • asia-east1
      • europe-west1
    • GCS_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
  2. Run the following command:
    gcloud beta transcoder jobs create \
        --input-uri="gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO" \
        --location=LOCATION \
        --output-uri="gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/" \
        --template-id="preset/web-hd"
    You should see a response similar to the following:
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID",
      "config": {
        "inputs": [
          {
            "key": "input0",
            "uri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
          }
        ],
        "editList": [
          {
            "key": "atom0",
            "inputs": [
              "input0"
            ],
            "startTimeOffset": "0s"
          }
        ],
        "elementaryStreams": [
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 360,
              "widthPixels": 640,
              "pixelFormat": "yuv420p",
              "bitrateBps": 550000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 550000,
              "vbvFullnessBits": 495000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "bFrameCount": 3,
              "frameRate": 30,
              "aqStrength": 1
            },
            "key": "video-stream0"
          },
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 720,
              "widthPixels": 1280,
              "pixelFormat": "yuv420p",
              "bitrateBps": 2500000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 2500000,
              "vbvFullnessBits": 2250000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "bFrameCount": 3,
              "frameRate": 30,
              "aqStrength": 1
            },
            "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://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
        }
      },
      "createTime": CREATE_TIME,
      "ttlAfterCompletionDays": 30
    }
    

Go

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.

import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1beta1"
	transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1"
)

// createJobFromPreset creates a job based on a given preset template. See
// https://cloud.google.com/transcoder/docs/how-to/jobs#create_jobs_presets
// for more information.
func createJobFromPreset(w io.Writer, projectID string, location string, inputURI string, outputURI string, preset string) 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)
	if err != nil {
		return fmt.Errorf("NewClient: %v", err)
	}
	defer client.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,
			},
		},
	}
	// 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)
	if err != nil {
		return fmt.Errorf("createJobFromPreset: %v", err)
	}

	fmt.Fprintf(w, "Job: %v", response.GetName())
	return nil
}

Java

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.


import com.google.cloud.video.transcoder.v1beta1.CreateJobRequest;
import com.google.cloud.video.transcoder.v1beta1.Job;
import com.google.cloud.video.transcoder.v1beta1.LocationName;
import com.google.cloud.video.transcoder.v1beta1.TranscoderServiceClient;
import java.io.IOException;

public class CreateJobFromPreset {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String location = "us-central1";
    String inputUri = "gs://my-bucket/my-video-file";
    String outputUri = "gs://my-bucket/my-output-folder/";
    String preset = "preset/web-hd";

    createJobFromPreset(projectId, location, inputUri, outputUri, preset);
  }

  // Creates a job from a preset.
  public static void createJobFromPreset(
      String projectId, String location, String inputUri, String outputUri, String preset)
      throws IOException {
    // 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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {

      var createJobRequest =
          CreateJobRequest.newBuilder()
              .setJob(
                  Job.newBuilder()
                      .setInputUri(inputUri)
                      .setOutputUri(outputUri)
                      .setTemplateId(preset)
                      .build())
              .setParent(LocationName.of(projectId, location).toString())
              .build();

      // Send the job creation request and process the response.
      Job job = transcoderServiceClient.createJob(createJobRequest);
      System.out.println("Job: " + job.getName());
    }
  }
}

Node.js

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.

/**
 * 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 library
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function createJobFromPreset() {
  // Construct request
  const request = {
    parent: transcoderServiceClient.locationPath(projectId, location),
    job: {
      inputUri: inputUri,
      outputUri: outputUri,
      templateId: preset,
    },
  };

  // Run request
  const [response] = await transcoderServiceClient.createJob(request);
  console.log(`Job: ${response.name}`);
}

createJobFromPreset();

Python

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.


import argparse

from google.cloud.video import transcoder_v1beta1
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
    TranscoderServiceClient,
)


def create_job_from_preset(project_id, location, input_uri, output_uri, preset):
    """Creates a job 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."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.template_id = preset

    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response

Creating jobs based on job templates

If you've created at least one job template in a location, you can specify a job template when sending a request to create a Transcoder API job in that location.

To create a job, use the projects.locations.jobs.create method.

REST & CMD LINE

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

  • PROJECT_ID: Your Google Cloud project ID listed in the IAM Settings.
  • LOCATION: The location where your job will run. Use a location from the following list:
    • us-central1
    • us-west1
    • us-east1
    • southamerica-east1
    • asia-east1
    • europe-west1
  • GCS_BUCKET_NAME: The name of the Cloud Storage bucket you created.
  • GCS_INPUT_VIDEO: The name of the video in your Cloud Storage bucket that you are transcoding, such as my-vid.mp4. This field should take into account any folders that you created in the bucket (for example, input/my-vid.mp4).
  • GCS_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
  • TEMPLATE_ID: The ID of the job template you created. If you don't specify a custom job template, the Transcoder API uses the preset/web-hd job template.

Request JSON body:

{
  "inputUri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO",
  "outputUri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/",
  "templateId": "TEMPLATE_ID"
}

To send your request, expand one of these options:

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://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
      }
    ],
    "editList": [
      {
        "key": "atom0",
        "inputs": [
          "input0"
        ],
        "startTimeOffset": "0s"
      }
    ],
    "elementaryStreams": [
      {
        "videoStream": {
          "codec": "h264",
          "profile": "high",
          "preset": "veryfast",
          "heightPixels": 360,
          "widthPixels": 640,
          "pixelFormat": "yuv420p",
          "bitrateBps": 550000,
          "rateControlMode": "vbr",
          "crfLevel": 21,
          "vbvSizeBits": 550000,
          "vbvFullnessBits": 495000,
          "gopDuration": "3s",
          "entropyCoder": "cabac",
          "frameRate": 60
        },
        "key": "video-stream0"
      },
      {
        "videoStream": {
          "codec": "h264",
          "profile": "high",
          "preset": "veryfast",
          "heightPixels": 720,
          "widthPixels": 1280,
          "pixelFormat": "yuv420p",
          "bitrateBps": 2500000,
          "rateControlMode": "vbr",
          "crfLevel": 21,
          "vbvSizeBits": 2500000,
          "vbvFullnessBits": 2250000,
          "gopDuration": "3s",
          "entropyCoder": "cabac",
          "frameRate": 60
        },
        "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"
        ]
      }
    ],
    "output": {
      "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
    }
  },
  "createTime": CREATE_TIME,
  "ttlAfterCompletionDays": 30
}

gcloud

  1. Make the following replacements for the gcloud command:
    • GCS_BUCKET_NAME: The name of the Cloud Storage bucket you created.
    • GCS_INPUT_VIDEO: The name of the video in your Cloud Storage bucket that you are transcoding, such as my-vid.mp4. This field should take into account any folders that you created in the bucket (for example, input/my-vid.mp4).
    • LOCATION: The location where your job will run. Use a location from the following list:
      • us-central1
      • us-west1
      • us-east1
      • southamerica-east1
      • asia-east1
      • europe-west1
    • GCS_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
    • TEMPLATE_ID: The ID of the job template you created. If you don't specify a custom job template, the Transcoder API uses the preset/web-hd job template.
  2. Run the following command:
    gcloud beta transcoder jobs create \
        --input-uri="gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO" \
        --location=LOCATION \
        --output-uri="gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/" \
        --template-id="TEMPLATE_ID"
    You should see a response similar to the following:
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID",
      "config": {
        "inputs": [
          {
            "key": "input0",
            "uri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
          }
        ],
        "editList": [
          {
            "key": "atom0",
            "inputs": [
              "input0"
            ],
            "startTimeOffset": "0s"
          }
        ],
        "elementaryStreams": [
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 360,
              "widthPixels": 640,
              "pixelFormat": "yuv420p",
              "bitrateBps": 550000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 550000,
              "vbvFullnessBits": 495000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "frameRate": 60
            },
            "key": "video-stream0"
          },
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 720,
              "widthPixels": 1280,
              "pixelFormat": "yuv420p",
              "bitrateBps": 2500000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 2500000,
              "vbvFullnessBits": 2250000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "frameRate": 60
            },
            "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"
            ]
          }
        ],
        "output": {
          "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
        }
      },
      "createTime": CREATE_TIME,
      "ttlAfterCompletionDays": 30
    }
    

Go

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.

import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1beta1"
	transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1"
)

// createJobFromTemplate creates a job from a template. See
// https://cloud.google.com/transcoder/docs/how-to/jobs#create_jobs_templates
// for more information.
func createJobFromTemplate(w io.Writer, projectID string, location string, inputURI string, outputURI string, templateID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// inputURI := "gs://my-bucket/my-video-file"
	// outputURI := "gs://my-bucket/my-output-folder/"
	// templateID := "my-job-template"
	ctx := context.Background()
	client, err := transcoder.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %v", err)
	}
	defer client.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: templateID,
			},
		},
	}
	// 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)
	if err != nil {
		return fmt.Errorf("createJobFromTemplate: %v", err)
	}

	fmt.Fprintf(w, "Job: %v", response.GetName())
	return nil
}

Java

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.


import com.google.cloud.video.transcoder.v1beta1.CreateJobRequest;
import com.google.cloud.video.transcoder.v1beta1.Job;
import com.google.cloud.video.transcoder.v1beta1.LocationName;
import com.google.cloud.video.transcoder.v1beta1.TranscoderServiceClient;
import java.io.IOException;

public class CreateJobFromTemplate {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String location = "us-central1";
    String inputUri = "gs://my-bucket/my-video-file";
    String outputUri = "gs://my-bucket/my-output-folder/";
    String templateId = "my-job-template";

    createJobFromTemplate(projectId, location, inputUri, outputUri, templateId);
  }

  // Creates a job from a job template.
  public static void createJobFromTemplate(
      String projectId, String location, String inputUri, String outputUri, String templateId)
      throws IOException {
    // 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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {

      var createJobRequest =
          CreateJobRequest.newBuilder()
              .setJob(
                  Job.newBuilder()
                      .setInputUri(inputUri)
                      .setOutputUri(outputUri)
                      .setTemplateId(templateId)
                      .build())
              .setParent(LocationName.of(projectId, location).toString())
              .build();

      // Send the job creation request and process the response.
      Job job = transcoderServiceClient.createJob(createJobRequest);
      System.out.println("Job: " + job.getName());
    }
  }
}

Node.js

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.

/**
 * 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/';
// templateId = 'my-job-template';

// Imports the Transcoder library
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function createJobFromTemplate() {
  // Construct request
  const request = {
    parent: transcoderServiceClient.locationPath(projectId, location),
    job: {
      inputUri: inputUri,
      outputUri: outputUri,
      templateId: templateId,
    },
  };

  // Run request
  const [response] = await transcoderServiceClient.createJob(request);
  console.log(`Job: ${response.name}`);
}

createJobFromTemplate();

Python

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.


import argparse

from google.cloud.video import transcoder_v1beta1
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
    TranscoderServiceClient,
)


def create_job_from_template(project_id, location, input_uri, output_uri, template_id):
    """Creates a job based on a job template.

    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.
        template_id: The user-defined template ID."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.template_id = template_id

    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response

The response is similar to the response returned when creating a job using the default template.

Creating jobs with ad-hoc configurations

You can send an ad-hoc configuration for a job with the request to create the job.

To create a job, use the projects.locations.jobs.create method.

REST & CMD LINE

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

  • PROJECT_ID: Your Google Cloud project ID listed in the IAM Settings.
  • LOCATION: The location where your job will run. Use a location from the following list:
    • us-central1
    • us-west1
    • us-east1
    • southamerica-east1
    • asia-east1
    • europe-west1
  • GCS_BUCKET_NAME: The name of the Cloud Storage bucket you created.
  • GCS_INPUT_VIDEO: The name of the video in your Cloud Storage bucket that you are transcoding, such as my-vid.mp4. This field should take into account any folders that you created in the bucket (for example, input/my-vid.mp4).
  • GCS_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.

Request JSON body:

{
  "config": {
    "inputs": [
          {
            "key": "input0",
            "uri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
          }
        ],
    "elementaryStreams": [
      {
        "key": "video-stream0",
        "videoStream": {
          "codec": "h264",
          "heightPixels": 360,
          "widthPixels": 640,
          "bitrateBps": 550000,
          "frameRate": 60
        }
      },
      {
        "key": "video-stream1",
        "videoStream": {
          "codec": "h264",
          "heightPixels": 720,
          "widthPixels": 1280,
          "bitrateBps": 2500000,
          "frameRate": 60
        }
      },
      {
        "key": "audio-stream0",
        "audioStream": {
          "codec": "aac",
          "bitrateBps": 64000
        }
      }
    ],
    "muxStreams": [
      {
        "key": "sd",
        "container": "mp4",
        "elementaryStreams": [
          "video-stream0",
          "audio-stream0"
        ]
      },
      {
        "key": "hd",
        "container": "mp4",
        "elementaryStreams": [
          "video-stream1",
          "audio-stream0"
        ]
      }
    ],
    "output": {
      "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
    }
  }
}

To send your request, expand one of these options:

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://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
      }
    ],
    "editList": [
      {
        "key": "atom0",
        "inputs": [
          "input0"
        ],
        "startTimeOffset": "0s"
      }
    ],
    "elementaryStreams": [
      {
        "videoStream": {
          "codec": "h264",
          "profile": "high",
          "preset": "veryfast",
          "heightPixels": 360,
          "widthPixels": 640,
          "pixelFormat": "yuv420p",
          "bitrateBps": 550000,
          "rateControlMode": "vbr",
          "crfLevel": 21,
          "vbvSizeBits": 550000,
          "vbvFullnessBits": 495000,
          "gopDuration": "3s",
          "entropyCoder": "cabac",
          "frameRate": 60
        },
        "key": "video-stream0"
      },
      {
        "videoStream": {
          "codec": "h264",
          "profile": "high",
          "preset": "veryfast",
          "heightPixels": 720,
          "widthPixels": 1280,
          "pixelFormat": "yuv420p",
          "bitrateBps": 2500000,
          "rateControlMode": "vbr",
          "crfLevel": 21,
          "vbvSizeBits": 2500000,
          "vbvFullnessBits": 2250000,
          "gopDuration": "3s",
          "entropyCoder": "cabac",
          "frameRate": 60
        },
        "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"
        ]
      }
    ],
    "output": {
      "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
    }
  },
  "createTime": CREATE_TIME,
  "ttlAfterCompletionDays": 30
}

gcloud

  1. Create a config.json file that defines the job fields. The following is an example job:
    {
      "config": {
        "elementaryStreams": [
          {
            "key": "video-stream0",
            "videoStream": {
              "codec": "h264",
              "heightPixels": 360,
              "widthPixels": 640,
              "bitrateBps": 550000,
              "frameRate": 60
            }
          },
          {
            "key": "video-stream1",
            "videoStream": {
              "codec": "h264",
              "heightPixels": 720,
              "widthPixels": 1280,
              "bitrateBps": 2500000,
              "frameRate": 60
            }
          },
          {
            "key": "audio-stream0",
            "audioStream": {
              "codec": "aac",
              "bitrateBps": 64000
            }
          }
        ],
        "muxStreams": [
          {
            "key": "sd",
            "container": "mp4",
            "elementaryStreams": [
              "video-stream0",
              "audio-stream0"
            ]
          },
          {
            "key": "hd",
            "container": "mp4",
            "elementaryStreams": [
              "video-stream1",
              "audio-stream0"
            ]
          }
        ]
      }
    }
    
  2. Make the following replacements for the gcloud command:
    • GCS_BUCKET_NAME: The name of the Cloud Storage bucket you created.
    • GCS_INPUT_VIDEO: The name of the video in your Cloud Storage bucket that you are transcoding, such as my-vid.mp4. This field should take into account any folders that you created in the bucket (for example, input/my-vid.mp4).
    • LOCATION: The location where your job will run. Use a location from the following list:
      • us-central1
      • us-west1
      • us-east1
      • southamerica-east1
      • asia-east1
      • europe-west1
    • GCS_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
  3. Run the following command:
    gcloud beta transcoder jobs create \
        --input-uri="gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO" \
        --location=LOCATION \
        --output-uri="gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/" \
        --file="config.json"
    You should see a response similar to the following:
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID",
      "config": {
        "inputs": [
          {
            "key": "input0",
            "uri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
          }
        ],
        "editList": [
          {
            "key": "atom0",
            "inputs": [
              "input0"
            ],
            "startTimeOffset": "0s"
          }
        ],
        "elementaryStreams": [
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 360,
              "widthPixels": 640,
              "pixelFormat": "yuv420p",
              "bitrateBps": 550000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 550000,
              "vbvFullnessBits": 495000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "frameRate": 60
            },
            "key": "video-stream0"
          },
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 720,
              "widthPixels": 1280,
              "pixelFormat": "yuv420p",
              "bitrateBps": 2500000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 2500000,
              "vbvFullnessBits": 2250000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "frameRate": 60
            },
            "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"
            ]
          }
        ],
        "output": {
          "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
        }
      },
      "createTime": CREATE_TIME,
      "ttlAfterCompletionDays": 30
    }
    

Go

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.

import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1beta1"
	transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1"
)

// createJobFromAdHoc creates a job based on a given configuration. See
// https://cloud.google.com/transcoder/docs/how-to/jobs#create_jobs_ad_hoc
// for more information.
func createJobFromAdHoc(w io.Writer, projectID string, location string, inputURI string, outputURI string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// inputURI := "gs://my-bucket/my-video-file"
	// outputURI := "gs://my-bucket/my-output-folder/"
	ctx := context.Background()
	client, err := transcoder.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %v", err)
	}
	defer client.Close()

	req := &transcoderpb.CreateJobRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		Job: &transcoderpb.Job{
			InputUri:  inputURI,
			OutputUri: outputURI,
			JobConfig: &transcoderpb.Job_Config{
				Config: &transcoderpb.JobConfig{
					ElementaryStreams: []*transcoderpb.ElementaryStream{
						&transcoderpb.ElementaryStream{
							Key: "video_stream0",
							ElementaryStream: &transcoderpb.ElementaryStream_VideoStream{
								VideoStream: &transcoderpb.VideoStream{
									Codec:        "h264",
									BitrateBps:   550000,
									FrameRate:    60,
									HeightPixels: 360,
									WidthPixels:  640,
								},
							},
						},
						&transcoderpb.ElementaryStream{
							Key: "video_stream1",
							ElementaryStream: &transcoderpb.ElementaryStream_VideoStream{
								VideoStream: &transcoderpb.VideoStream{
									Codec:        "h264",
									BitrateBps:   2500000,
									FrameRate:    60,
									HeightPixels: 720,
									WidthPixels:  1280,
								},
							},
						},
						&transcoderpb.ElementaryStream{
							Key: "audio_stream0",
							ElementaryStream: &transcoderpb.ElementaryStream_AudioStream{
								AudioStream: &transcoderpb.AudioStream{
									Codec:      "aac",
									BitrateBps: 64000,
								},
							},
						},
					},
					MuxStreams: []*transcoderpb.MuxStream{
						&transcoderpb.MuxStream{
							Key:               "sd",
							Container:         "mp4",
							ElementaryStreams: []string{"video_stream0", "audio_stream0"},
						},
						&transcoderpb.MuxStream{
							Key:               "hd",
							Container:         "mp4",
							ElementaryStreams: []string{"video_stream1", "audio_stream0"},
						},
					},
				},
			},
		},
	}
	// 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)
	if err != nil {
		return fmt.Errorf("createJobFromAdHoc: %v", err)
	}

	fmt.Fprintf(w, "Job: %v", response.GetName())
	return nil
}

Java

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.


import com.google.cloud.video.transcoder.v1beta1.AudioStream;
import com.google.cloud.video.transcoder.v1beta1.CreateJobRequest;
import com.google.cloud.video.transcoder.v1beta1.ElementaryStream;
import com.google.cloud.video.transcoder.v1beta1.Input;
import com.google.cloud.video.transcoder.v1beta1.Job;
import com.google.cloud.video.transcoder.v1beta1.JobConfig;
import com.google.cloud.video.transcoder.v1beta1.LocationName;
import com.google.cloud.video.transcoder.v1beta1.MuxStream;
import com.google.cloud.video.transcoder.v1beta1.Output;
import com.google.cloud.video.transcoder.v1beta1.TranscoderServiceClient;
import com.google.cloud.video.transcoder.v1beta1.VideoStream;
import java.io.IOException;

public class CreateJobFromAdHoc {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String location = "us-central1";
    String inputUri = "gs://my-bucket/my-video-file";
    String outputUri = "gs://my-bucket/my-output-folder/";

    createJobFromAdHoc(projectId, location, inputUri, outputUri);
  }

  // Creates a job from an ad-hoc configuration.
  public static void createJobFromAdHoc(
      String projectId, String location, String inputUri, String outputUri) throws IOException {
    // 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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {

      VideoStream videoStream0 =
          VideoStream.newBuilder()
              .setCodec("h264")
              .setBitrateBps(550000)
              .setFrameRate(60)
              .setHeightPixels(360)
              .setWidthPixels(640)
              .build();
      VideoStream videoStream1 =
          VideoStream.newBuilder()
              .setCodec("h264")
              .setBitrateBps(2500000)
              .setFrameRate(60)
              .setHeightPixels(720)
              .setWidthPixels(1280)
              .build();
      AudioStream audioStream0 =
          AudioStream.newBuilder().setCodec("aac").setBitrateBps(64000).build();
      JobConfig config =
          JobConfig.newBuilder()
              .addInputs(Input.newBuilder().setKey("input0").setUri(inputUri))
              .setOutput(Output.newBuilder().setUri(outputUri))
              .addElementaryStreams(
                  ElementaryStream.newBuilder()
                      .setKey("video_stream0")
                      .setVideoStream(videoStream0))
              .addElementaryStreams(
                  ElementaryStream.newBuilder()
                      .setKey("video_stream1")
                      .setVideoStream(videoStream1))
              .addElementaryStreams(
                  ElementaryStream.newBuilder()
                      .setKey("audio_stream0")
                      .setAudioStream(audioStream0))
              .addMuxStreams(
                  MuxStream.newBuilder()
                      .setKey("sd")
                      .setContainer("mp4")
                      .addElementaryStreams("video_stream0")
                      .addElementaryStreams("audio_stream0")
                      .build())
              .addMuxStreams(
                  MuxStream.newBuilder()
                      .setKey("hd")
                      .setContainer("mp4")
                      .addElementaryStreams("video_stream1")
                      .addElementaryStreams("audio_stream0")
                      .build())
              .build();

      var createJobRequest =
          CreateJobRequest.newBuilder()
              .setJob(
                  Job.newBuilder()
                      .setInputUri(inputUri)
                      .setOutputUri(outputUri)
                      .setConfig(config)
                      .build())
              .setParent(LocationName.of(projectId, location).toString())
              .build();

      // Send the job creation request and process the response.
      Job job = transcoderServiceClient.createJob(createJobRequest);
      System.out.println("Job: " + job.getName());
    }
  }
}

Node.js

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.

/**
 * 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/';

// Imports the Transcoder library
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function createJobFromAdHoc() {
  // Construct request
  const request = {
    parent: transcoderServiceClient.locationPath(projectId, location),
    job: {
      inputUri: inputUri,
      outputUri: outputUri,
      config: {
        elementaryStreams: [
          {
            key: 'video-stream0',
            videoStream: {
              codec: 'h264',
              heightPixels: 360,
              widthPixels: 640,
              bitrateBps: 550000,
              frameRate: 60,
            },
          },
          {
            key: 'video-stream1',
            videoStream: {
              codec: 'h264',
              heightPixels: 720,
              widthPixels: 1280,
              bitrateBps: 2500000,
              frameRate: 60,
            },
          },
          {
            key: 'audio-stream0',
            audioStream: {
              codec: 'aac',
              bitrateBps: 64000,
            },
          },
        ],
        muxStreams: [
          {
            key: 'sd',
            container: 'mp4',
            elementaryStreams: ['video-stream0', 'audio-stream0'],
          },
          {
            key: 'hd',
            container: 'mp4',
            elementaryStreams: ['video-stream1', 'audio-stream0'],
          },
        ],
      },
    },
  };

  // Run request
  const [response] = await transcoderServiceClient.createJob(request);
  console.log(`Job: ${response.name}`);
}

createJobFromAdHoc();

Python

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.


import argparse

from google.cloud.video import transcoder_v1beta1
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
    TranscoderServiceClient,
)


def create_job_from_ad_hoc(project_id, location, input_uri, output_uri):
    """Creates a job based on an ad-hoc job configuration.

    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."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.config = transcoder_v1beta1.types.JobConfig(
        elementary_streams=[
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream0",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=360,
                    width_pixels=640,
                    bitrate_bps=550000,
                    frame_rate=60,
                ),
            ),
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream1",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=720,
                    width_pixels=1280,
                    bitrate_bps=2500000,
                    frame_rate=60,
                ),
            ),
            transcoder_v1beta1.types.ElementaryStream(
                key="audio-stream0",
                audio_stream=transcoder_v1beta1.types.AudioStream(
                    codec="aac", bitrate_bps=64000
                ),
            ),
        ],
        mux_streams=[
            transcoder_v1beta1.types.MuxStream(
                key="sd",
                container="mp4",
                elementary_streams=["video-stream0", "audio-stream0"],
            ),
            transcoder_v1beta1.types.MuxStream(
                key="hd",
                container="mp4",
                elementary_streams=["video-stream1", "audio-stream0"],
            ),
        ],
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response

Getting job details

To check the details or status of a job, use the projects.locations.jobs.get method.

REST & CMD LINE

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

  • JOB_ID: The ID of the job you created.
  • PROJECT_ID: Your Google Cloud project ID.
  • LOCATION: The location of your job. Use a location from the following list:
    • us-central1
    • us-west1
    • us-east1
    • southamerica-east1
    • asia-east1
    • europe-west1
  • To send your request, expand one of these options:

    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://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
          }
        ],
        "editList": [
          {
            "key": "atom0",
            "inputs": [
              "input0"
            ],
            "startTimeOffset": "0s"
          }
        ],
        "elementaryStreams": [
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 360,
              "widthPixels": 640,
              "pixelFormat": "yuv420p",
              "bitrateBps": 550000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 550000,
              "vbvFullnessBits": 495000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "frameRate": 60
            },
            "key": "video-stream0"
          },
          {
            "videoStream": {
              "codec": "h264",
              "profile": "high",
              "preset": "veryfast",
              "heightPixels": 720,
              "widthPixels": 1280,
              "pixelFormat": "yuv420p",
              "bitrateBps": 2500000,
              "rateControlMode": "vbr",
              "crfLevel": 21,
              "vbvSizeBits": 2500000,
              "vbvFullnessBits": 2250000,
              "gopDuration": "3s",
              "entropyCoder": "cabac",
              "frameRate": 60
            },
            "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"
            ]
          }
        ],
        "output": {
          "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
        }
      },
      "state": "SUCCEEDED"
      "createTime": CREATE_TIME,
      "startTime": START_TIME,
      "endTime": END_TIME,
      "ttlAfterCompletionDays": 30
    }
    

    gcloud

    1. Make the following replacements for the gcloud command:
      • JOB_ID: The ID of the job you created.
      • LOCATION: The location of your job. Use a location from the following list:
        • us-central1
        • us-west1
        • us-east1
        • southamerica-east1
        • asia-east1
        • europe-west1
    2. Run the following command:
      gcloud beta transcoder jobs describe JOB_ID --location=LOCATION
      You should see a response similar to the following:
      {
        "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID",
        "config": {
          "inputs": [
            {
              "key": "input0",
              "uri": "gs://GCS_BUCKET_NAME/GCS_INPUT_VIDEO"
            }
          ],
          "editList": [
            {
              "key": "atom0",
              "inputs": [
                "input0"
              ],
              "startTimeOffset": "0s"
            }
          ],
          "elementaryStreams": [
            {
              "videoStream": {
                "codec": "h264",
                "profile": "high",
                "preset": "veryfast",
                "heightPixels": 360,
                "widthPixels": 640,
                "pixelFormat": "yuv420p",
                "bitrateBps": 550000,
                "rateControlMode": "vbr",
                "crfLevel": 21,
                "vbvSizeBits": 550000,
                "vbvFullnessBits": 495000,
                "gopDuration": "3s",
                "entropyCoder": "cabac",
                "frameRate": 60
              },
              "key": "video-stream0"
            },
            {
              "videoStream": {
                "codec": "h264",
                "profile": "high",
                "preset": "veryfast",
                "heightPixels": 720,
                "widthPixels": 1280,
                "pixelFormat": "yuv420p",
                "bitrateBps": 2500000,
                "rateControlMode": "vbr",
                "crfLevel": 21,
                "vbvSizeBits": 2500000,
                "vbvFullnessBits": 2250000,
                "gopDuration": "3s",
                "entropyCoder": "cabac",
                "frameRate": 60
              },
              "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"
              ]
            }
          ],
          "output": {
            "uri": "gs://GCS_BUCKET_NAME/GCS_OUTPUT_FOLDER/"
          }
        },
        "state": "SUCCEEDED"
        "createTime": CREATE_TIME,
        "startTime": START_TIME,
        "endTime": END_TIME,
        "ttlAfterCompletionDays": 30
      }
      

    Go

    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.

    import (
    	"context"
    	"fmt"
    	"io"
    
    	transcoder "cloud.google.com/go/video/transcoder/apiv1beta1"
    	transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1"
    )
    
    // getJob gets a previously-created job. See https://cloud.google.com/transcoder/docs/how-to/jobs#check_job_status
    // for more information.
    func getJob(w io.Writer, projectID string, location string, jobID string) error {
    	// projectID := "my-project-id"
    	// location := "us-central1"
    	// jobID := "my-job-id"
    	ctx := context.Background()
    	client, err := transcoder.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("NewClient: %v", err)
    	}
    	defer client.Close()
    
    	req := &transcoderpb.GetJobRequest{
    		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, location, jobID),
    	}
    
    	response, err := client.GetJob(ctx, req)
    	if err != nil {
    		return fmt.Errorf("GetJob: %v", err)
    	}
    
    	fmt.Fprintf(w, "Job: %v", response)
    	return nil
    }
    

    Java

    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.

    
    import com.google.cloud.video.transcoder.v1beta1.GetJobRequest;
    import com.google.cloud.video.transcoder.v1beta1.Job;
    import com.google.cloud.video.transcoder.v1beta1.JobName;
    import com.google.cloud.video.transcoder.v1beta1.TranscoderServiceClient;
    import java.io.IOException;
    
    public class GetJob {
    
      public static void main(String[] args) throws Exception {
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "my-project-id";
        String location = "us-central1";
        String jobId = "my-job-id";
    
        getJob(projectId, location, jobId);
      }
    
      // Gets a job.
      public static void getJob(String projectId, String location, String jobId) throws IOException {
        // 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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
          JobName jobName =
              JobName.newBuilder().setProject(projectId).setLocation(location).setJob(jobId).build();
          var getJobRequest = GetJobRequest.newBuilder().setName(jobName.toString()).build();
    
          // Send the get job request and process the response.
          Job job = transcoderServiceClient.getJob(getJobRequest);
          System.out.println("Job: " + job.getName());
        }
      }
    }

    Node.js

    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.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // projectId = 'my-project-id';
    // location = 'us-central1';
    // jobId = 'my-job-id';
    
    // Imports the Transcoder library
    const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
    
    // Instantiates a client
    const transcoderServiceClient = new TranscoderServiceClient();
    
    async function getJob() {
      // Construct request
      const request = {
        name: transcoderServiceClient.jobPath(projectId, location, jobId),
      };
      const [response] = await transcoderServiceClient.getJob(request);
      console.log(`Job: ${response.name}`);
    }
    
    getJob();

    Python

    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.

    
    import argparse
    
    from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
        TranscoderServiceClient,
    )
    
    
    def get_job(project_id, location, job_id):
        """Gets a job.
    
        Args:
            project_id: The GCP project ID.
            location: The location this job is in.
            job_id: The job ID."""
    
        client = TranscoderServiceClient()
    
        name = f"projects/{project_id}/locations/{location}/jobs/{job_id}"
        response = client.get_job(name=name)
        print(f"Job: {response.name}")
        return response
    
    

    The response is similar to the response returned when creating a job.

    Listing jobs

    If you want to review all the jobs you created in a location, use the projects.locations.jobs.list method.

    REST & CMD LINE

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

  • PROJECT_ID: Your Google Cloud project ID.
  • LOCATION: The location of your jobs. Use a location from the following list:
    • us-central1
    • us-west1
    • us-east1
    • southamerica-east1
    • asia-east1
    • europe-west1
  • To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    {
      "jobs": [
        {
          "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/MY_JOB",
          "config": {
            ....
           },
          "state": "SUCCEEDED"
        },
        {
          "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/MY_OTHER_JOB",
          "config": {
            ....
           },
          "state": "SUCCEEDED"
        }
      ]
    }
    

    gcloud

    1. Make the following replacements for the gcloud command:
      • LOCATION: The location of your job(s). Use a location from the following list:
        • us-central1
        • us-west1
        • us-east1
        • southamerica-east1
        • asia-east1
        • europe-west1
    2. Run the following command:
      gcloud beta transcoder jobs list --location=LOCATION
      You should see a response similar to the following:
      NAME                                                    STATE      FAILURE_REASON
      projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID  SUCCEEDED
      projects/PROJECT_NUMBER/locations/LOCATION/jobs/abc123  SUCCEEDED
      

    Go

    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.

    import (
    	"context"
    	"fmt"
    	"io"
    
    	"google.golang.org/api/iterator"
    
    	transcoder "cloud.google.com/go/video/transcoder/apiv1beta1"
    	transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1"
    )
    
    // listJobs lists all jobs for a given location. See
    // https://cloud.google.com/transcoder/docs/how-to/jobs#list_jobs for more
    // information.
    func listJobs(w io.Writer, projectID string, location string) error {
    	// projectID := "my-project-id"
    	// location := "us-central1"
    	ctx := context.Background()
    	client, err := transcoder.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("NewClient: %v", err)
    	}
    	defer client.Close()
    
    	req := &transcoderpb.ListJobsRequest{
    		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
    	}
    
    	it := client.ListJobs(ctx, req)
    	fmt.Fprintln(w, "Jobs:")
    
    	for {
    		response, err := it.Next()
    		if err == iterator.Done {
    			break
    		}
    		if err != nil {
    			return fmt.Errorf("ListJobs: %v", err)
    		}
    		fmt.Fprintln(w, response.GetName())
    	}
    	return nil
    }
    

    Java

    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.

    
    import com.google.cloud.video.transcoder.v1beta1.Job;
    import com.google.cloud.video.transcoder.v1beta1.ListJobsRequest;
    import com.google.cloud.video.transcoder.v1beta1.LocationName;
    import com.google.cloud.video.transcoder.v1beta1.TranscoderServiceClient;
    import java.io.IOException;
    
    public class ListJobs {
    
      public static void main(String[] args) throws Exception {
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "my-project-id";
        String location = "us-central1";
    
        listJobs(projectId, location);
      }
    
      // Lists the jobs for a given location.
      public static void listJobs(String projectId, String location) throws IOException {
        // 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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
    
          var listJobsRequest =
              ListJobsRequest.newBuilder()
                  .setParent(LocationName.of(projectId, location).toString())
                  .build();
    
          // Send the list jobs request and process the response.
          TranscoderServiceClient.ListJobsPagedResponse response =
              transcoderServiceClient.listJobs(listJobsRequest);
          System.out.println("Jobs:");
    
          for (Job job : response.iterateAll()) {
            System.out.println(job.getName());
          }
        }
      }
    }

    Node.js

    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.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // projectId = 'my-project-id';
    // location = 'us-central1';
    
    // Imports the Transcoder library
    const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
    
    // Instantiates a client
    const transcoderServiceClient = new TranscoderServiceClient();
    
    async function listJobs() {
      const [jobs] = await transcoderServiceClient.listJobs({
        parent: transcoderServiceClient.locationPath(projectId, location),
      });
      console.info('Jobs:');
      for (const job of jobs) {
        console.info(job.name);
      }
    }
    
    listJobs();

    Python

    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.

    
    import argparse
    
    from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
        TranscoderServiceClient,
    )
    
    
    def list_jobs(project_id, location):
        """Lists all jobs in a location.
    
        Args:
            project_id: The GCP project ID.
            location: The location of the jobs."""
    
        client = TranscoderServiceClient()
    
        parent = f"projects/{project_id}/locations/{location}"
        response = client.list_jobs(parent=parent)
        print("Jobs:")
        for job in response.jobs:
            print({job.name})
    
        return response
    
    

    This response may include a nextPageToken, which you can use to retrieve additional results:

    {
      "jobs": [
        ...
      ],
      "nextPageToken": "NEXT_PAGE_TOKEN"
    }
    

    In the following curl example, you can then send another request, and include the value of NEXT_PAGE_TOKEN to list additional jobs, similar to the following:

    curl -X GET \
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    https://transcoder.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/jobs?pageToken=NEXT_PAGE_TOKEN
    

    See the relevant client library for more information on using this token.

    Deleting jobs

    To delete a job, use the projects.locations.jobs.delete method.

    REST & CMD LINE

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

  • JOB_ID: The ID of the job you created.
  • PROJECT_ID: Your Google Cloud project ID.
  • LOCATION: The location of your job. Use a location from the following list:
    • us-central1
    • us-west1
    • us-east1
    • southamerica-east1
    • asia-east1
    • europe-west1
  • To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    {}
    

    gcloud

    1. Make the following replacements for the gcloud command:
      • JOB_ID: The ID of the job you created.
      • LOCATION: The location of your job. Use a location from the following list:
        • us-central1
        • us-west1
        • us-east1
        • southamerica-east1
        • asia-east1
        • europe-west1
    2. Run the following command:
      gcloud beta transcoder jobs delete JOB_ID --location=LOCATION
      You should see a response similar to the following:
      Deleted job [projects/PROJECT_ID/locations/LOCATION/jobs/JOB_ID].
      

    Go

    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.

    import (
    	"context"
    	"fmt"
    	"io"
    
    	transcoder "cloud.google.com/go/video/transcoder/apiv1beta1"
    	transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1"
    )
    
    // deleteJob deletes a previously-created job. See
    // https://cloud.google.com/transcoder/docs/how-to/jobs#delete_jobs for more
    // information.
    func deleteJob(w io.Writer, projectID string, location string, jobID string) error {
    	// projectID := "my-project-id"
    	// location := "us-central1"
    	// jobID := "my-job-id"
    	ctx := context.Background()
    	client, err := transcoder.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("NewClient: %v", err)
    	}
    	defer client.Close()
    
    	req := &transcoderpb.DeleteJobRequest{
    		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, location, jobID),
    	}
    
    	err = client.DeleteJob(ctx, req)
    	if err != nil {
    		return fmt.Errorf("DeleteJob: %v", err)
    	}
    
    	fmt.Fprintf(w, "Deleted job")
    	return nil
    }
    

    Java

    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.

    
    import com.google.cloud.video.transcoder.v1beta1.DeleteJobRequest;
    import com.google.cloud.video.transcoder.v1beta1.JobName;
    import com.google.cloud.video.transcoder.v1beta1.TranscoderServiceClient;
    import java.io.IOException;
    
    public class DeleteJob {
    
      public static void main(String[] args) throws Exception {
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "my-project-id";
        String location = "us-central1";
        String jobId = "my-job-id";
    
        deleteJob(projectId, location, jobId);
      }
    
      // Deletes a job.
      public static void deleteJob(String projectId, String location, String jobId) throws IOException {
        // 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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
          JobName jobName =
              JobName.newBuilder().setProject(projectId).setLocation(location).setJob(jobId).build();
          var deleteJobRequest = DeleteJobRequest.newBuilder().setName(jobName.toString()).build();
    
          // Send the delete job request and process the response.
          transcoderServiceClient.deleteJob(deleteJobRequest);
          System.out.println("Deleted job");
        }
      }
    }

    Node.js

    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.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // projectId = 'my-project-id';
    // location = 'us-central1';
    // jobId = 'my-job-id';
    
    // Imports the Transcoder library
    const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
    
    // Instantiates a client
    const transcoderServiceClient = new TranscoderServiceClient();
    
    async function deleteJob() {
      // Construct request
      const request = {
        name: transcoderServiceClient.jobPath(projectId, location, jobId),
      };
      await transcoderServiceClient.deleteJob(request);
      console.log('Deleted job');
    }
    
    deleteJob();

    Python

    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.

    
    import argparse
    
    from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
        TranscoderServiceClient,
    )
    
    
    def delete_job(project_id, location, job_id):
        """Gets a job.
    
        Args:
            project_id: The GCP project ID.
            location: The location this job is in.
            job_id: The job ID."""
    
        client = TranscoderServiceClient()
    
        name = f"projects/{project_id}/locations/{location}/jobs/{job_id}"
        response = client.delete_job(name=name)
        print("Deleted job")
        return response
    
    

    What's next

    Learn about Creating and managing job templates.