管理由 Google Ad Manager 啟用的即時工作階段

每次開始播放直播時,您都可以使用 Video Stitcher API 建立直播工作階段,在廣告插播期間動態併接 Google Ad Manager 放送的廣告。回應包含播放網址和直播工作階段的設定。

本頁說明如何建立及管理透過 Google Ad Manager 啟用的直播工作階段。如要瞭解使用 Google Ad Manager 的直播工作階段,請參閱「管理直播工作階段」。

事前準備

  • 建立即時設定。如要與 Google Ad Manager 整合,請確保已設定 gamLiveConfig 物件。
  • 如果您要指定候選影片組合,請務必在註冊的候選影片組合中設定 gamSlate 物件。

建立直播工作階段

您可以透過 IMA SDK (呼叫 Video Stitcher API) 或直接使用 Video Stitcher API 建立直播工作階段。

使用 IMA SDK

如果您與 IMA SDK 整合,IMA SDK 會建立直播工作階段。

function requestVideoStitcherStream() {
  const streamRequest = new google.ima.dai.api.VideoStitcherLiveStreamRequest();
  streamRequest.liveStreamEventId = 'LIVE_CONFIG_ID';
  streamRequest.region = 'LOCATION';
  streamRequest.projectNumber = 'PROJECT_NUMBER';
  streamRequest.oAuthToken = 'OAUTH_TOKEN';
  streamRequest.networkCode = 'NETWORK_CODE';
  streamRequest.customAssetKey = 'CUSTOM_ASSET_KEY';

  streamManager.requestStream(streamRequest);
}

您可以為每個工作階段設定或覆寫下列選用參數:

請參閱下一節,瞭解如何使用 IMA SDK 設定這些參數。

選用參數和覆寫

您可以為每個工作階段設定選用參數,例如 manifestOptions 欄位。 這個欄位不適用於即時設定。您也可以覆寫特定工作階段的即時設定中設定的參數。

舉例來說,如果將即時設定中的預設 adTracking 設為 SERVER,您可以將該值覆寫為 CLIENT,並透過設定 videoStitcherSessionOptions JSON 物件欄位,在 IMA SDK 中設定 manifestOptions 欄位。

function requestVideoStitcherStream() {
  const streamRequest = new google.ima.dai.api.VideoStitcherLiveStreamRequest();
  streamRequest.liveStreamEventId = 'LIVE_CONFIG_ID';
  streamRequest.region = 'LOCATION';
  streamRequest.projectNumber = 'PROJECT_NUMBER';
  streamRequest.oAuthToken = 'OAUTH_TOKEN';
  streamRequest.networkCode = 'NETWORK_CODE';
  streamRequest.customAssetKey = 'CUSTOM_ASSET_KEY';
  streamRequest.videoStitcherSessionOptions = {
    adTracking: 'CLIENT',
    '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);
}

詳情請參閱「新增串流工作階段選項」。

直接使用 API

如要直接使用 API 建立直播工作階段,請使用 projects.locations.liveSessions.create 方法。

JSON 內文中只有 liveConfig 欄位為必填。您可以為每個即時工作階段設定或覆寫下列選用參數 (如下列 REST 範例所示):

REST

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_NUMBER:位於「IAM 設定」頁面「專案編號」欄位的 Google Cloud 專案編號
  • LOCATION:建立工作階段的位置;請使用其中一個支援的區域
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • LIVE_CONFIG_ID:使用者定義的即時設定 ID

如要傳送要求,請展開以下其中一個選項:

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID",
  "playUri": "PLAY_URI",
  "manifestOptions": {
    "includeRenditions": [
      {
        "bitrateBps": 150000,
        "codecs": "hvc1.1.4.L126.B0"
      },
      {
        "bitrateBps": 440000,
        "codecs": "hvc1.1.4.L126.B0"
      }
    ],
    "bitrateOrder": "DESCENDING"
  },
  "gamSettings": {
    "streamId": "STREAM_ID"
  },
  "liveConfig": "projects/PROJECT_NUMBER/locations/LOCATION/liveConfigs/LIVE_CONFIG_ID",
  "adTracking": "SERVER"
}

C#

在試用這個範例之前,請先按照C#使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API C# API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


using Google.Cloud.Video.Stitcher.V1;

public class CreateLiveSessionSample
{
    public LiveSession CreateLiveSession(
        string projectId, string location, string liveConfigId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        CreateLiveSessionRequest request = new CreateLiveSessionRequest
        {
            Parent = $"projects/{projectId}/locations/{location}",
            LiveSession = new LiveSession
            {
                LiveConfig = LiveConfigName.FormatProjectLocationLiveConfig(projectId, location, liveConfigId)
            }
        };

        // Call the API.
        LiveSession session = client.CreateLiveSession(request);

        // Return the result.
        return session;
    }
}

Go

在試用這個範例之前,請先按照Go使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Go API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import (
	"context"
	"fmt"
	"io"

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

// createLiveSession creates a livestream session in which to insert ads.
// Live sessions are ephemeral resources that expire after a few minutes.
func createLiveSession(w io.Writer, projectID, liveConfigID string) error {
	// projectID := "my-project-id"
	// liveConfigID := "my-live-config"
	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 := &stitcherpb.CreateLiveSessionRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		LiveSession: &stitcherpb.LiveSession{
			LiveConfig: fmt.Sprintf("projects/%s/locations/%s/liveConfigs/%s", projectID, location, liveConfigID),
		},
	}
	// Creates the live session.
	response, err := client.CreateLiveSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.CreateLiveSession: %w", err)
	}

	fmt.Fprintf(w, "Live session: %v\n", response.GetName())
	fmt.Fprintf(w, "Play URI: %v", response.GetPlayUri())
	return nil
}

Java

在試用這個範例之前,請先按照Java使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Java API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.video.stitcher.v1.CreateLiveSessionRequest;
import com.google.cloud.video.stitcher.v1.LiveConfigName;
import com.google.cloud.video.stitcher.v1.LiveSession;
import com.google.cloud.video.stitcher.v1.LocationName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class CreateLiveSession {

  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 liveConfigId = "my-live-config-id";

    createLiveSession(projectId, location, liveConfigId);
  }

  // Creates a live session given the parameters in the supplied live config.
  // For more information, see
  // https://cloud.google.com/video-stitcher/docs/how-to/managing-live-sessions.
  public static LiveSession createLiveSession(
      String projectId, String location, String liveConfigId) 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()) {
      CreateLiveSessionRequest createLiveSessionRequest =
          CreateLiveSessionRequest.newBuilder()
              .setParent(LocationName.of(projectId, location).toString())
              .setLiveSession(
                  LiveSession.newBuilder()
                      .setLiveConfig(LiveConfigName.format(projectId, location, liveConfigId)))
              .build();

      LiveSession response = videoStitcherServiceClient.createLiveSession(createLiveSessionRequest);
      System.out.println("Created live session: " + response.getName());
      System.out.println("Play URI: " + response.getPlayUri());
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Node.js API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

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

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

async function createLiveSession() {
  // Construct request
  const request = {
    parent: stitcherClient.locationPath(projectId, location),
    liveSession: {
      liveConfig: stitcherClient.liveConfigPath(
        projectId,
        location,
        liveConfigId
      ),
    },
  };

  const [session] = await stitcherClient.createLiveSession(request);
  console.log(`Live session: ${session.name}`);
  console.log(`Play URI: ${session.playUri}`);
}

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

PHP

在試用這個範例之前,請先按照PHP使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API PHP API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\CreateLiveSessionRequest;
use Google\Cloud\Video\Stitcher\V1\LiveSession;

/**
 * Creates a live session. Live sessions are ephemeral resources that expire
 * after a few minutes.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $liveConfigId         The live config ID to use to create the
 *                                     live session
 */
function create_live_session(
    string $callingProjectId,
    string $location,
    string $liveConfigId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $parent = $stitcherClient->locationName($callingProjectId, $location);
    $liveConfig = $stitcherClient->liveConfigName($callingProjectId, $location, $liveConfigId);
    $liveSession = new LiveSession();
    $liveSession->setLiveConfig($liveConfig);

    // Run live session creation request
    $request = (new CreateLiveSessionRequest())
        ->setParent($parent)
        ->setLiveSession($liveSession);
    $response = $stitcherClient->createLiveSession($request);

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

Python

在試用這個範例之前,請先按照Python使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Python API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import argparse

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


def create_live_session(
    project_id: str, location: str, live_config_id: str
) -> stitcher_v1.types.LiveSession:
    """Creates a live session. Live sessions are ephemeral resources that expire
    after a few minutes.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the session.
        live_config_id: The user-defined live config ID.

    Returns:
        The live session resource.
    """

    client = VideoStitcherServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    live_config = (
        f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
    )

    live_session = stitcher_v1.types.LiveSession(live_config=live_config)

    response = client.create_live_session(parent=parent, live_session=live_session)
    print(f"Live session: {response.name}")
    return response

Ruby

在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Ruby API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

require "google/cloud/video/stitcher"

##
# Create a live stream session. Live sessions are ephemeral resources
# that expire after a few minutes.
#
# @param project_id [String] Your Google Cloud project (e.g. `my-project`)
# @param location [String] The location (e.g. `us-central1`)
# @param live_config_id [String] Your live config name (e.g. `my-live-config`)
#
def create_live_session project_id:, location:, live_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 live config.
  live_config_name = client.live_config_path project: project_id,
                                             location: location,
                                             live_config: live_config_id

  # Set the session fields.
  new_live_session = {
    live_config: live_config_name
  }

  response = client.create_live_session parent: parent,
                                        live_session: new_live_session

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

回應是即時工作階段物件playUri 是用戶端裝置用來播放這個直播工作階段的廣告縫合串流的網址。

Video Stitcher API 會為每個要求產生專屬工作階段 ID。如果過去 5 分鐘內未要求 playUri,工作階段就會過期。

如果您要代表顧客裝置產生工作階段,可以使用 HTTP 標頭設定下列參數:

參數 HTTP 標頭
CLIENT_IP x-forwarded-for
REFERRER_URL referer
USER_AGENT user-agent

您可以在上述 curl 要求中加入下列標頭:

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

如果未提供 x-forwarded-for 標頭,Video Stitcher API 會在廣告中繼資料要求中使用用戶端 IP 位址。請注意,如果工作階段是代表顧客裝置產生,用戶端的 IP 位址可能與顧客裝置的 IP 位址不符。

取得工作階段

如要取得即時工作階段,請使用 projects.locations.liveSessions.get 方法。

REST

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_NUMBER:位於「IAM 設定」頁面「專案編號」欄位的 Google Cloud 專案編號
  • LOCATION:建立工作階段的位置;請使用其中一個支援的區域
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID:即時會議的 ID

如要傳送要求,請展開以下其中一個選項:

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID",
  "playUri": "ad-stitched-live-stream-uri",
  "manifestOptions": {
    "includeRenditions": [
      {
        "bitrateBps": 150000,
        "codecs": "hvc1.1.4.L126.B0"
      },
      {
        "bitrateBps": 440000,
        "codecs": "hvc1.1.4.L126.B0"
      }
    ],
    "bitrateOrder": "DESCENDING"
  },
  "gamSettings": {
    "streamId": "STREAM_ID",
    "targetingParameters": {
      "my_key": "my_value"
    }
  },
  "liveConfig": "projects/PROJECT_NUMBER/locations/LOCATION/liveConfigs/LIVE_CONFIG_ID",
  "adTracking": "SERVER"
}

C#

在試用這個範例之前,請先按照C#使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API C# API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


using Google.Cloud.Video.Stitcher.V1;

public class GetLiveSessionSample
{
    public LiveSession GetLiveSession(
        string projectId, string location, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetLiveSessionRequest request = new GetLiveSessionRequest
        {
            LiveSessionName = LiveSessionName.FromProjectLocationLiveSession(projectId, location, sessionId)
        };

        // Call the API.
        LiveSession session = client.GetLiveSession(request);

        // Return the result.
        return session;
    }
}

Go

在試用這個範例之前,請先按照Go使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Go API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import (
	"context"
	"fmt"
	"io"

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

// getLiveSession gets a livestream session by ID.
func getLiveSession(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 := &stitcherpb.GetLiveSessionRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/liveSessions/%s", projectID, location, sessionID),
	}
	// Gets the session.
	response, err := client.GetLiveSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetLiveSession: %w", err)
	}

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

Java

在試用這個範例之前,請先按照Java使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Java API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.video.stitcher.v1.GetLiveSessionRequest;
import com.google.cloud.video.stitcher.v1.LiveSession;
import com.google.cloud.video.stitcher.v1.LiveSessionName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class GetLiveSession {

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

    getLiveSession(projectId, location, sessionId);
  }

  // Gets a live session.
  public static LiveSession getLiveSession(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()) {
      GetLiveSessionRequest getLiveSessionRequest =
          GetLiveSessionRequest.newBuilder()
              .setName(LiveSessionName.of(projectId, location, sessionId).toString())
              .build();

      LiveSession response = videoStitcherServiceClient.getLiveSession(getLiveSessionRequest);
      System.out.println("Live session: " + response.getName());
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Node.js API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

/**
 * 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 getLiveSession() {
  // Construct request
  const request = {
    name: stitcherClient.liveSessionPath(projectId, location, sessionId),
  };
  const [session] = await stitcherClient.getLiveSession(request);
  console.log(`Live session: ${session.name}`);
}

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

PHP

在試用這個範例之前,請先按照PHP使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API PHP API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

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

/**
 * Gets a live 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_live_session(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->liveSessionName($callingProjectId, $location, $sessionId);
    $request = (new GetLiveSessionRequest())
        ->setName($formattedName);
    $session = $stitcherClient->getLiveSession($request);

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

Python

在試用這個範例之前,請先按照Python使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Python API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import argparse

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


def get_live_session(
    project_id: str, location: str, session_id: str
) -> stitcher_v1.types.LiveSession:
    """Gets a live session. Live sessions are ephemeral resources that expire
    after a few minutes.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the live session.

    Returns:
        The live session resource.
    """

    client = VideoStitcherServiceClient()

    name = client.live_session_path(project_id, location, session_id)
    response = client.get_live_session(name=name)
    print(f"Live session: {response.name}")
    return response

Ruby

在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Video Stitcher API 快速入門中的設定說明操作。 詳情請參閱 Video Stitcher API Ruby API 參考說明文件

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

require "google/cloud/video/stitcher"

##
# Get a live session. Live sessions are ephemeral resources
# that expire after a few minutes.
#
# @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 live session ID (e.g. `my-live-session-id`)
#
def get_live_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 live session.
  name = client.live_session_path project: project_id, location: location,
                                  live_session: session_id

  # Get the live session.
  session = client.get_live_session name: name

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

已插入廣告的播放清單範例

以下是廣告縫合前的來源直播播放清單範例:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:5
#EXTINF:10.010
segment_00005.ts
#EXTINF:10.010
segment_00006.ts
#EXT-X-DATERANGE:ID="2415919105",START-DATE="2021-06-22T08:32:00Z",DURATION=60,SCTE35-OUT=0xF...
#EXTINF:10.010
segment_00007.ts
#EXTINF:10.010
segment_00008.ts
#EXT-X-DATERANGE:ID="2415919105",START-DATE="2021-06-22T08:39:20Z",SCTE35-IN=0xF...
#EXTINF:10.010
segment_00009.ts

以下顯示廣告縫合後的來源直播播放清單範例:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:5
#EXTINF:10.010
segment_00005.ts
#EXTINF:10.010
segment_00006.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000
https://dai.google.com/.../ad-1/seg-1.ts
#EXTINF:5.000
https://dai.google.com/.../ad-1/seg-2.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000
https://dai.google.com/.../ad-2/seg-1.ts
#EXTINF:5.000
https://dai.google.com/.../ad-2/seg-2.ts
#EXT-X-DISCONTINUITY
#EXTINF:10.010
segment_00009.ts

檢查透過 Google Ad Manager 啟用的即時工作階段

如要查看工作階段的廣告代碼詳細資料,請使用 Ad Manager 中的串流播放活動監控器,查看廣告請求的詳細資料。