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.
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); }
You can set or override the following optional parameters per session:
manifestOptions
: specifies which video renditions are generated in the stitched video manifest and the ordering of the renditions; see the manifest options documentationadTracking
: select either client-side ad tracking or server-side ad trackingtargetingParameters
: a Google Ad Manager ad tag can contain targeting parameters that can be updated per session; see how to set targeting parameters with the IMA SDK
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.
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' } }; 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 documentationadTracking
: select either client-side ad tracking or server-side ad tracking; this overrides the value in the live config for the sessiontargetingParameters
: 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 stringmy_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 pageLOCATION
: the location in which to create your session; use one of the supported regionsShow locationsus-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:
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.
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.
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.
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.
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.
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.
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.
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 pageLOCATION
: the location in which to create your session; use one of the supported regionsShow locationsus-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:
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.
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.
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.
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.
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.
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.
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.
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-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
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.