The YouTube Live Streaming API lets you create, update, and manage live events on YouTube. Using the API, you can schedule events (broadcasts) and associate them with video streams, which represent the actual broadcast content.
The Live Streaming API is actually comprised of components of the YouTube Data API and the YouTube Content ID API. The Data API enables YouTube users to manage their YouTube accounts, while the YouTube Content ID API enables interactions with YouTube's rights management system. However, all of the resources that make up the Live Streaming API are used only to create and manage live events.
This document is intended for developers who want to write applications to facilitate live broadcasting on YouTube. It explains basic concepts of YouTube and of the API itself. It also provides an overview of the different functions that the API supports.
- A broadcast represents an event that can be watched on YouTube as it happens. Broadcasts can also be recorded and saved as YouTube videos so that users can watch them after they happen.
- A stream identifies the audio-video content that is being communicated to YouTube. Each broadcast is associated with one video stream.
- A cuepoint represents an ad break that can be inserted into a live broadcast.
API use cases
The list below suggests several ways to use the API in your application:
Schedule broadcasts and define broadcast settings. Your application could enable users to predefine broadcast settings and then select the settings to apply to a particular broadcast.
Associate video streams and broadcasts.
Enable broadcasters to define information about a broadcast and its video (using the YouTube Data API) at the same time.
Simplify transitions between broadcast states (
live, etc.) and enable users to insert cuepoints.
Before you start
You need a Google Account to access the Google Developers Console, request an API key, and register your application.
Register your application with Google so that it can submit API requests.
After registering your application, select the YouTube Data API as one of the services that your application uses:
- Go to the Developers Console and select the project that you just registered.
- In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure the status is ON for the YouTube Data API v3 and, if you are a YouTube Content Partner, the YouTube Content ID API.
Authorizing API requests
As noted above, the Live Streaming API uses functionality that is technically part of either the YouTube Data API or the YouTube Content ID API. You can use the Content ID API to provide YouTube with metadata, ownership information, and policy information for your assets. (A live video broadcast is an example of an asset.) The API also lets you claim videos and set ad policies for your videos.
This section explains the authorization requirements for requests to the Content ID API, which are different from the requirements for authorizing other Live Streaming API requests.
- Calling the Data API
- The API request must be authorized by the Google Account that owns the broadcasting YouTube channel.
- Calling the Content ID API
- The API request must be authorized by a Google Account that is linked to the content owner that owns the broadcasting YouTube channel.
Resources and resource types
A resource is an individual data entity with a unique identifier. The table below describes the different types of resources that you will interact with using the Live Streaming API. Technically, all of these resources are actually defined as part of either the YouTube Data API or the YouTube Content ID API. However, the
liveCuepoint resources are only used to create and manage live events.
||Contains information about an event that you are broadcasting on YouTube. A
As such, a
||Contains information about the video stream that you are transmitting to YouTube. The stream provides the content that will be broadcast to YouTube users. Once created, a
||Starts an ad break in the broadcast video stream.
Note: The API command for controlling cuepoints is actually part of the YouTube Content ID API and has different authorization requirements than requests to manage
||Represents a single YouTube video. As noted above, a
||Defines the advertising settings for a video (or broadcast). You use the YouTube Content ID API to set advertising options.|
||Represents a piece of intellectual property, such as a movie or an episode of a show. In this case, the broadcast video is the asset. You will use the YouTube Content ID API to create and manage
||Links a video to an asset that the video matches. You create a claim, using the YouTube Content ID API, to identify yourself as the owner of the broadcast video.|
||Defines rules that specify the circumstances under which you want your content to be viewable on YouTube or blocked from appearing on YouTube. You need to apply a policy to your broadcast video and can also specify a policy that YouTube will apply to user-uploaded videos that match your broadcast video.|
The following table shows the different methods that the API supports:
||Changes the status of a
||Toggles the display settings for a slate that displays in the broadcast stream for a broadcast that is already in progress.|
The table below identifies the operations that are supported for different types of resources. Operations that insert, update, or delete resources always require user authorization. In some cases,
list methods support both authorized and unauthorized requests, where unauthorized requests only retrieve public data while authorized requests can also retrieve information that is restricted to the currently authenticated user.
The API allows, and actually requires, the retrieval of partial resources so that applications avoid transferring, parsing, and storing unneeded data. This approach also ensures that the API uses network, CPU, and memory resources more efficiently.
part parameter is a required parameter for any API request that retrieves or returns a YouTube Data API resource. The parameter identifies one or more top-level (non-nested) resource properties that should be included in an API response. For example, a
liveStream resource has the following parts:
All of these parts are objects that contain nested properties, and you can think of these objects as groups of metadata fields that the API server might (or might not) retrieve. As such, the
part parameter requires you to select the resource components that your application actually uses. This requirement serves several purposes:
- It lets you manage your API quota usage. If you increase the number of parts you retrieve in API responses, your API usage increases accordingly, and your available quota decreases.
- It reduces latency by preventing the API server from spending time retrieving metadata fields that your application doesn't use.
- It reduces bandwidth usage by reducing (or eliminating) the amount of unnecessary data that your application might retrieve.
Over time, as resources add more parts, these benefits will only increase since your application will not be requesting newly introduced properties that it doesn't support.
Tips and best practices
Claim your content
If you would like to show ads during your broadcast, you need to claim the broadcast video before the event begins. To claim content, you must be a YouTube Content Partner participating in the Content ID program.
The process for claiming your live broadcast video is different than the normal process for claiming a video. When claiming live video, you need to create your claim before the video actually exists. The API does support this, and the life of a broadcast document explains the YouTube Content ID API calls that enable you to create your claim.
Preview and test your content
Upon receiving your inbound video stream, YouTube can then broadcast that video on two different outbound streams:
The monitor stream enables you to preview (and test) your video broadcast. It is a private stream that is only accessible to you. You can only transition a broadcast to the
testingphase if the broadcast's monitor stream is enabled. The monitor stream does not show ad breaks.
The broadcast stream is the stream visible to your audience. You can set the broadcast's privacy status to either
unlisted. (A private broadcast is only visible to users who have been explicitly invited to watch it, while an unlisted broadcast is visible to anyone with a link to view it.)
You can choose to delay the broadcast stream so that it does not run concurrently with the monitor stream. By delaying the broadcast stream, you can have more fine-grained control over the time that you insert cuepoints into the broadcast.
However, delaying the broadcast stream makes it difficult for your live presenters to interact with your viewing audience. In addition, delaying the broadcast increases the likelihood that viewers will discover key details about the event from sources other than your broadcast. For example, if you are broadcasting a sporting event on a 60-second delay, viewers might learn about critical moments in the event from other real-time news sources before actually seeing them in the broadcast.
YouTube recommends that you enable the monitor stream for your broadcast so that you can test your content. You should choose whether to also delay your broadcast based on your desire to control timing of cuepoints as opposed to your desire to interact with your audience or provide real-time coverage of an event.
Control your broadcast stream content
The YouTube Live Streaming API provides two ways to show users content other than your broadcast video for a broadcast that is in progress:
A slate is a static image that displays in the video player instead of the broadcast video. The slate can be enabled or disabled by calling the
liveBroadcasts.controlmethod. While it is enabled, viewers cannot see or hear your broadcast content.
YouTube selects the image that displays while the slate is enabled, and the same image displays in all regions and in all video players.
A cuepoint indicates that an ad break is starting in the broadcast. During your broadcast, you can use the API's
liveCuepoints.insertmethod to insert those breaks into your live broadcast.
From the end user's perspective, ads and slates behave differently in two important ways, which are described below:
An ad break has a predefined length of time, which you set using the
settings.durationSecsproperty. After the ad concludes, viewers return to the live broadcast.
On the other hand, a slate displays until you explicitly indicate that it should be removed. You call the
liveBroadcasts.controlmethod to toggle the display settings for the slate, and viewers return to your broadcast after you call that method to disable the slate.
When you insert an ad break, an ad only plays in the video player for viewers who are watching the broadcast when the cuepoint is inserted. An ad does not run when viewers refresh the page where the broadcast is playing or when visitors start watching the broadcast after the cuepoint is inserted.
However, when you enable a slate, the slate displays in the video player instead of your broadcast stream for all viewers. Viewers who refresh the page where the broadcast is playing and new viewers will also see the slate.
With those differences in mind, it is very important to note that ad breaks and slates are not mutually exclusive. In fact, if you are inserting an ad break, you are encouraged to also display a slate at the same time. By doing so, you ensure that viewers who start watching your broadcast while an ad break is in progress will see the slate instead of your broadcast stream. This approach provides you with the most control over the time that the broadcast break ends and, consequently, over the time that viewers return to your broadcast.
The sequence of steps below reflects the best practice for inserting an ad break during your broadcast:
- Call the
liveBroadcasts.controlmethod to display a slate in the video player instead of your broadcast.
- Insert a cuepoint to start your ad break. The video player shows an ad to any viewers already watching the broadcast. New viewers see the slate inserted in step 1.
- The ad ends. Viewers return to the slate inserted in step 1.
- Call the
liveBroadcasts.controlmethod to remove the slate. Viewers return to your broadcast.
Set time offsets
When enabling a slate or inserting a cuepoint, you can specify that the slate or cuepoint should be inserted right away or that it should be inserted at a specific point in the broadcast. Your options depend on whether the broadcast stream for your video is delayed.
If your broadcast stream is not delayed, then your only option is to enable the slate or insert the cuepoint immediately:
- To enable a slate, call the
liveBroadcasts.controlmethod and set the
displaySlateparameter's value to
true. Do not include the
offsetTimeMsparameter in your request.
- To insert a cuepoint, call the
liveCuepoints.insertmethod. In the resource sent in the request, either set the
settings.offsetTimeMsproperty's value to
0or do not specify a value for that property.
Important: In fact, viewers do not see the resulting slate or ad content immediately. There may be a delay of around 30 seconds before the slate or ad content is visible to users. During that delay, your broadcast stream will still be visible to your viewers, and you need to watch the broadcast stream to determine when the slate or ad content actually displays instead of your monitor stream.
- To enable a slate, call the
If your broadcast stream is delayed, then you can either insert the slate or cuepoint immediately as described above, or you can specify a time offset to determine when the slate or ad will display. Rather than instructing YouTube to enable the slate or insert the cuepoint as soon as possible, the time offset specifies a point in your broadcast when viewers should see a slate or an ad.
The offset value is measured from the beginning of the monitor stream for your broadcast. Note that if your broadcast has a testing phase, then the monitor stream starts when your broadcast transitions to the
testingstatus. Otherwise, your monitor stream starts when your broadcast transitions to the
Calculate the time offset value
To retrieve the offset value, call the YouTube Player API's
getCurrentTime function for the player that is playing the monitor stream. Use the retrieved value to insert the cuepoint in the broadcast stream at that time.
The possible values for the offset time can be calculated as the following range:
[(elapsed_time - broadcast_delay + Δ), (elapsed_time - Δ)]
Δ is a five-second buffer at the beginning and end of the possible time offsets when YouTube cannot precisely insert a cuepoint. For example:
- A broadcast has a five-minute testing phase.
- The broadcast stream is delayed 60 seconds after the monitor stream.
- The broadcaster is inserting the cuepoint four minutes after the broadcast transitions to
livestatus. (This is three minutes after the broadcast stream becomes visible.)
In this case, the possible range of offset times is
These times are specified in milliseconds, and are calculated using the following values:
elapsed_time=540000– The monitor stream has run for nine minutes (540 seconds, 540000 milliseconds) when the
liveCuepoints.insertmethod is called.
broadcast_delay=60000– The broadcast stream is delayed by 60 seconds, or 60000 milliseconds.
Δ=5000– The five-second buffer when the cuepoint cannot be reliably inserted.
Troubleshooting and error handling
The following guidelines explain how to resolve specific problems that may arise. Also refer to the error documentation for lists of errors that each API method might return.
When a broadcast transitions from one status to another, it may temporarily be assigned with another status while YouTube completes the actions associated with the transition. For example, if you send a
liveBroadcasts.transitionrequest to change a broadcast's status from
testing, YouTube will set the broadcast's status to
testStartingand then complete the actions associated with the status change. When all of those actions have been completed, YouTube will update the broadcast's status to
testing, thereby indicating that the transition is complete.
If a broadcast becomes stuck with a
liveStartingstatus, you need to call the
liveBroadcasts.deletemethod and delete the broadcast. Then create a new broadcast, bind it to your live stream, and continue with the testing process.
As noted in the
liveBroadcasts.transitionmethod's documentation, you should confirm that the value of the
status.streamStatusproperty for the stream bound to your broadcast is
activebefore calling that method.