Gestire una sessione VOD abilitata da Google Ad Manager

Utilizzando l'API Video Stitcher, crei una sessione video on demand (VOD) ogni volta che inserisci dinamicamente gli annunci pubblicati da Google Ad Manager prima della pubblicazione sui dispositivi client. Quando crei una sessione, la risposta include l'URL di riproduzione e le informazioni sugli annunci che hai inserito nel video.

Questa pagina descrive come creare e gestire una sessione VOD abilitata da Google Ad Manager. Per informazioni sulle sessioni VOD che non utilizzano Google Ad Manager, consulta Gestire una sessione VOD.

Prima di iniziare

Creare una sessione

Puoi creare una sessione VOD utilizzando l'SDK IMA (che chiama l'API Video Stitcher) o utilizzando direttamente l'API Video Stitcher.

Utilizzare l'SDK IMA

Se esegui l'integrazione con l'SDK IMA, quest'ultimo crea la sessione VOD.

function requestVodVideoStitcherStream() {
  const streamRequest = new google.ima.dai.api.VideoStitcherVodStreamRequest();
  streamRequest.vodConfigId = 'VOD_CONFIG_ID';
  streamRequest.region = 'LOCATION';
  streamRequest.projectNumber = 'PROJECT_NUMBER';
  streamRequest.oAuthToken = 'OAUTH_TOKEN';
  streamRequest.networkCode = 'NETWORK_CODE';

  streamManager.requestStream(streamRequest);
}

Le sessioni VOD abilitate da Google Ad Manager devono utilizzare il monitoraggio degli annunci lato client.

Puoi impostare o eseguire l'override dei seguenti parametri facoltativi per sessione:

Consulta la sezione successiva per scoprire come impostare questi parametri utilizzando l'SDK IMA.

Parametri e override facoltativi

function requestVodVideoStitcherStream() {
  const streamRequest = new google.ima.dai.api.VideoStitcherVodStreamRequest();
  streamRequest.vodConfigId = 'VOD_CONFIG_ID';
  streamRequest.region = 'LOCATION';
  streamRequest.projectNumber = 'PROJECT_NUMBER';
  streamRequest.oAuthToken = 'OAUTH_TOKEN';
  streamRequest.networkCode = 'NETWORK_CODE';
  streamRequest.videoStitcherSessionOptions = {
    manifestOptions: {
      "includeRenditions": [
        {
          "bitrateBps": 150000,
          "codecs": "hvc1.1.4.L126.B0"
        },
        {
          "bitrateBps": 440000,
          "codecs": "hvc1.1.4.L126.B0"
        },
      ],
      "bitrateOrder": "descending",
    },
  };
  streamRequest.adTagParameters = {
    "key1": "value1",
    "key2": "value2",
  };

  streamManager.requestStream(streamRequest);
}

Utilizzare direttamente l'API

Per creare una sessione per un video con annunci cuciti, utilizza il metodo projects.locations.vodSessions.create.

REST

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

  • PROJECT_NUMBER: il numero di Google Cloud progetto che si trova nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui creare la sessione; utilizza una delle regioni supportate
    Mostra località
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • VOD_CONFIG_ID: l'identificatore definito dall'utente per la configurazione VOD

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID",
  "interstitials": {
    "sessionContent": {
      "duration": "60s"
    }
  },
  "playUri": "PLAY_URI", # This is the ad-stitched VOD URI
  "sourceUri": "VOD_URI",
  "adTagUri": "AD_TAG_URI",
  "assetId": "ASSET_ID",
  "adTracking": "SERVER",
  "vodConfig": "projects/PROJECT_NUMBER/locations/LOCATION/vodConfigs/VOD_CONFIG_ID"
}

C#

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


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

public class CreateVodSessionSample
{
    public VodSession CreateVodSession(
        string projectId, string location, string vodConfigId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        CreateVodSessionRequest request = new CreateVodSessionRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, location),
            VodSession = new VodSession
            {
                VodConfig = VodConfigName.FormatProjectLocationVodConfig(projectId, location, vodConfigId),
                AdTracking = AdTracking.Server
            }
        };

        // Call the API.
        VodSession session = client.CreateVodSession(request);

        // Return the result.
        return session;
    }
}

Go

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

import (
	"context"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	stitcherstreampb "cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
)

// createVodSession creates a video on demand (VOD) session in which to insert ads.
// VOD sessions are ephemeral resources that expire after a few hours.
func createVodSession(w io.Writer, projectID, vodConfigID string) error {
	// projectID := "my-project-id"
	// vodConfigID := "my-vod-config-id"
	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.CreateVodSessionRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		VodSession: &stitcherstreampb.VodSession{
			VodConfig:  fmt.Sprintf("projects/%s/locations/%s/vodConfigs/%s", projectID, location, vodConfigID),
			AdTracking: stitcherstreampb.AdTracking_SERVER,
		},
	}
	// Creates the VOD session.
	response, err := client.CreateVodSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.CreateVodSession: %w", err)
	}

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

Java

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


import com.google.cloud.video.stitcher.v1.AdTracking;
import com.google.cloud.video.stitcher.v1.CreateVodSessionRequest;
import com.google.cloud.video.stitcher.v1.LocationName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodConfigName;
import com.google.cloud.video.stitcher.v1.VodSession;
import java.io.IOException;

public class CreateVodSession {

  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 vodConfigId = "my-vod-config-id";

    createVodSession(projectId, location, vodConfigId);
  }

  // Creates a video on demand (VOD) session using the parameters in the designated VOD config.
  // For more information, see
  // https://cloud.google.com/video-stitcher/docs/how-to/creating-vod-sessions.
  public static VodSession createVodSession(String projectId, String location, String vodConfigId)
      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 (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      CreateVodSessionRequest createVodSessionRequest =
          CreateVodSessionRequest.newBuilder()
              .setParent(LocationName.of(projectId, location).toString())
              .setVodSession(
                  VodSession.newBuilder()
                      .setVodConfig(VodConfigName.format(projectId, location, vodConfigId))
                      .setAdTracking(AdTracking.SERVER)
                      .build())
              .build();

      VodSession response = videoStitcherServiceClient.createVodSession(createVodSessionRequest);
      System.out.println("Created VOD session: " + response.getName());
      return response;
    }
  }
}

Node.js

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// vodConfigId = 'my-vod-config-id';

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

async function createVodSession() {
  // Construct request
  const request = {
    parent: stitcherClient.locationPath(projectId, location),
    vodSession: {
      vodConfig: stitcherClient.vodConfigPath(
        projectId,
        location,
        vodConfigId
      ),
      adTracking: 'SERVER',
    },
  };
  const [session] = await stitcherClient.createVodSession(request);
  console.log(`VOD session: ${session.name}`);
}

createVodSession().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

use Google\Cloud\Video\Stitcher\V1\AdTracking;
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\CreateVodSessionRequest;
use Google\Cloud\Video\Stitcher\V1\VodSession;

/**
 * Creates a VOD session. VOD sessions are ephemeral resources that expire
 * after a few hours.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $vodConfigId          The name of the VOD config to use for the session
 */
function create_vod_session(
    string $callingProjectId,
    string $location,
    string $vodConfigId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $parent = $stitcherClient->locationName($callingProjectId, $location);
    $vodConfig = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
    $vodSession = new VodSession();
    $vodSession->setVodConfig($vodConfig);
    $vodSession->setAdTracking(AdTracking::SERVER);

    // Run VOD session creation request
    $request = (new CreateVodSessionRequest())
        ->setParent($parent)
        ->setVodSession($vodSession);
    $response = $stitcherClient->createVodSession($request);

    // Print results
    printf('VOD session: %s' . PHP_EOL, $response->getName());
}

Python

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    VideoStitcherServiceClient,
)


def create_vod_session(
    project_id: str, location: str, vod_config_id: str
) -> stitcher_v1.types.VodSession:
    """Creates a VOD session. VOD sessions are ephemeral resources that expire
    after a few hours.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the session.
        vod_config_id: The user-defined VOD config ID to use to create the
                        session.

    Returns:
        The VOD session resource.
    """

    client = VideoStitcherServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    vod_config_name = (
        f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
    )

    vod_session = stitcher_v1.types.VodSession(
        vod_config=vod_config_name, ad_tracking="SERVER"
    )

    response = client.create_vod_session(parent=parent, vod_session=vod_session)
    print(f"VOD session: {response.name}")
    return response

Ruby

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

require "google/cloud/video/stitcher"

##
# Create a video on demand (VOD) session. VOD sessions are ephemeral resources
# that expire after a few hours.
#
# @param project_id [String] Your Google Cloud project (e.g. `my-project`)
# @param location [String] The location (e.g. `us-central1`)
# @param vod_config_id [String] The VOD config ID (e.g. `my-vod-config`) to use
#
def create_vod_session project_id:, location:, vod_config_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

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

  # Build the resource name of the VOD config.
  vod_config_name = client.vod_config_path project: project_id,
                                           location: location,
                                           vod_config: vod_config_id

  # Set the session fields.
  new_vod_session = {
    vod_config: vod_config_name,
    ad_tracking: Google::Cloud::Video::Stitcher::V1::AdTracking::SERVER
  }

  response = client.create_vod_session parent: parent,
                                       vod_session: new_vod_session

  # Print the VOD session name.
  puts "VOD session: #{response.name}"
end

L'API Video Stitcher genera un ID sessione univoco per ogni richiesta. Una sessione scade dopo 4 ore.

La risposta ora dovrebbe essere simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID",
  "interstitials": {
    "adBreaks": [
      {
        "progressEvents": [
          {
            "timeOffset": "0s",
            "events": [
              {
                "type": "IMPRESSION",
                "uri": "https://securepubads.g.doubleclick.net/pcs/view..."
              },
              {
                "type": "START",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              ...
            ]
          },
          ...
        ],
        "ads": [
          {
            "duration": "10s",
            "activityEvents": [
              {
                "type": "ERROR",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              {
                "type": "CLICK_THROUGH",
                "uri": "https://pubads.g.doubleclick.net/pcs/click...",
                "id": "GDFP"
              },
              ...
            ]
          }
        ],
        "endTimeOffset": "10s",
        "startTimeOffset": "0s"
      }
    ],
    "sessionContent": {
      "duration": "70s"
    }
  },
  "playUri": "PLAY_URI",
  "sourceUri": "VOD_URI",
  "adTagUri": "AD_TAG_URI",
  "assetId": "ASSET_ID",
  "adTracking": "SERVER",
  "vodConfig": "projects/PROJECT_NUMBER/locations/LOCATION/vodConfigs/VOD_CONFIG_ID"
}

La risposta è un oggetto VodSession che contiene i seguenti campi:

  • Un campo name che mostra il VOD SESSION_ID. Utilizza questo ID per recuperare la sessione.
  • Un campo interstitials che contiene i metadati relativi agli annunci inseriti (vedi i concetti relativi ai metadati degli annunci).
  • Un campo playUri che mostra l'URL utilizzato dal dispositivo client per riprodurre l'asset video condizionato.

Se generi una sessione per conto dei dispositivi dei tuoi clienti, imposta i seguenti parametri utilizzando le intestazioni HTTP:

Parametro Intestazione HTTP
CLIENT_IP x-user-ip
REFERRER_URL referer
USER_AGENT user-agent

Puoi aggiungere le seguenti intestazioni alla richiesta curl precedente:

-H "x-user-ip: CLIENT_IP" \
-H "referer: REFERRER_URL" \
-H "user-agent: USER_AGENT" \

Recuperare una sessione

Per ottenere la sessione per un video con annunci integrati, utilizza il metodo projects.locations.vodSessions.get.

REST

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

  • PROJECT_NUMBER: il numero di Google Cloud progetto che si trova nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località della sessione; utilizza una delle regioni supportate
    Mostra località
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID: l'identificatore della sessione VOD

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID",
  "interstitials": {
    "adBreaks": [
      {
        "progressEvents": [
          {
            "timeOffset": "0s",
            "events": [
              {
                "type": "IMPRESSION",
                "uri": "https://securepubads.g.doubleclick.net/pcs/view..."
              },
              {
                "type": "START",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              ...
            ]
          },
          ...
        ],
        "ads": [
          {
            "duration": "10s",
            "activityEvents": [
              {
                "type": "ERROR",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              {
                "type": "CLICK_THROUGH",
                "uri": "https://pubads.g.doubleclick.net/pcs/click...",
                "id": "GDFP"
              },
              ...
            ]
          }
        ],
        "endTimeOffset": "10s",
        "startTimeOffset": "0s"
      }
    ],
    "sessionContent": {
      "duration": "70s"
    }
  },
  "playUri": "PLAY_URI",
  "sourceUri": "VOD_URI",
  "adTagUri": "AD_TAG_URI",
  "assetId": "ASSET_ID",
  "adTracking": "SERVER",
  "vodConfig": "projects/PROJECT_NUMBER/locations/LOCATION/vodConfigs/VOD_CONFIG_ID"
}

C#

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


using Google.Cloud.Video.Stitcher.V1;

public class GetVodSessionSample
{
    public VodSession GetVodSession(
        string projectId, string location, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetVodSessionRequest request = new GetVodSessionRequest
        {
            VodSessionName = VodSessionName.FromProjectLocationVodSession(projectId, location, sessionId)
        };

        // Call the API.
        VodSession session = client.GetVodSession(request);

        // Return the result.
        return session;
    }
}

Go

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

import (
	"context"
	"encoding/json"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	stitcherstreampb "cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
)

// getVodSession gets a VOD session by ID.
func getVodSession(w io.Writer, projectID, sessionID string) error {
	// projectID := "my-project-id"
	// sessionID := "123-456-789"
	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.GetVodSessionRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/vodSessions/%s", projectID, location, sessionID),
	}
	// Gets the session.
	response, err := client.GetVodSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetVodSession: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}

	fmt.Fprintf(w, "VOD session:\n%s", string(b))
	return nil
}

Java

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


import com.google.cloud.video.stitcher.v1.GetVodSessionRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodSession;
import com.google.cloud.video.stitcher.v1.VodSessionName;
import java.io.IOException;

public class GetVodSession {

  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 sessionId = "my-session-id";

    getVodSession(projectId, location, sessionId);
  }

  // Gets a video on demand (VOD) session.
  public static VodSession getVodSession(String projectId, String location, String sessionId)
      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 (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      GetVodSessionRequest getVodSessionRequest =
          GetVodSessionRequest.newBuilder()
              .setName(VodSessionName.of(projectId, location, sessionId).toString())
              .build();

      VodSession response = videoStitcherServiceClient.getVodSession(getVodSessionRequest);
      System.out.println("VOD session: " + response.getName());
      return response;
    }
  }
}

Node.js

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// sessionId = 'my-session-id';

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

async function getVodSession() {
  // Construct request
  const request = {
    name: stitcherClient.vodSessionPath(projectId, location, sessionId),
  };
  const [session] = await stitcherClient.getVodSession(request);
  console.log(`VOD session: ${session.name}`);
}

getVodSession().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\GetVodSessionRequest;

/**
 * Gets a VOD session.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $sessionId            The ID of the session
 */
function get_vod_session(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodSessionName($callingProjectId, $location, $sessionId);
    $request = (new GetVodSessionRequest())
        ->setName($formattedName);
    $session = $stitcherClient->getVodSession($request);

    // Print results
    printf('VOD session: %s' . PHP_EOL, $session->getName());
}

Python

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    VideoStitcherServiceClient,
)


def get_vod_session(
    project_id: str, location: str, session_id: str
) -> stitcher_v1.types.VodSession:
    """Gets a VOD session. VOD sessions are ephemeral resources that expire
    after a few hours.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the VOD session.

    Returns:
        The VOD session resource.
    """

    client = VideoStitcherServiceClient()

    name = client.vod_session_path(project_id, location, session_id)
    response = client.get_vod_session(name=name)
    print(f"VOD session: {response.name}")
    return response

Ruby

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

Per autenticarti all'API Video Stitcher, configura le Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

require "google/cloud/video/stitcher"

##
# Get a VOD session. VOD sessions are ephemeral resources that expire
# after a few hours.
#
# @param project_id [String] Your Google Cloud project (e.g. `my-project`)
# @param location [String] The location (e.g. `us-central1`)
# @param session_id [String] The VOD session ID (e.g. `my-vod-session-id`)
#
def get_vod_session project_id:, location:, session_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the VOD session.
  name = client.vod_session_path project: project_id, location: location,
                                 vod_session: session_id

  # Get the VOD session.
  session = client.get_vod_session name: name

  # Print the VOD session name.
  puts "VOD session: #{session.name}"
end

Esempio di playlist con annunci integrati

Di seguito è riportato un esempio di playlist VOD di origine prima dell'inserimento degli annunci:

#EXTM3U
#EXT-X-TARGETDURATION:6
#EXT-X-VERSION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:6.000,
segment_01.ts
#EXTINF:6.000,
segment_02.ts
#EXTINF:6.000,
segment_03.ts
#EXTINF:6.000,
segment_04.ts
#EXTINF:6.000,
segment_05.ts
#EXTINF:6.000,
segment_06.ts
#EXT-X-ENDLIST

Di seguito è riportato un esempio di playlist VOD di origine dopo l'inserimento di annunci pre-roll, mid-roll e post-roll:

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:6
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
https://redirector.googlevideo.com/videoplayback/...
#EXTINF:4.000,
https://redirector.googlevideo.com/videoplayback/...
#EXTINF:1.990,
https://redirector.googlevideo.com/videoplayback/...
#EXT-X-DISCONTINUITY
#EXTINF:6.000,
segment_01.ts
#EXTINF:6.000,
segment_02.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
https://redirector.googlevideo.com/videoplayback/...
#EXTINF:0.990,
https://redirector.googlevideo.com/videoplayback/...
#EXT-X-DISCONTINUITY
#EXTINF:6.000,
segment_03.ts
#EXTINF:6.000,
segment_04.ts
#EXTINF:6.000,
segment_05.ts
#EXTINF:6.000,
segment_06.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
https://redirector.googlevideo.com/videoplayback/...
#EXTINF:4.000,
https://redirector.googlevideo.com/videoplayback/...
#EXTINF:1.990,
https://redirector.googlevideo.com/videoplayback/...
#EXT-X-ENDLIST

Gestire il monitoraggio degli annunci lato client

L'SDK IMA gestirà automaticamente il monitoraggio degli annunci lato client.

Ispezionare le sessioni VOD abilitate da Google Ad Manager

Per esaminare le sessioni VOD e i dettagli dei tag annuncio per queste sessioni, utilizza lo strumento Monitoraggio attività di streaming in Ad Manager.