Creazione di un canale con uno stream di input di backup

Questa pagina spiega come creare una risorsa di canale con due flussi di input, in cui uno di input può fungere da backup per l'altro.

Quando è abilitato il failover automatico, se il flusso di input principale viene disconnesso a causa di problemi di rete, il canale passa automaticamente a utilizzare il flusso di input di backup come origine di input. Quando lo stream di input principale è di nuovo online, il canale torna automaticamente allo stream di input principale come sorgente di ingresso. La funzionalità di failover automatico è facoltativa.

Devi assicurarti che il flusso di input principale e quello di backup siano identici se vuoi che il flusso di input di backup sostituisca completamente il flusso di input principale.

Puoi anche cambiare manualmente lo stream di input utilizzando un evento di canale.

Crea l'endpoint di input principale

Per creare l'endpoint di input principale, utilizza il metodo projects.locations.inputs.create.

REST

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

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui creare l'endpoint di input; utilizza una delle regioni supportate.
    Mostra località
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • INPUT_ID: un identificatore definito dall'utente per il nuovo endpoint di input da creare (a cui invii il tuo flusso di input). Questo valore deve contenere da 1 a 63 caratteri, iniziare e terminare con [a-z0-9] e può contenere trattini (-) tra i caratteri. Ad esempio: my-input.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}
Questo comando crea un'operazione a lunga esecuzione (LRO) che puoi utilizzare per monitorare l'avanzamento della richiesta. Per saperne di più, consulta Gestire le operazioni a lunga esecuzione .

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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.LiveStream.V1;
using Google.LongRunning;
using System.Threading.Tasks;

public class CreateInputSample
{
    public async Task<Input> CreateInputAsync(
         string projectId, string locationId, string inputId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        CreateInputRequest request = new CreateInputRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, locationId),
            InputId = inputId,
            Input = new Input
            {
                Type = Input.Types.Type.RtmpPush
            }
        };

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

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

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

Go

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

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

import (
	"context"
	"fmt"
	"io"

	livestream "cloud.google.com/go/video/livestream/apiv1"
	"cloud.google.com/go/video/livestream/apiv1/livestreampb"
)

// createInput creates an input endpoint. You send an input video stream to this
// endpoint.
func createInput(w io.Writer, projectID, location, inputID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// inputID := "my-input"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.CreateInputRequest{
		Parent:  fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		InputId: inputID,
		Input: &livestreampb.Input{
			Type: livestreampb.Input_RTMP_PUSH,
		},
	}
	// Creates the input.
	op, err := client.CreateInput(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateInput: %w", err)
	}
	response, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Input: %v", response.Name)
	return nil
}

Java

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

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


import com.google.cloud.video.livestream.v1.CreateInputRequest;
import com.google.cloud.video.livestream.v1.Input;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateInput {

  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 inputId = "my-input-id";

    createInput(projectId, location, inputId);
  }

  public static void createInput(String projectId, String location, String inputId)
      throws InterruptedException, ExecutionException, TimeoutException, 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. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create();
    var createInputRequest =
        CreateInputRequest.newBuilder()
            .setParent(LocationName.of(projectId, location).toString())
            .setInputId(inputId)
            .setInput(Input.newBuilder().setType(Input.Type.RTMP_PUSH).build())
            .build();
    // First API call in a project can take up to 15 minutes.
    Input result =
        livestreamServiceClient.createInputAsync(createInputRequest).get(15, TimeUnit.MINUTES);
    System.out.println("Input: " + result.getName());
    livestreamServiceClient.close();
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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';
// inputId = 'my-input';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function createInput() {
  // Construct request
  const request = {
    parent: livestreamServiceClient.locationPath(projectId, location),
    inputId: inputId,
    input: {
      type: 'RTMP_PUSH',
    },
  };

  // Run request
  const [operation] = await livestreamServiceClient.createInput(request);
  const response = await operation.promise();
  const [input] = response;
  console.log(`Input: ${input.name}`);
}

createInput();

PHP

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

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

use Google\Cloud\Video\LiveStream\V1\Input;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\CreateInputRequest;

/**
 * Creates an input. You send an input video stream to this endpoint.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the input
 * @param string  $inputId            The ID of the input to be created
 */
function create_input(
    string $callingProjectId,
    string $location,
    string $inputId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();

    $parent = $livestreamClient->locationName($callingProjectId, $location);
    $input = (new Input())
        ->setType(Input\Type::RTMP_PUSH);

    // Run the input creation request. The response is a long-running operation ID.
    $request = (new CreateInputRequest())
        ->setParent($parent)
        ->setInput($input)
        ->setInputId($inputId);
    $operationResponse = $livestreamClient->createInput($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // Print results
        printf('Input: %s' . PHP_EOL, $result->getName());
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

Python

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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 live_stream_v1
from google.cloud.video.live_stream_v1.services.livestream_service import (
    LivestreamServiceClient,
)

def create_input(
    project_id: str, location: str, input_id: str
) -> live_stream_v1.types.Input:
    """Creates an input.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the input.
        input_id: The user-defined input ID."""

    client = LivestreamServiceClient()

    parent = f"projects/{project_id}/locations/{location}"

    input = live_stream_v1.types.Input(
        type_="RTMP_PUSH",
    )
    operation = client.create_input(parent=parent, input=input, input_id=input_id)
    response = operation.result(900)
    print(f"Input: {response.name}")

    return response

Ruby

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

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

require "google/cloud/video/live_stream"

##
# Create an input endpoint
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param input_id [String] Your input name (e.g. "my-input")
#
def create_input project_id:, location:, input_id:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the parent.
  parent = client.location_path project: project_id, location: location

  # Set the input fields.
  new_input = {
    type: Google::Cloud::Video::LiveStream::V1::Input::Type::RTMP_PUSH
  }

  operation = client.create_input parent: parent, input: new_input, input_id: input_id

  # 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 input name.
  puts "Input: #{operation.response.name}"
end

Crea l'endpoint di input di backup

Per creare l'endpoint di input di backup, utilizza nuovamente il metodo projects.locations.inputs.create. Assicurati di utilizzare un ID di input diverso dall'endpoint di input principale.

REST

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

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui creare l'endpoint di input; utilizza una delle regioni supportate.
    Mostra località
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • BACKUP_INPUT_ID: identificatore definito dall'utente per la creazione dell'endpoint di input di backup (e da utilizzare se il flusso di input principale è disconnesso a causa di problemi di rete); questo valore deve contenere da 1 a 63 caratteri, iniziare e terminare con [a-z0-9] e può contenere trattini (-) tra i caratteri

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/BACKUP_INPUT_ID",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}
Questo comando crea un'operazione a lunga esecuzione (LRO) che puoi utilizzare per monitorare l'avanzamento della richiesta. Per saperne di più, consulta Gestire le operazioni a lunga esecuzione .

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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.LiveStream.V1;
using Google.LongRunning;
using System.Threading.Tasks;

public class CreateInputSample
{
    public async Task<Input> CreateInputAsync(
         string projectId, string locationId, string inputId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        CreateInputRequest request = new CreateInputRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, locationId),
            InputId = inputId,
            Input = new Input
            {
                Type = Input.Types.Type.RtmpPush
            }
        };

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

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

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

Go

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

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

import (
	"context"
	"fmt"
	"io"

	livestream "cloud.google.com/go/video/livestream/apiv1"
	"cloud.google.com/go/video/livestream/apiv1/livestreampb"
)

// createInput creates an input endpoint. You send an input video stream to this
// endpoint.
func createInput(w io.Writer, projectID, location, inputID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// inputID := "my-input"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.CreateInputRequest{
		Parent:  fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		InputId: inputID,
		Input: &livestreampb.Input{
			Type: livestreampb.Input_RTMP_PUSH,
		},
	}
	// Creates the input.
	op, err := client.CreateInput(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateInput: %w", err)
	}
	response, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Input: %v", response.Name)
	return nil
}

Java

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

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


import com.google.cloud.video.livestream.v1.CreateInputRequest;
import com.google.cloud.video.livestream.v1.Input;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateInput {

  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 inputId = "my-input-id";

    createInput(projectId, location, inputId);
  }

  public static void createInput(String projectId, String location, String inputId)
      throws InterruptedException, ExecutionException, TimeoutException, 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. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create();
    var createInputRequest =
        CreateInputRequest.newBuilder()
            .setParent(LocationName.of(projectId, location).toString())
            .setInputId(inputId)
            .setInput(Input.newBuilder().setType(Input.Type.RTMP_PUSH).build())
            .build();
    // First API call in a project can take up to 15 minutes.
    Input result =
        livestreamServiceClient.createInputAsync(createInputRequest).get(15, TimeUnit.MINUTES);
    System.out.println("Input: " + result.getName());
    livestreamServiceClient.close();
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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';
// inputId = 'my-input';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function createInput() {
  // Construct request
  const request = {
    parent: livestreamServiceClient.locationPath(projectId, location),
    inputId: inputId,
    input: {
      type: 'RTMP_PUSH',
    },
  };

  // Run request
  const [operation] = await livestreamServiceClient.createInput(request);
  const response = await operation.promise();
  const [input] = response;
  console.log(`Input: ${input.name}`);
}

createInput();

PHP

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

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

use Google\Cloud\Video\LiveStream\V1\Input;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\CreateInputRequest;

/**
 * Creates an input. You send an input video stream to this endpoint.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the input
 * @param string  $inputId            The ID of the input to be created
 */
function create_input(
    string $callingProjectId,
    string $location,
    string $inputId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();

    $parent = $livestreamClient->locationName($callingProjectId, $location);
    $input = (new Input())
        ->setType(Input\Type::RTMP_PUSH);

    // Run the input creation request. The response is a long-running operation ID.
    $request = (new CreateInputRequest())
        ->setParent($parent)
        ->setInput($input)
        ->setInputId($inputId);
    $operationResponse = $livestreamClient->createInput($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // Print results
        printf('Input: %s' . PHP_EOL, $result->getName());
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

Python

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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 live_stream_v1
from google.cloud.video.live_stream_v1.services.livestream_service import (
    LivestreamServiceClient,
)

def create_input(
    project_id: str, location: str, input_id: str
) -> live_stream_v1.types.Input:
    """Creates an input.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the input.
        input_id: The user-defined input ID."""

    client = LivestreamServiceClient()

    parent = f"projects/{project_id}/locations/{location}"

    input = live_stream_v1.types.Input(
        type_="RTMP_PUSH",
    )
    operation = client.create_input(parent=parent, input=input, input_id=input_id)
    response = operation.result(900)
    print(f"Input: {response.name}")

    return response

Ruby

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

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

require "google/cloud/video/live_stream"

##
# Create an input endpoint
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param input_id [String] Your input name (e.g. "my-input")
#
def create_input project_id:, location:, input_id:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the parent.
  parent = client.location_path project: project_id, location: location

  # Set the input fields.
  new_input = {
    type: Google::Cloud::Video::LiveStream::V1::Input::Type::RTMP_PUSH
  }

  operation = client.create_input parent: parent, input: new_input, input_id: input_id

  # 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 input name.
  puts "Input: #{operation.response.name}"
end

Creare il canale

Per creare il canale, utilizza il metodo projects.locations.channels.create. Per questo esempio, automaticFailover è configurato per il primo collegamento di input.

REST

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

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui creare il canale; utilizza una delle regioni supportate.
    Mostra località
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • CHANNEL_ID: un identificatore definito dall'utente per il canale da creare. Questo valore deve contenere da 1 a 63 caratteri, iniziare e terminare con [a-z0-9] e può contenere trattini (-) tra i caratteri.
  • INPUT_ID: l'identificatore definito dall'utente per l'endpoint di input principale
  • BACKUP_INPUT_ID: identificatore definito dall'utente per l'endpoint di input di backup
  • BUCKET_NAME: il nome del bucket Cloud Storage che hai creato

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}
Questo comando crea un'operazione a lunga esecuzione (LRO) che puoi utilizzare per monitorare l'avanzamento della richiesta. Per saperne di più, consulta Gestire le operazioni a lunga esecuzione .

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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.LiveStream.V1;
using Google.LongRunning;
using System.Threading.Tasks;

public class CreateChannelWithBackupInputSample
{
    public async Task<Channel> CreateChannelWithBackupInputAsync(
         string projectId, string locationId, string channelId, string primaryInputId, string backupInputId, string outputUri)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        InputAttachment primaryInputAttachment = new InputAttachment
        {
            Key = "my-primary-input",
            InputAsInputName = InputName.FromProjectLocationInput(projectId, locationId, primaryInputId),
            AutomaticFailover = new InputAttachment.Types.AutomaticFailover
            {
                InputKeys = { "my-backup-input" }
            }
        };

        InputAttachment backupInputAttachment = new InputAttachment
        {
            Key = "my-backup-input",
            InputAsInputName = InputName.FromProjectLocationInput(projectId, locationId, backupInputId)
        };

        VideoStream videoStream = new VideoStream
        {
            H264 = new VideoStream.Types.H264CodecSettings
            {
                Profile = "high",
                BitrateBps = 3000000,
                FrameRate = 30,
                HeightPixels = 720,
                WidthPixels = 1280
            }
        };

        ElementaryStream elementaryStreamVideo = new ElementaryStream
        {
            Key = "es_video",
            VideoStream = videoStream
        };

        AudioStream audioStream = new AudioStream
        {
            Codec = "aac",
            ChannelCount = 2,
            BitrateBps = 160000
        };

        ElementaryStream elementaryStreamAudio = new ElementaryStream
        {
            Key = "es_audio",
            AudioStream = audioStream
        };

        MuxStream muxVideo = new MuxStream
        {
            Key = "mux_video",
            ElementaryStreams = { "es_video" },
            SegmentSettings = new SegmentSettings
            {
                SegmentDuration = new Google.Protobuf.WellKnownTypes.Duration
                {
                    Seconds = 2
                }
            }
        };

        MuxStream muxAudio = new MuxStream
        {
            Key = "mux_audio",
            ElementaryStreams = { "es_audio" },
            SegmentSettings = new SegmentSettings
            {
                SegmentDuration = new Google.Protobuf.WellKnownTypes.Duration
                {
                    Seconds = 2
                }
            }
        };

        CreateChannelRequest request = new CreateChannelRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, locationId),
            ChannelId = channelId,
            Channel = new Channel
            {
                InputAttachments = { primaryInputAttachment, backupInputAttachment },
                Output = new Channel.Types.Output
                {
                    Uri = outputUri
                },
                ElementaryStreams = { elementaryStreamVideo, elementaryStreamAudio },
                MuxStreams = { muxVideo, muxAudio },
                Manifests = {
                    new Manifest {
                        FileName = "manifest.m3u8",
                        Type = Manifest.Types.ManifestType.Hls,
                        MuxStreams = { "mux_video", "mux_audio" },
                        MaxSegmentCount = 5
                    }
                }
            }
        };

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

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

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

Go

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

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

import (
	"context"
	"fmt"
	"io"

	"github.com/golang/protobuf/ptypes/duration"

	livestream "cloud.google.com/go/video/livestream/apiv1"
	"cloud.google.com/go/video/livestream/apiv1/livestreampb"
)

// createChannelWithBackupInput creates a channel with a failover backup input.
func createChannelWithBackupInput(w io.Writer, projectID, location, channelID, primaryInputID, backupInputID, outputURI string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// channelID := "my-channel"
	// primaryInputID := "my-primary-input"
	// backupInputID := "my-backup-input"
	// outputURI := "gs://my-bucket/my-output-folder/"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	primaryInput := fmt.Sprintf("projects/%s/locations/%s/inputs/%s", projectID, location, primaryInputID)
	backupInput := fmt.Sprintf("projects/%s/locations/%s/inputs/%s", projectID, location, backupInputID)
	automaticFailover := &livestreampb.InputAttachment_AutomaticFailover{
		InputKeys: []string{"my-backup-input"},
	}

	req := &livestreampb.CreateChannelRequest{
		Parent:    fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		ChannelId: channelID,
		Channel: &livestreampb.Channel{
			InputAttachments: []*livestreampb.InputAttachment{
				{
					Key:               "my-primary-input",
					Input:             primaryInput,
					AutomaticFailover: automaticFailover,
				},
				{
					Key:   "my-backup-input",
					Input: backupInput,
				},
			},
			Output: &livestreampb.Channel_Output{
				Uri: outputURI,
			},
			ElementaryStreams: []*livestreampb.ElementaryStream{
				{
					Key: "es_video",
					ElementaryStream: &livestreampb.ElementaryStream_VideoStream{
						VideoStream: &livestreampb.VideoStream{
							CodecSettings: &livestreampb.VideoStream_H264{
								H264: &livestreampb.VideoStream_H264CodecSettings{
									Profile:      "high",
									BitrateBps:   3000000,
									FrameRate:    30,
									HeightPixels: 720,
									WidthPixels:  1280,
								},
							},
						},
					},
				},
				{
					Key: "es_audio",
					ElementaryStream: &livestreampb.ElementaryStream_AudioStream{
						AudioStream: &livestreampb.AudioStream{
							Codec:        "aac",
							ChannelCount: 2,
							BitrateBps:   160000,
						},
					},
				},
			},
			MuxStreams: []*livestreampb.MuxStream{
				{
					Key:               "mux_video",
					ElementaryStreams: []string{"es_video"},
					SegmentSettings: &livestreampb.SegmentSettings{
						SegmentDuration: &duration.Duration{
							Seconds: 2,
						},
					},
				},
				{
					Key:               "mux_audio",
					ElementaryStreams: []string{"es_audio"},
					SegmentSettings: &livestreampb.SegmentSettings{
						SegmentDuration: &duration.Duration{
							Seconds: 2,
						},
					},
				},
			},
			Manifests: []*livestreampb.Manifest{
				{
					FileName:        "manifest.m3u8",
					Type:            livestreampb.Manifest_HLS,
					MuxStreams:      []string{"mux_video", "mux_audio"},
					MaxSegmentCount: 5,
				},
			},
		},
	}
	// Creates the channel.
	op, err := client.CreateChannel(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateChannel: %w", err)
	}
	response, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Channel: %v", response.Name)
	return nil
}

Java

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

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


import com.google.cloud.video.livestream.v1.AudioStream;
import com.google.cloud.video.livestream.v1.Channel;
import com.google.cloud.video.livestream.v1.Channel.Output;
import com.google.cloud.video.livestream.v1.CreateChannelRequest;
import com.google.cloud.video.livestream.v1.ElementaryStream;
import com.google.cloud.video.livestream.v1.InputAttachment;
import com.google.cloud.video.livestream.v1.InputAttachment.AutomaticFailover;
import com.google.cloud.video.livestream.v1.InputName;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import com.google.cloud.video.livestream.v1.Manifest;
import com.google.cloud.video.livestream.v1.Manifest.ManifestType;
import com.google.cloud.video.livestream.v1.MuxStream;
import com.google.cloud.video.livestream.v1.SegmentSettings;
import com.google.cloud.video.livestream.v1.VideoStream;
import com.google.cloud.video.livestream.v1.VideoStream.H264CodecSettings;
import com.google.protobuf.Duration;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateChannelWithBackupInput {

  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 channelId = "my-channel-id";
    String primaryInputId = "my-primary-input-id";
    String backupInputId = "my-backup-input-id";
    String outputUri = "gs://my-bucket/my-output-folder/";

    createChannelWithBackupInput(
        projectId, location, channelId, primaryInputId, backupInputId, outputUri);
  }

  public static void createChannelWithBackupInput(
      String projectId,
      String location,
      String channelId,
      String primaryInputId,
      String backupInputId,
      String outputUri)
      throws InterruptedException, ExecutionException, TimeoutException, 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. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create();
    VideoStream videoStream =
        VideoStream.newBuilder()
            .setH264(
                H264CodecSettings.newBuilder()
                    .setProfile("high")
                    .setBitrateBps(3000000)
                    .setFrameRate(30)
                    .setHeightPixels(720)
                    .setWidthPixels(1280))
            .build();

    AudioStream audioStream =
        AudioStream.newBuilder().setCodec("aac").setChannelCount(2).setBitrateBps(160000).build();

    var createChannelRequest =
        CreateChannelRequest.newBuilder()
            .setParent(LocationName.of(projectId, location).toString())
            .setChannelId(channelId)
            .setChannel(
                Channel.newBuilder()
                    .addInputAttachments(
                        0,
                        InputAttachment.newBuilder()
                            .setKey("my-primary-input")
                            .setInput(
                                InputName.of(projectId, location, primaryInputId).toString())
                            .setAutomaticFailover(
                                AutomaticFailover.newBuilder()
                                    .addInputKeys("my-backup-input")
                                    .build())
                            .build())
                    .addInputAttachments(
                        1,
                        InputAttachment.newBuilder()
                            .setKey("my-backup-input")
                            .setInput(
                                InputName.of(projectId, location, backupInputId).toString()))
                    .setOutput(Output.newBuilder().setUri(outputUri).build())
                    .addElementaryStreams(
                        ElementaryStream.newBuilder()
                            .setKey("es_video")
                            .setVideoStream(videoStream))
                    .addElementaryStreams(
                        ElementaryStream.newBuilder()
                            .setKey("es_audio")
                            .setAudioStream(audioStream))
                    .addMuxStreams(
                        MuxStream.newBuilder()
                            .setKey("mux_video")
                            .addElementaryStreams("es_video")
                            .setSegmentSettings(
                                SegmentSettings.newBuilder()
                                    .setSegmentDuration(
                                        Duration.newBuilder().setSeconds(2).build())
                                    .build())
                            .build())
                    .addMuxStreams(
                        MuxStream.newBuilder()
                            .setKey("mux_audio")
                            .addElementaryStreams("es_audio")
                            .setSegmentSettings(
                                SegmentSettings.newBuilder()
                                    .setSegmentDuration(
                                        Duration.newBuilder().setSeconds(2).build())
                                    .build())
                            .build())
                    .addManifests(
                        Manifest.newBuilder()
                            .setFileName("manifest.m3u8")
                            .setType(ManifestType.HLS)
                            .addMuxStreams("mux_video")
                            .addMuxStreams("mux_audio")
                            .setMaxSegmentCount(5)
                            .build()))
            .build();
    // First API call in a project can take up to 10 minutes.
    Channel result =
        livestreamServiceClient
            .createChannelAsync(createChannelRequest)
            .get(10, TimeUnit.MINUTES);
    System.out.println("Channel: " + result.getName());
    livestreamServiceClient.close();
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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';
// channelId = 'my-channel';
// primaryInputId = 'my-primary-input';
// backupInputId = 'my-backup-input';
// outputUri = 'gs://my-bucket/my-output-folder/';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function createChannelWithBackupInput() {
  // Construct request
  const request = {
    parent: livestreamServiceClient.locationPath(projectId, location),
    channelId: channelId,
    channel: {
      inputAttachments: [
        {
          key: 'my-primary-input',
          input: livestreamServiceClient.inputPath(
            projectId,
            location,
            primaryInputId
          ),
          automaticFailover: {
            inputKeys: ['my-backup-input'],
          },
        },
        {
          key: 'my-backup-input',
          input: livestreamServiceClient.inputPath(
            projectId,
            location,
            backupInputId
          ),
        },
      ],
      output: {
        uri: outputUri,
      },
      elementaryStreams: [
        {
          key: 'es_video',
          videoStream: {
            h264: {
              profile: 'high',
              heightPixels: 720,
              widthPixels: 1280,
              bitrateBps: 3000000,
              frameRate: 30,
            },
          },
        },
        {
          key: 'es_audio',
          audioStream: {
            codec: 'aac',
            channelCount: 2,
            bitrateBps: 160000,
          },
        },
      ],
      muxStreams: [
        {
          key: 'mux_video',
          elementaryStreams: ['es_video'],
          segmentSettings: {
            seconds: 2,
          },
        },
        {
          key: 'mux_audio',
          elementaryStreams: ['es_audio'],
          segmentSettings: {
            seconds: 2,
          },
        },
      ],
      manifests: [
        {
          fileName: 'manifest.m3u8',
          type: 'HLS',
          muxStreams: ['mux_video', 'mux_audio'],
          maxSegmentCount: 5,
        },
      ],
    },
  };

  // Run request
  const [operation] = await livestreamServiceClient.createChannel(request);
  const response = await operation.promise();
  const [channel] = response;
  console.log(`Channel: ${channel.name}`);
}

createChannelWithBackupInput();

PHP

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

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

use Google\Cloud\Video\LiveStream\V1\AudioStream;
use Google\Cloud\Video\LiveStream\V1\Channel;
use Google\Cloud\Video\LiveStream\V1\ElementaryStream;
use Google\Cloud\Video\LiveStream\V1\InputAttachment;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\CreateChannelRequest;
use Google\Cloud\Video\LiveStream\V1\Manifest;
use Google\Cloud\Video\LiveStream\V1\MuxStream;
use Google\Cloud\Video\LiveStream\V1\SegmentSettings;
use Google\Cloud\Video\LiveStream\V1\VideoStream;
use Google\Protobuf\Duration;

/**
 * Creates a channel with a backup input.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the channel
 * @param string  $channelId          The ID of the channel to be created
 * @param string  $primaryInputId     The ID of the primary input for the channel
 * @param string  $backupInputId      The ID of the backup input for the channel
 * @param string  $outputUri          Uri of the channel output folder in a
 *                                    Cloud Storage bucket. (e.g.
 *                                    "gs://my-bucket/my-output-folder/")
 */
function create_channel_with_backup_input(
    string $callingProjectId,
    string $location,
    string $channelId,
    string $primaryInputId,
    string $backupInputId,
    string $outputUri
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();

    $parent = $livestreamClient->locationName($callingProjectId, $location);
    $channelName = $livestreamClient->channelName($callingProjectId, $location, $channelId);
    $primaryInputName = $livestreamClient->inputName($callingProjectId, $location, $primaryInputId);
    $backupInputName = $livestreamClient->inputName($callingProjectId, $location, $backupInputId);

    $channel = (new Channel())
        ->setName($channelName)
        ->setInputAttachments([
            new InputAttachment([
                'key' => 'my-primary-input',
                'input' => $primaryInputName,
                'automatic_failover' => new InputAttachment\AutomaticFailover([
                    'input_keys' => ['my-backup-input']
                ])
            ]),
            new InputAttachment([
                'key' => 'my-backup-input',
                'input' => $backupInputName
            ])
        ])
        ->setElementaryStreams([
            new ElementaryStream([
                'key' => 'es_video',
                'video_stream' => new VideoStream([
                    'h264' => new VideoStream\H264CodecSettings([
                        'profile' => 'high',
                        'width_pixels' => 1280,
                        'height_pixels' => 720,
                        'bitrate_bps' => 3000000,
                        'frame_rate' => 30
                    ])
                ]),
            ]),
            new ElementaryStream([
                'key' => 'es_audio',
                'audio_stream' => new AudioStream([
                    'codec' => 'aac',
                    'channel_count' => 2,
                    'bitrate_bps' => 160000
                ])
            ])
        ])
        ->setOutput(new Channel\Output(['uri' => $outputUri]))
        ->setMuxStreams([
            new MuxStream([
                'key' => 'mux_video',
                'elementary_streams' => ['es_video'],
                'segment_settings' => new SegmentSettings([
                    'segment_duration' => new Duration(['seconds' => 2])
                ])
            ]),
            new MuxStream([
                'key' => 'mux_audio',
                'elementary_streams' => ['es_audio'],
                'segment_settings' => new SegmentSettings([
                    'segment_duration' => new Duration(['seconds' => 2])
                ])
            ]),
        ])
        ->setManifests([
            new Manifest([
                'file_name' => 'manifest.m3u8',
                'type' => Manifest\ManifestType::HLS,
                'mux_streams' => ['mux_video', 'mux_audio'],
                'max_segment_count' => 5
            ])
        ]);

    // Run the channel creation request. The response is a long-running operation ID.
    $request = (new CreateChannelRequest())
        ->setParent($parent)
        ->setChannel($channel)
        ->setChannelId($channelId);
    $operationResponse = $livestreamClient->createChannel($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // Print results
        printf('Channel: %s' . PHP_EOL, $result->getName());
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

Python

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, 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 live_stream_v1
from google.cloud.video.live_stream_v1.services.livestream_service import (
    LivestreamServiceClient,
)
from google.protobuf import duration_pb2 as duration

def create_channel_with_backup_input(
    project_id: str,
    location: str,
    channel_id: str,
    primary_input_id: str,
    backup_input_id: str,
    output_uri: str,
) -> live_stream_v1.types.Channel:
    """Creates a channel.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the channel.
        channel_id: The user-defined channel ID.
        primary_input_id: The user-defined primary input ID.
        backup_input_id: The user-defined backup input ID.
        output_uri: Uri of the channel output folder in a Cloud Storage bucket."""

    client = LivestreamServiceClient()
    parent = f"projects/{project_id}/locations/{location}"
    primary_input = (
        f"projects/{project_id}/locations/{location}/inputs/{primary_input_id}"
    )
    backup_input = (
        f"projects/{project_id}/locations/{location}/inputs/{backup_input_id}"
    )
    name = f"projects/{project_id}/locations/{location}/channels/{channel_id}"

    channel = live_stream_v1.types.Channel(
        name=name,
        input_attachments=[
            live_stream_v1.types.InputAttachment(
                key="my-primary-input",
                input=primary_input,
                automatic_failover=live_stream_v1.types.InputAttachment.AutomaticFailover(
                    input_keys=["my-backup-input"],
                ),
            ),
            live_stream_v1.types.InputAttachment(
                key="my-backup-input",
                input=backup_input,
            ),
        ],
        output=live_stream_v1.types.Channel.Output(
            uri=output_uri,
        ),
        elementary_streams=[
            live_stream_v1.types.ElementaryStream(
                key="es_video",
                video_stream=live_stream_v1.types.VideoStream(
                    h264=live_stream_v1.types.VideoStream.H264CodecSettings(
                        profile="high",
                        width_pixels=1280,
                        height_pixels=720,
                        bitrate_bps=3000000,
                        frame_rate=30,
                    ),
                ),
            ),
            live_stream_v1.types.ElementaryStream(
                key="es_audio",
                audio_stream=live_stream_v1.types.AudioStream(
                    codec="aac", channel_count=2, bitrate_bps=160000
                ),
            ),
        ],
        mux_streams=[
            live_stream_v1.types.MuxStream(
                key="mux_video",
                elementary_streams=["es_video"],
                segment_settings=live_stream_v1.types.SegmentSettings(
                    segment_duration=duration.Duration(
                        seconds=2,
                    ),
                ),
            ),
            live_stream_v1.types.MuxStream(
                key="mux_audio",
                elementary_streams=["es_audio"],
                segment_settings=live_stream_v1.types.SegmentSettings(
                    segment_duration=duration.Duration(
                        seconds=2,
                    ),
                ),
            ),
        ],
        manifests=[
            live_stream_v1.types.Manifest(
                file_name="manifest.m3u8",
                type_="HLS",
                mux_streams=["mux_video", "mux_audio"],
                max_segment_count=5,
            ),
        ],
    )
    operation = client.create_channel(
        parent=parent, channel=channel, channel_id=channel_id
    )
    response = operation.result(600)
    print(f"Channel: {response.name}")

    return response

Ruby

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

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

require "google/cloud/video/live_stream"

##
# Create a channel with a failover backup input
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param channel_id [String] Your channel name (e.g. "my-channel")
# @param primary_input_id [String] Your primary input name (e.g. "my-primary-input")
# @param backup_input_id [String] Your backup input name (e.g. "my-backup-input")
# @param output_uri [String] Uri of the channel output folder in a Cloud Storage
#     bucket. (e.g. "gs://my-bucket/my-output-folder/";)
#
def create_channel_with_backup_input project_id:, location:, channel_id:, primary_input_id:, backup_input_id:, output_uri:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the parent.
  parent = client.location_path project: project_id, location: location
  # Build the resource name of the inputs.
  primary_input_path = client.input_path project: project_id, location: location, input: primary_input_id
  backup_input_path = client.input_path project: project_id, location: location, input: backup_input_id

  # Set the channel fields.
  new_channel = {
    input_attachments: [
      {
        key: "my-primary-input",
        input: primary_input_path,
        automatic_failover: {
          input_keys: ["my-backup-input"]
        }
      },
      {
        key: "my-backup-input",
        input: backup_input_path
      }
    ],
    output: {
      uri: output_uri
    },
    elementary_streams: [
      {
        key: "es_video",
        video_stream: {
          h264: {
            profile: "high",
            bitrate_bps: 3_000_000,
            frame_rate: 30,
            height_pixels: 720,
            width_pixels: 1280
          }
        }
      },
      {
        key: "es_audio",
        audio_stream: {
          codec: "aac",
          channel_count: 2,
          bitrate_bps: 160_000
        }
      }
    ],
    mux_streams: [
      {
        key: "mux_video",
        elementary_streams: [
          "es_video"
        ],
        segment_settings: {
          segment_duration: {
            seconds: 2
          }
        }
      },
      {
        key: "mux_audio",
        elementary_streams: [
          "es_audio"
        ],
        segment_settings: {
          segment_duration: {
            seconds: 2
          }
        }
      }
    ],
    manifests: [
      {
        file_name: "main.m3u8",
        type: Google::Cloud::Video::LiveStream::V1::Manifest::ManifestType::HLS,
        mux_streams: [
          "mux_video", "mux_audio"
        ],
        max_segment_count: 5
      }
    ]
  }

  operation = client.create_channel parent: parent, channel: new_channel, channel_id: channel_id

  # 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 channel name.
  puts "Channel: #{operation.response.name}"
end

Cambiare manualmente l'input

Per cambiare manualmente l'ingresso dall'ingresso principale a quello di backup (ad esempio, da my-primary-input a my-backup-input), crea un evento di canale.

Dopo il passaggio manuale, puoi scollegare e ricollegare my-primary-input come preferisci. Il canale non passa a questo input al momento della riconnessione, come farebbe con le impostazioni predefinite di failover automatico.

Per tornare a my-primary-input, esegui una delle seguenti operazioni:

  • Crea un nuovo evento inputSwitch in cui inputKey è impostato su my-primary-input. Questo evento torna all'input principale senza ripristinare le impostazioni di failover automatico.
  • Aggiorna il canale per abilitare il failover automatico. Per ulteriori informazioni, consulta la sezione Evento Cambia input.