Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using basic ingestion when using the YouTube Live Streaming API or avoiding duplicate custom ones

We are using the YouTube Live Streaming API in conjunction with the Google API PHP Client and I cannot work out how to make it use a basic (preset) ingestion rather than a custom one.

Custom ones are OK, but for some reason even if you call them the same name it continually creates duplicates for every stream you create.

So my question is, how do we get it to use basic ingestion or be able to select a custom one without creating a new one each time?

For example here is the basic ingestion you can select when you setup a stream manually within your YouTube account:

YouTube encoder

The relevant PHP code:

// Create an object for the liveBroadcast resource's snippet. Specify values
// for the snippet's title, scheduled start time, and scheduled end time.
$broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet();
$broadcastSnippet->setTitle($this->title);
$broadcastSnippet->setDescription($this->desc);
$broadcastSnippet->setScheduledStartTime($this->start_time);

// Create an object for the liveBroadcast resource's status, and set the
// broadcast's status.
$status = new Google_Service_YouTube_LiveBroadcastStatus();
$status->setPrivacyStatus($this->privacy_status);

// Create the API request that inserts the liveBroadcast resource.
$broadcastInsert = new Google_Service_YouTube_LiveBroadcast();
$broadcastInsert->setSnippet($broadcastSnippet);
$broadcastInsert->setStatus($status);
$broadcastInsert->setKind('youtube#liveBroadcast');

// Execute the request and return an object that contains information
// about the new broadcast.
$broadcastsResponse = $this->youtube->liveBroadcasts->insert('snippet,status', $broadcastInsert, array());

// Create an object for the liveStream resource's snippet. Specify a value
// for the snippet's title.
$streamSnippet = new Google_Service_YouTube_LiveStreamSnippet();
$streamSnippet->setTitle($this->stream_title);

// Create an object for content distribution network details for the live
// stream and specify the stream's format and ingestion type.
$cdn = new Google_Service_YouTube_CdnSettings();
# TODO: Update the below `Format` method to use the new 'resolution' and 'frameRate' methods
$cdn->setFormat($this->format);
$cdn->setIngestionType('rtmp');

// Create the API request that inserts the liveStream resource.
$streamInsert = new Google_Service_YouTube_LiveStream();
$streamInsert->setSnippet($streamSnippet);
$streamInsert->setCdn($cdn);
$streamInsert->setKind('youtube#liveStream');

// Execute the request and return an object that contains information
// about the new stream.
$streamsResponse = $this->youtube->liveStreams->insert('snippet,cdn', $streamInsert, array());

// Bind the broadcast to the live stream.
$bindBroadcastResponse = $this->youtube->liveBroadcasts->bind(
    $broadcastsResponse['id'], 'id,contentDetails',
    array(
        'streamId' => $streamsResponse['id'],
    ));
like image 964
Brett Avatar asked May 01 '16 09:05

Brett


1 Answers

I'm not sure what you mean by "basic ingestion." According to the API, the only settable ingestion property is cdn.ingestionType which only supports RTMP ingestion at this time.

The equivalent of the encoder settings you see in the web portal was the cdn.format value, provided an interface to select bitrate-resolution pair for your Live Broadcast. This property was deprecated on April 18, 2016 in favor of two new properties: cdn.frameRate and cdn.resolution. The bitrate values listed in the web portal are the recommended bitrates for each resolution, which are configured by your encoder, not the API.

Properly setting custom cdn formats should not cause duplicate Live Stream objects. There may be a bug elsewhere in your code. If you feel that this is an API defect, I recommend opening a ticket for Google here.

like image 112
JAL Avatar answered Oct 08 '22 19:10

JAL