Slate aktualisieren

Aktualisieren Sie eine Video Stitcher-Slate-Ressource.

Weitere Informationen

Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:

Codebeispiel

C#

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für C# in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der C# API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


using Google.Cloud.Video.Stitcher.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public class UpdateSlateSample
{
    public async Task<Slate> UpdateSlateAsync(
        string projectId, string location, string slateId, string slateUri)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        UpdateSlateRequest request = new UpdateSlateRequest
        {
            Slate = new Slate
            {
                SlateName = SlateName.FromProjectLocationSlate(projectId, location, slateId),
                Uri = slateUri
            },
            UpdateMask = new FieldMask { Paths = { "uri" } }
        };

        // Make the request.
        Operation<Slate, OperationMetadata> response = await client.UpdateSlateAsync(request);

        // Poll until the returned long-running operation is complete.
        Operation<Slate, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return completedResponse.Result;
    }
}

Go

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für Go in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Go API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

import (
	"context"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	stitcherstreampb "cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
	"google.golang.org/protobuf/types/known/fieldmaskpb"
)

// updateSlate updates an existing slate. This sample updates the uri for an
// existing slate.
func updateSlate(w io.Writer, projectID, slateID, slateURI string) error {
	// projectID := "my-project-id"
	// slateID := "my-slate-id"
	// slateURI := "https://my-updated-slate-uri/test.mp4"
	location := "us-central1"
	ctx := context.Background()
	client, err := stitcher.NewVideoStitcherClient(ctx)
	if err != nil {
		return fmt.Errorf("stitcher.NewVideoStitcherClient: %w", err)
	}
	defer client.Close()

	req := &stitcherstreampb.UpdateSlateRequest{
		Slate: &stitcherstreampb.Slate{
			Name: fmt.Sprintf("projects/%s/locations/%s/slates/%s", projectID, location, slateID),
			Uri:  slateURI,
		},
		UpdateMask: &fieldmaskpb.FieldMask{
			Paths: []string{
				"uri",
			},
		},
	}
	// Updates the slate.
	op, err := client.UpdateSlate(ctx, req)
	if err != nil {
		return fmt.Errorf("client.UpdateSlate: %w", err)
	}
	response, err := op.Wait(ctx)
	if err != nil {
		return err
	}

	fmt.Fprintf(w, "Updated slate: %+v", response)
	return nil
}

Java

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für Java in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Java API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import com.google.cloud.video.stitcher.v1.Slate;
import com.google.cloud.video.stitcher.v1.SlateName;
import com.google.cloud.video.stitcher.v1.UpdateSlateRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.protobuf.FieldMask;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class UpdateSlate {

  private static final int TIMEOUT_IN_MINUTES = 2;

  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 slateId = "my-slate-id";
    String slateUri =
        "https://my-slate-uri/test.mp4"; // URI of an MP4 video with at least one audio track

    updateSlate(projectId, location, slateId, slateUri);
  }

  // updateSlate updates the slate URI for an existing slate.
  public static void updateSlate(String projectId, String location, String slateId, String slateUri)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create();
    UpdateSlateRequest updateSlateRequest =
        UpdateSlateRequest.newBuilder()
            .setSlate(
                Slate.newBuilder()
                    .setName(SlateName.of(projectId, location, slateId).toString())
                    .setUri(slateUri)
                    .build())
            // Set the update mask to the uri field in the existing slate. You must set the mask
            // to the field you want to update.
            .setUpdateMask(FieldMask.newBuilder().addPaths("uri").build())
            .build();

    Slate response =
        videoStitcherServiceClient
            .updateSlateAsync(updateSlateRequest)
            .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES);
    System.out.println("Updated slate: " + response.getName());
    videoStitcherServiceClient.close();
  }
}

Node.js

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für Node.js in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Node.js API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// slateId = 'my-slate';
// slateUri = 'https://my-slate-uri/test.mp4';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
  require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function updateSlate() {
  // Construct request
  const request = {
    slate: {
      name: stitcherClient.slatePath(projectId, location, slateId),
      uri: slateUri,
    },
    updateMask: {
      paths: ['uri'],
    },
  };

  const [operation] = await stitcherClient.updateSlate(request);
  const [response] = await operation.promise();
  console.log(`Updated slate: ${response.name}`);
  console.log(`Updated uri: ${response.uri}`);
}

updateSlate();

PHP

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für PHP in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der PHP API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\Slate;
use Google\Cloud\Video\Stitcher\V1\UpdateSlateRequest;
use Google\Protobuf\FieldMask;

/**
 * Updates a slate's uri field.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the slate
 * @param string $slateId              The name of the slate to be created
 * @param string $slateUri             The public URI for an MP4 video with at least one audio track
 */
function update_slate(
    string $callingProjectId,
    string $location,
    string $slateId,
    string $slateUri
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->slateName($callingProjectId, $location, $slateId);
    $slate = new Slate();
    $slate->setName($formattedName);
    $slate->setUri($slateUri);
    $updateMask = new FieldMask([
        'paths' => ['uri']
    ]);

    // Run slate update request
    $request = (new UpdateSlateRequest())
        ->setSlate($slate)
        ->setUpdateMask($updateMask);
    $operationResponse = $stitcherClient->updateSlate($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // Print results
        printf('Updated slate: %s' . PHP_EOL, $result->getName());
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

Python

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für Python in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Python API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    VideoStitcherServiceClient,
)
from google.protobuf import field_mask_pb2 as field_mask

def update_slate(
    project_id: str, location: str, slate_id: str, slate_uri: str
) -> stitcher_v1.types.Slate:
    """Updates a slate.
    Args:
        project_id: The GCP project ID.
        location: The location of the slate.
        slate_id: The existing slate's ID.
        slate_uri: Updated uri of the video slate; must be an MP4 video with at least one audio track.

    Returns:
        The slate resource.
    """

    client = VideoStitcherServiceClient()

    name = f"projects/{project_id}/locations/{location}/slates/{slate_id}"
    slate = stitcher_v1.types.Slate(
        name=name,
        uri=slate_uri,
    )
    update_mask = field_mask.FieldMask(paths=["uri"])

    operation = client.update_slate(slate=slate, update_mask=update_mask)
    response = operation.result()
    print(f"Updated slate: {response.name}")
    return response

Ruby

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für Ruby in der Video Stitcher API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Ruby API-Referenzdokumentation zur Video Stitcher API.

Richten Sie für die Authentifizierung bei der Video Stitcher API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

require "google/cloud/video/stitcher"

##
# Update a slate
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param slate_id [String] Your slate name (e.g. "my-slate")
# @param slate_uri [String] The URI of an MP4 video with at least one audio
#   track (e.g. "https://my-slate-uri/test.mp4")
#
def update_slate project_id:, location:, slate_id:, slate_uri:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the slate.
  name = client.slate_path project: project_id, location: location,
                           slate: slate_id

  # Set the update mask.
  update_mask = { paths: ["uri"] }

  # Set the slate fields.
  update_slate = {
    name: name,
    uri: slate_uri
  }

  operation = client.update_slate slate: update_slate, update_mask: update_mask

  # The returned object is of type Gapic::Operation. You can use this
  # object to check the status of an operation, cancel it, or wait
  # for results. Here is how to block until completion:
  operation.wait_until_done!

  # Print the slate name.
  puts "Updated slate: #{operation.response.name}"
  puts "Updated uri: #{operation.response.uri}"
end

Nächste Schritte

Informationen zum Suchen und Filtern von Codebeispielen für andere Google Cloud-Produkte finden Sie im Google Cloud-Beispielbrowser.