To enable the Video Stitcher API for your project, please reach out to your Account Representative or contact Sales to learn more.

Manage a live session enabled by Google Ad Manager

Using the Video Stitcher API, you create a live session each time you start playback of a livestream in which ads served by Google Ad Manager are dynamically stitched during ad breaks. The response contains the playback URL and the configuration of the live session.

This page describes how to create and manage a live session that is enabled by Google Ad Manager. For information on live sessions that don't use Google Ad Manager, see Manage a live session.

Before you begin

  • Create a live config. For the integration with Google Ad Manager, ensure that the gamLiveConfig object is set.
  • If you are specifying a slate, ensure that the gamSlate object is set on the slate you register.

Create a live session

You can create a live session by using the IMA SDK (which calls the Video Stitcher API) or by using the Video Stitcher API directly.

Use the IMA SDK

If you are integrating with the IMA SDK, the IMA SDK creates the live session.

functionrequestVideoStitcherStream(){
conststreamRequest=newgoogle.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);
}

You can set or override the following optional parameters per session:

See the next section to learn how to set these parameters using the IMA SDK.

Optional parameters and overrides

You can set optional parameters per session, like the manifestOptions field. This field is not available in the live config. You can also override certain parameters that are set in the live config for a given session.

For example, if the default adTracking on the live config is set to SERVER, you can override that value to CLIENT and also set the manifestOptions field in the IMA SDK by setting the videoStitcherSessionOptions JSON object field.

functionrequestVideoStitcherStream(){
conststreamRequest=newgoogle.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);
}

For more information, see Add streaming session options.

Use the API directly

To create a live session using the API directly, use the projects.locations.liveSessions.create method.

The liveConfig field is the only required field in the JSON body. You can set or override the following optional parameters per live session (as shown in the following REST example):

  • manifestOptions: specifies which video renditions are generated in the stitched video manifest and the ordering of the renditions; see the manifest options documentation
  • adTracking: select either client-side ad tracking or server-side ad tracking; this overrides the value in the live config for the session
  • targetingParameters: a Google Ad Manager ad tag can contain targeting parameters that can be updated per session; provide a mapping in this field (for example, to replace the [my_key] macro with the string my_value, see the REST example)

REST

Before using any of the request data, make the following replacements:

  • PROJECT_NUMBER: your Google Cloud project number located in the Project number field on the IAM Settings page
  • LOCATION: the location in which to create your session; use one of the supported regions
    Show locations
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • LIVE_CONFIG_ID: the user-defined identifier for the live config

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Save the request body in a file named request.json. Run the following command in the terminal to create or overwrite this file in the current directory:

cat> request.json << 'EOF' { "liveConfig": "projects/PROJECT_NUMBER/locations/LOCATION/liveConfigs/LIVE_CONFIG_ID",
 "manifestOptions": {
 "includeRenditions": [
 {
 "bitrateBps": 150000,
 "codecs": "hvc1.1.4.L126.B0"
 },
 {
 "bitrateBps": 440000,
 "codecs": "hvc1.1.4.L126.B0"
 }
 ],
 "bitrateOrder": "DESCENDING"
 },
 "adTracking": "SERVER",
 "gamSettings": {
 "targetingParameters": {
 "my_key": "my_value",
 },
 }
}
EOF

Then execute the following command to send your REST request:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://videostitcher.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/liveSessions"

PowerShell (Windows)

Save the request body in a file named request.json. Run the following command in the terminal to create or overwrite this file in the current directory:

@'
{
 "liveConfig": "projects/PROJECT_NUMBER/locations/LOCATION/liveConfigs/LIVE_CONFIG_ID",
 "manifestOptions": {
 "includeRenditions": [
 {
 "bitrateBps": 150000,
 "codecs": "hvc1.1.4.L126.B0"
 },
 {
 "bitrateBps": 440000,
 "codecs": "hvc1.1.4.L126.B0"
 }
 ],
 "bitrateOrder": "DESCENDING"
 },
 "adTracking": "SERVER",
 "gamSettings": {
 "targetingParameters": {
 "my_key": "my_value",
 },
 }
}
'@ | Out-File -FilePath request.json -Encoding utf8

Then execute the following command to send your REST request:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://videostitcher.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/liveSessions" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

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

Before trying this sample, follow the C# setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API C# API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


usingGoogle.Cloud.Video.Stitcher.V1 ;
publicclassCreateLiveSessionSample
{
publicLiveSessionCreateLiveSession(
stringprojectId,stringlocation,stringliveConfigId)
{
// Create the client.
VideoStitcherServiceClient client=VideoStitcherServiceClient .Create ();
CreateLiveSessionRequest request=newCreateLiveSessionRequest
{
Parent=$"projects/{projectId}/locations/{location}",
LiveSession=newLiveSession
{
LiveConfig=LiveConfigName .FormatProjectLocationLiveConfig (projectId,location,liveConfigId)
}
};
// Call the API.
LiveSession session=client.CreateLiveSession (request);
// Return the result.
returnsession;
}
}

Go

Before trying this sample, follow the Go setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Go API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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.
funccreateLiveSession(wio.Writer,projectID,liveConfigIDstring)error{
// projectID := "my-project-id"
// liveConfigID := "my-live-config"
location:="us-central1"
ctx:=context.Background()
client,err:=stitcher.NewVideoStitcherClient (ctx)
iferr!=nil{
returnfmt.Errorf("stitcher.NewVideoStitcherClient: %w",err)
}
deferclient.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)
iferr!=nil{
returnfmt.Errorf("client.CreateLiveSession: %w",err)
}
fmt.Fprintf(w,"Live session: %v\n",response.GetName())
fmt.Fprintf(w,"Play URI: %v",response.GetPlayUri())
returnnil
}

Java

Before trying this sample, follow the Java setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Java API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


importcom.google.cloud.video.stitcher.v1.CreateLiveSessionRequest ;
importcom.google.cloud.video.stitcher.v1.LiveConfigName ;
importcom.google.cloud.video.stitcher.v1.LiveSession ;
importcom.google.cloud.video.stitcher.v1.LocationName ;
importcom.google.cloud.video.stitcher.v1.VideoStitcherServiceClient ;
importjava.io.IOException;
publicclass CreateLiveSession{
publicstaticvoidmain(String[]args)throwsException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="my-project-id";
Stringlocation="us-central1";
StringliveConfigId="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.
publicstaticLiveSession createLiveSession(
StringprojectId,Stringlocation,StringliveConfigId)throwsIOException{
// 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 ());
returnresponse;
}
}
}

Node.js

Before trying this sample, follow the Node.js setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Node.js API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

/**
 * 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
conststitcherClient=newVideoStitcherServiceClient ();
asyncfunctioncreateLiveSession(){
// Construct request
constrequest={
parent:stitcherClient.locationPath (projectId,location),
liveSession:{
liveConfig:stitcherClient.liveConfigPath (
projectId,
location,
liveConfigId
),
},
};
const[session]=awaitstitcherClient.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

Before trying this sample, follow the PHP setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API PHP API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

Before trying this sample, follow the Python setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Python API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


importargparse
fromgoogle.cloud.videoimport stitcher_v1
fromgoogle.cloud.video.stitcher_v1.services.video_stitcher_serviceimport (
 VideoStitcherServiceClient,
)
defcreate_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

Before trying this sample, follow the Ruby setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Ruby API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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`)
#
defcreate_live_sessionproject_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_pathproject:project_id,location:location
# Build the resource name of the live config.
live_config_name=client.live_config_pathproject: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_sessionparent:parent,
live_session:new_live_session
# Print the live session name.
puts"Live session: #{response.name}"
end

The response is a live session object. The playUri is the URL the client device uses to play the ad stitched stream for this live session.

The Video Stitcher API generates a unique session ID for each request. A session expires if the playUri is not requested within the past 5 minutes.

If you're generating a session on behalf of your customers' devices, you can set the following parameters using HTTP headers:

Parameter HTTP Header
CLIENT_IP x-forwarded-for
REFERRER_URL referer
USER_AGENT user-agent

You can add the following headers to the preceding curl request:

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

If the x-forwarded-for header is not provided, the Video Stitcher API uses the client's IP address in ad metadata requests. Be aware that the client's IP address may not match the IP of your customers' devices if sessions are generated on behalf of your customers' devices.

Get a session

To get the live session, use the projects.locations.liveSessions.get method.

REST

Before using any of the request data, make the following replacements:

  • PROJECT_NUMBER: your Google Cloud project number located in the Project number field on the IAM Settings page
  • LOCATION: the location in which to create your session; use one of the supported regions
    Show locations
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID: the identifier for the live session

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://videostitcher.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID"

PowerShell (Windows)

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://videostitcher.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

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

Before trying this sample, follow the C# setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API C# API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


usingGoogle.Cloud.Video.Stitcher.V1 ;
publicclassGetLiveSessionSample
{
publicLiveSessionGetLiveSession(
stringprojectId,stringlocation,stringsessionId)
{
// Create the client.
VideoStitcherServiceClient client=VideoStitcherServiceClient .Create ();
GetLiveSessionRequest request=newGetLiveSessionRequest
{
LiveSessionName=LiveSessionName .FromProjectLocationLiveSession (projectId,location,sessionId)
};
// Call the API.
LiveSession session=client.GetLiveSession (request);
// Return the result.
returnsession;
}
}

Go

Before trying this sample, follow the Go setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Go API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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.
funcgetLiveSession(wio.Writer,projectID,sessionIDstring)error{
// projectID := "my-project-id"
// sessionID := "123-456-789"
location:="us-central1"
ctx:=context.Background()
client,err:=stitcher.NewVideoStitcherClient (ctx)
iferr!=nil{
returnfmt.Errorf("stitcher.NewVideoStitcherClient: %w",err)
}
deferclient.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)
iferr!=nil{
returnfmt.Errorf("client.GetLiveSession: %w",err)
}
fmt.Fprintf(w,"Live session: %+v",response)
returnnil
}

Java

Before trying this sample, follow the Java setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Java API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


importcom.google.cloud.video.stitcher.v1.GetLiveSessionRequest ;
importcom.google.cloud.video.stitcher.v1.LiveSession ;
importcom.google.cloud.video.stitcher.v1.LiveSessionName ;
importcom.google.cloud.video.stitcher.v1.VideoStitcherServiceClient ;
importjava.io.IOException;
publicclass GetLiveSession{
publicstaticvoidmain(String[]args)throwsException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="my-project-id";
Stringlocation="us-central1";
StringsessionId="my-session-id";
getLiveSession(projectId,location,sessionId);
}
// Gets a live session.
publicstaticLiveSession getLiveSession(StringprojectId,Stringlocation,StringsessionId)
throwsIOException{
// 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 ());
returnresponse;
}
}
}

Node.js

Before trying this sample, follow the Node.js setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Node.js API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

/**
 * 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
conststitcherClient=newVideoStitcherServiceClient ();
asyncfunctiongetLiveSession(){
// Construct request
constrequest={
name:stitcherClient.liveSessionPath (projectId,location,sessionId),
};
const[session]=awaitstitcherClient.getLiveSession(request);
console.log(`Live session: ${session.name}`);
}
getLiveSession().catch(err=>{
console.error(err.message);
process.exitCode=1;
});

PHP

Before trying this sample, follow the PHP setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API PHP API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

Before trying this sample, follow the Python setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Python API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


importargparse
fromgoogle.cloud.videoimport stitcher_v1
fromgoogle.cloud.video.stitcher_v1.services.video_stitcher_serviceimport (
 VideoStitcherServiceClient,
)
defget_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

Before trying this sample, follow the Ruby setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Ruby API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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`)
#
defget_live_sessionproject_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_pathproject:project_id,location:location,
live_session:session_id
# Get the live session.
session=client.get_live_sessionname:name
# Print the live session name.
puts"Live session: #{session.name}"
end

Sample ad-stitched playlist

The following shows a sample source live playlist before ad-stitching:

#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月22日T08: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月22日T08:39:20Z",SCTE35-IN=0xF...
#EXTINF:10.010
segment_00009.ts

The following shows a sample source live playlist after ad-stitching:

#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

Inspect live sessions enabled by Google Ad Manager

To see ad tag details for sessions, use the Stream activity monitor in Ad Manager to see details about ad requests.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.