Transcodifica di un video con l'API Transcoder

Questa pagina mostra come creare un job di transcodifica video di base utilizzando le impostazioni predefinite dell'API Transcoder e di curl, di Windows PowerShell o delle librerie client.

Puoi anche eseguire questa guida rapida direttamente nella console Google Cloud utilizzando uno dei seguenti linguaggi di programmazione:

Prima di iniziare

  1. Accedi al tuo account Google Cloud. Se non conosci Google Cloud, crea un account per valutare le prestazioni dei nostri prodotti in scenari reali. I nuovi clienti ricevono anche 300 $di crediti gratuiti per l'esecuzione, il test e il deployment dei carichi di lavoro.
  2. Installa Google Cloud CLI.
  3. Per initialize gcloud CLI, esegui questo comando:

    gcloud init
  4. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  5. Assicurati che la fatturazione sia attivata per il tuo progetto Google Cloud.

  6. Attiva l'API Transcoder.

    gcloud services enable transcoder.googleapis.com
  7. Crea credenziali di autenticazione locali per il tuo Account Google:

    gcloud auth application-default login
  8. Concedi i ruoli al tuo Account Google. Esegui questo comando una volta per ciascuno dei seguenti ruoli IAM: roles/transcoder.admin, roles/storage.admin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="user:EMAIL_ADDRESS" --role=ROLE
    • Sostituisci PROJECT_ID con l'ID progetto.
    • Sostituisci EMAIL_ADDRESS con il tuo indirizzo email.
    • Sostituisci ROLE con ogni singolo ruolo.
  9. Installa Google Cloud CLI.
  10. Per initialize gcloud CLI, esegui questo comando:

    gcloud init
  11. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  12. Assicurati che la fatturazione sia attivata per il tuo progetto Google Cloud.

  13. Attiva l'API Transcoder.

    gcloud services enable transcoder.googleapis.com
  14. Crea credenziali di autenticazione locali per il tuo Account Google:

    gcloud auth application-default login
  15. Concedi i ruoli al tuo Account Google. Esegui questo comando una volta per ciascuno dei seguenti ruoli IAM: roles/transcoder.admin, roles/storage.admin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="user:EMAIL_ADDRESS" --role=ROLE
    • Sostituisci PROJECT_ID con l'ID progetto.
    • Sostituisci EMAIL_ADDRESS con il tuo indirizzo email.
    • Sostituisci ROLE con ogni singolo ruolo.

crea un bucket Cloud Storage

  1. Nella console Google Cloud, vai alla pagina Bucket di Cloud Storage.

    Vai alla pagina Bucket

  2. Fai clic su Crea bucket.
  3. Nella pagina Crea un bucket, inserisci le informazioni del bucket. Per andare al passaggio successivo, fai clic su Continua.
    • In Assegna un nome al bucket, inserisci un nome univoco per il bucket. Non includere informazioni sensibili nel nome del bucket, poiché lo spazio dei nomi dei bucket è globale e visibile pubblicamente.
    • Per Scegli dove archiviare i tuoi dati, segui questi passaggi:
      • Seleziona un'opzione Tipo di località.
      • Seleziona un'opzione Località.
    • Per Scegli una classe di archiviazione predefinita per i dati, seleziona quanto segue: Standard.
    • Per Scegli come controllare l'accesso agli oggetti, seleziona un'opzione Controllo dell'accesso.
    • In Impostazioni avanzate (facoltative), specifica un metodo di crittografia, un criterio di conservazione o le etichette dei bucket.
  4. Fai clic su Crea.
  5. Fai clic su Crea cartella e inserisci un nome per creare una cartella in cui salvare gli output video codificati.

Transcodifica di un video utilizzando l'API Transcoder

Per i seguenti passaggi (video di esempio), devi creare un video di almeno 5 secondi dal tuo computer locale. Consulta l'elenco dei formati di input e di output supportati.

Carica un video sul bucket Cloud Storage

  1. Nella console Google Cloud, vai alla pagina Browser Cloud Storage.
    Vai alla pagina del browser Cloud Storage
  2. Fai clic sul nome del bucket per aprirlo.
  3. Fai clic su Carica file.
  4. Seleziona un file video da caricare dal tuo computer locale.

Il video è stato salvato nel bucket Cloud Storage.

Crea un job di transcodifica

Per impostazione predefinita, l'API Transcoder transcodifica i video utilizzando la codifica H.264 e la pacchettizzazione in formato MP4, HLS e MPEG-DASH. Per ogni video in ingresso, fornisce rappresentazioni di output in alta definizione (1280 x 720 pixel) e in definizione standard (640 x 360 pixel).

Per creare un job, utilizza il metodo projects.locations.jobs.create. I seguenti esempi di codice creano un job di transcodifica di base utilizzando un preset.

REST

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_ID: l'ID del tuo progetto Google Cloud elencato nelle impostazioni IAM.
  • LOCATION: la località in cui verrà eseguito il job. Utilizza una delle regioni supportate.
    Mostra località
    • us-central1
    • us-west1
    • us-west2
    • us-east1
    • us-east4
    • southamerica-east1
    • northamerica-northeast1
    • asia-east1
    • asia-northeast1
    • asia-northeast3
    • asia-south1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west4
  • STORAGE_BUCKET_NAME: il nome del bucket Cloud Storage che hai creato.
  • STORAGE_INPUT_VIDEO: il nome del video nel bucket Cloud Storage che stai transcodificando, ad esempio my-vid.mp4. Questo campo deve tenere conto di eventuali cartelle create nel bucket (ad esempio, input/my-vid.mp4).
  • STORAGE_OUTPUT_FOLDER: il nome della cartella di Cloud Storage in cui vuoi salvare gli output video codificati.

Per inviare la richiesta, espandi una delle seguenti opzioni:

Questo particolare esempio REST utilizza il parametro di query facoltativo fields per mostrare nella risposta solo il nome della risorsa creata.

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID"
}

gcloud

  1. Apporta le seguenti sostituzioni per il comando gcloud:
    • STORAGE_BUCKET_NAME: il nome del bucket Cloud Storage che hai creato.
    • STORAGE_INPUT_VIDEO: il nome del video nel bucket Cloud Storage che stai transcodificando, ad esempio my-vid.mp4. Questo campo deve tenere conto di eventuali cartelle create nel bucket (ad esempio, input/my-vid.mp4).
    • LOCATION: la località in cui verrà eseguito il job. Utilizza una delle regioni supportate.
      Mostra località
      • us-central1
      • us-west1
      • us-west2
      • us-east1
      • us-east4
      • southamerica-east1
      • northamerica-northeast1
      • asia-east1
      • asia-northeast1
      • asia-northeast3
      • asia-south1
      • asia-southeast1
      • australia-southeast1
      • europe-west1
      • europe-west2
      • europe-west4
    • STORAGE_OUTPUT_FOLDER: il nome della cartella di Cloud Storage in cui vuoi salvare gli output video codificati.
  2. Esegui questo comando:
    gcloud transcoder jobs create \
      --input-uri="gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" \
      --location=LOCATION \
      --output-uri="gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/"
    
    Dovresti vedere una risposta simile alla seguente:
    {
      "config": {
       ...
      },
      "createTime": CREATE_TIME,
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID",
      "state": "PENDING",
      "ttlAfterCompletionDays": 30
    }
    

C#

Prima di provare questo esempio, segui le istruzioni per la configurazione di C# nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API C# dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


using Google.Api.Gax.ResourceNames;
using Google.Cloud.Video.Transcoder.V1;

public class CreateJobFromPresetSample
{
    public Job CreateJobFromPreset(
        string projectId, string location, string inputUri, string outputUri, string preset)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the parent location name.
        LocationName parent = new LocationName(projectId, location);

        // Build the job.
        Job newJob = new Job
        {
            InputUri = inputUri,
            OutputUri = outputUri,
            TemplateId = preset
        };

        // Call the API.
        Job job = client.CreateJob(parent, newJob);

        // Return the result.
        return job;
    }
}

Go

Prima di provare questo esempio, segui le istruzioni per la configurazione di Go nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Go dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1"
	"cloud.google.com/go/video/transcoder/apiv1/transcoderpb"
)

// 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) 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: %w", 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: %w", err)
	}

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

Java

Prima di provare questo esempio, segui le istruzioni per la configurazione di Java nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Java dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import com.google.cloud.video.transcoder.v1.CreateJobRequest;
import com.google.cloud.video.transcoder.v1.Job;
import com.google.cloud.video.transcoder.v1.LocationName;
import com.google.cloud.video.transcoder.v1.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/";
    // See https://cloud.google.com/transcoder/docs/concepts/overview#job_template
    // for information on this preset.
    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()) {

      CreateJobRequest 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

Prima di provare questo esempio, segui le istruzioni per la configurazione di Node.js nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Node.js dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

// 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();

PHP

Prima di provare questo esempio, segui le istruzioni per la configurazione di PHP nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API PHP dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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 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($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);
    $request = (new CreateJobRequest())
        ->setParent($formattedParent)
        ->setJob($job);

    $response = $transcoderServiceClient->createJob($request);

    // Print job name.
    printf('Job: %s' . PHP_EOL, $response->getName());
}

Python

Prima di provare questo esempio, segui le istruzioni per la configurazione di Python nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Python dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import argparse

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


def create_job_from_preset(
    project_id: str,
    location: str,
    input_uri: str,
    output_uri: str,
    preset: str,
) -> transcoder_v1.types.resources.Job:
    """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 (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_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

Ruby

Prima di provare questo esempio, segui le istruzioni per la configurazione di Ruby nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Ruby dell'API Transcoder.

Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

# 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_path project: project_id, location: location

# Set the job fields.
new_job = {
  input_uri: input_uri,
  output_uri: output_uri,
  template_id: preset
}

job = client.create_job parent: parent, job: new_job

# Print the job name.
puts "Job: #{job.name}"

Copia il valore JOB_ID restituito. È necessario per ottenere lo stato del job.

Controllare lo stato del job di transcodifica

Per controllare lo stato di un job, utilizza il metodo projects.locations.jobs.get. I seguenti esempi di codice recuperano i dettagli del job e quindi mostrano lo stato del job.

REST

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • JOB_ID: l'ID del job che hai creato.
  • PROJECT_ID: l'ID del tuo progetto Google Cloud.
  • LOCATION: la posizione del tuo lavoro. Utilizza una delle regioni supportate.
    Mostra località
    • us-central1
    • us-west1
    • us-west2
    • us-east1
    • us-east4
    • southamerica-east1
    • northamerica-northeast1
    • asia-east1
    • asia-northeast1
    • asia-northeast3
    • asia-south1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west4
  • Per inviare la richiesta, espandi una delle seguenti opzioni:

    Dovresti ricevere una risposta JSON simile alla seguente:

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

    1. Apporta le seguenti sostituzioni per il comando gcloud:
      • JOB_ID: l'ID del job che hai creato.
      • LOCATION: la località del job. Utilizza una delle regioni supportate.
        Mostra località
        • us-central1
        • us-west1
        • us-west2
        • us-east1
        • us-east4
        • southamerica-east1
        • northamerica-northeast1
        • asia-east1
        • asia-northeast1
        • asia-northeast3
        • asia-south1
        • asia-southeast1
        • australia-southeast1
        • europe-west1
        • europe-west2
        • europe-west4
    2. Esegui questo comando:
      gcloud transcoder jobs describe JOB_ID --location=LOCATION
      Dovresti vedere una risposta simile alla seguente:
      {
        "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#

    Prima di provare questo esempio, segui le istruzioni per la configurazione di C# nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API C# dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    
    using Google.Cloud.Video.Transcoder.V1;
    
    public class GetJobStateSample
    {
        public Job.Types.ProcessingState GetJobState(string projectId, string location, string jobId)
        {
            // Create the client.
            TranscoderServiceClient client = TranscoderServiceClient.Create();
    
            // Build the job name.
            JobName jobName = JobName.FromProjectLocationJob(projectId, location, jobId);
    
            // Call the API.
            Job job = client.GetJob(jobName);
    
            // Return the result.
            return job.State;
        }
    }

    Go

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Go nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Go dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    import (
    	"context"
    	"fmt"
    	"io"
    
    	transcoder "cloud.google.com/go/video/transcoder/apiv1"
    	"cloud.google.com/go/video/transcoder/apiv1/transcoderpb"
    )
    
    // getJobState gets the state for a previously-created job. See
    // https://cloud.google.com/transcoder/docs/how-to/jobs#check_job_status for
    // more information.
    func getJobState(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: %w", 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: %w", err)
    	}
    	fmt.Fprintf(w, "Job state: %v\n----\nJob failure reason:%v\n", response.State, response.Error)
    	return nil
    }
    

    Java

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Java nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Java dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    
    import com.google.cloud.video.transcoder.v1.GetJobRequest;
    import com.google.cloud.video.transcoder.v1.Job;
    import com.google.cloud.video.transcoder.v1.JobName;
    import com.google.cloud.video.transcoder.v1.TranscoderServiceClient;
    import java.io.IOException;
    
    public class GetJobState {
    
      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";
    
        getJobState(projectId, location, jobId);
      }
    
      // Gets the state of a job.
      public static void getJobState(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();
          GetJobRequest 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 state: " + job.getState());
        }
      }
    }

    Node.js

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Node.js nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Node.js dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    /**
     * 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').v1;
    
    // 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 state: ${response.state}`);
    }
    
    getJob();

    PHP

    Prima di provare questo esempio, segui le istruzioni per la configurazione di PHP nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API PHP dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient;
    use Google\Cloud\Video\Transcoder\V1\GetJobRequest;
    use Google\Cloud\Video\Transcoder\V1\Job;
    
    /**
     * Gets a Transcoder job's state.
     *
     * @param string $projectId The ID of your Google Cloud Platform project.
     * @param string $location The location of the job.
     * @param string $jobId The job ID.
     */
    function get_job_state($projectId, $location, $jobId)
    {
        // Instantiate a client.
        $transcoderServiceClient = new TranscoderServiceClient();
    
        $formattedName = $transcoderServiceClient->jobName($projectId, $location, $jobId);
        $request = (new GetJobRequest())
            ->setName($formattedName);
        $job = $transcoderServiceClient->getJob($request);
    
        // Print job state.
        printf('Job state: %s' . PHP_EOL, Job\ProcessingState::name($job->getState()));
    }

    Python

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Python nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Python dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    
    import argparse
    
    from google.cloud.video import transcoder_v1
    from google.cloud.video.transcoder_v1.services.transcoder_service import (
        TranscoderServiceClient,
    )
    
    
    def get_job_state(
        project_id: str,
        location: str,
        job_id: str,
    ) -> transcoder_v1.types.resources.Job:
        """Gets a job's state.
    
        Args:
            project_id: The GCP project ID.
            location: The location this job is in.
            job_id: The job ID.
    
        Returns:
            The job resource.
        """
    
        client = TranscoderServiceClient()
    
        name = f"projects/{project_id}/locations/{location}/jobs/{job_id}"
        response = client.get_job(name=name)
    
        print(f"Job state: {str(response.state.name)}")
        return response
    
    

    Ruby

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Ruby nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Ruby dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    # project_id = "YOUR-GOOGLE-CLOUD-PROJECT"  # (e.g. "my-project")
    # location   = "YOUR-JOB-LOCATION"  # (e.g. "us-central1")
    # job_id     = "YOUR-JOB-ID"  # (e.g. "c82c295b-3f5a-47df-8562-938a89d40fd0")
    
    # 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 job.
    name = client.job_path project: project_id, location: location, job: job_id
    
    # Get the job.
    job = client.get_job name: name
    
    # Print the job state.
    puts "Job state: #{job.state}"

    Se state è SUCCEEDED, il job viene completato e gli output video sono ora disponibili nell'elenco di file codificati del bucket Cloud Storage.

    Riproduci il video

    Per riprodurre il file multimediale generato in Shaka Player, completa i seguenti passaggi:

    1. Rendi leggibile pubblicamente il bucket Cloud Storage che hai creato.
    2. Per abilitare la condivisione delle risorse tra origini (CORS) in un bucket Cloud Storage, segui questi passaggi:
      1. Crea un file JSON contenente quanto segue:
        [
          {
            "origin": ["https://shaka-player-demo.appspot.com/"],
            "responseHeader": ["Content-Type", "Range"],
            "method": ["GET", "HEAD"],
            "maxAgeSeconds": 3600
          }
        ]
      2. Esegui questo comando dopo aver sostituito JSON_FILE_NAME con il nome del file JSON che hai creato nel passaggio precedente:
        gsutil cors set JSON_FILE_NAME.json gs://STORAGE_BUCKET_NAME
    3. Scegli uno dei file MP4 o manifest generati dal job di transcodifica nel bucket Cloud Storage. Fai clic su Copia URL nella colonna Accesso pubblico del file.
    4. Vai a Shaka Player, un player online per il live streaming.
    5. Fai clic su Custom Content (Contenuti personalizzati) nella barra di navigazione in alto.
    6. Fai clic sul pulsante +.
    7. Incolla l'URL pubblico del file nella casella Manifest URL (URL del manifest).

      Inserisci l'URL del file in Shaka Player.

    8. Digita un nome nella casella Name (Nome).

    9. Fai clic su Salva.

    10. Fai clic su Play (Riproduci).

    Esegui la pulizia

    Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questa pagina, segui questi passaggi.

    Elimina il bucket

    1. Nella console Google Cloud, vai alla pagina Browser Cloud Storage.

      Vai alla pagina Browser Cloud Storage

    2. Seleziona la casella di controllo accanto al bucket che hai creato.

    3. Fai clic su Elimina.

    4. Nella finestra popup che viene visualizzata, fai clic su Elimina per eliminare definitivamente il bucket e i relativi contenuti.

    Elimina il job

    REST

    Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • JOB_ID: l'ID del job che hai creato.
  • PROJECT_ID: l'ID del tuo progetto Google Cloud.
  • LOCATION: la posizione del tuo lavoro. Utilizza una delle regioni supportate.
    Mostra località
    • us-central1
    • us-west1
    • us-west2
    • us-east1
    • us-east4
    • southamerica-east1
    • northamerica-northeast1
    • asia-east1
    • asia-northeast1
    • asia-northeast3
    • asia-south1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west4
  • Per inviare la richiesta, espandi una delle seguenti opzioni:

    Dovresti ricevere una risposta JSON simile alla seguente:

    {}
    

    gcloud

    1. Apporta le seguenti sostituzioni per il comando gcloud:
      • JOB_ID: l'ID del job che hai creato.
      • LOCATION: la località del job. Utilizza una delle regioni supportate.
        Mostra località
        • us-central1
        • us-west1
        • us-west2
        • us-east1
        • us-east4
        • southamerica-east1
        • northamerica-northeast1
        • asia-east1
        • asia-northeast1
        • asia-northeast3
        • asia-south1
        • asia-southeast1
        • australia-southeast1
        • europe-west1
        • europe-west2
        • europe-west4
    2. Esegui questo comando:
      gcloud transcoder jobs delete JOB_ID --location=LOCATION
      Dovresti vedere una risposta simile alla seguente:
      Deleted job [projects/PROJECT_ID/locations/LOCATION/jobs/JOB_ID].
      

    C#

    Prima di provare questo esempio, segui le istruzioni per la configurazione di C# nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API C# dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    
    using Google.Cloud.Video.Transcoder.V1;
    
    public class DeleteJobSample
    {
        public void DeleteJob(string projectId, string location, string jobId)
        {
            // Create the client.
            TranscoderServiceClient client = TranscoderServiceClient.Create();
    
            // Build the job name.
            JobName jobName = JobName.FromProjectLocationJob(projectId, location, jobId);
    
            // Call the API.
            client.DeleteJob(jobName);
        }
    }

    Go

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Go nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Go dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    import (
    	"context"
    	"fmt"
    	"io"
    
    	transcoder "cloud.google.com/go/video/transcoder/apiv1"
    	"cloud.google.com/go/video/transcoder/apiv1/transcoderpb"
    )
    
    // 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: %w", 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: %w", err)
    	}
    
    	fmt.Fprintf(w, "Deleted job")
    	return nil
    }
    

    Java

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Java nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Java dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    
    import com.google.cloud.video.transcoder.v1.DeleteJobRequest;
    import com.google.cloud.video.transcoder.v1.JobName;
    import com.google.cloud.video.transcoder.v1.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();
          DeleteJobRequest 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

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Node.js nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Node.js dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    /**
     * 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').v1;
    
    // 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();

    PHP

    Prima di provare questo esempio, segui le istruzioni per la configurazione di PHP nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API PHP dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient;
    use Google\Cloud\Video\Transcoder\V1\DeleteJobRequest;
    
    /**
     * Deletes a Transcoder job.
     *
     * @param string $projectId The ID of your Google Cloud Platform project.
     * @param string $location The location of the job.
     * @param string $jobId The job ID.
     */
    function delete_job($projectId, $location, $jobId)
    {
        // Instantiate a client.
        $transcoderServiceClient = new TranscoderServiceClient();
    
        $formattedName = $transcoderServiceClient->jobName($projectId, $location, $jobId);
        $request = (new DeleteJobRequest())
            ->setName($formattedName);
        $transcoderServiceClient->deleteJob($request);
    
        print('Deleted job' . PHP_EOL);
    }

    Python

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Python nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Python dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    
    import argparse
    
    from google.cloud.video.transcoder_v1.services.transcoder_service import (
        TranscoderServiceClient,
    )
    
    
    def delete_job(
        project_id: str,
        location: str,
        job_id: str,
    ) -> None:
        """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
    
    

    Ruby

    Prima di provare questo esempio, segui le istruzioni per la configurazione di Ruby nella guida rapida dell'API Transcoder sull'utilizzo delle librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Ruby dell'API Transcoder.

    Per eseguire l'autenticazione nell'API Transcoder, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

    # project_id = "YOUR-GOOGLE-CLOUD-PROJECT"  # (e.g. "my-project")
    # location   = "YOUR-JOB-LOCATION"  # (e.g. "us-central1")
    # job_id     = "YOUR-JOB-ID"  # (e.g. "c82c295b-3f5a-47df-8562-938a89d40fd0")
    
    # 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 job.
    name = client.job_path project: project_id, location: location, job: job_id
    
    # Delete the job.
    client.delete_job name: name
    
    # Print a success message.
    puts "Deleted job"

    Revocare le credenziali

    1. Facoltativo: revoca le credenziali di autenticazione che hai creato ed elimina il file delle credenziali locale.

      gcloud auth application-default revoke
    2. Facoltativo: revoca le credenziali dallgcloud CLI.

      gcloud auth revoke

    Passaggi successivi