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:
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'],
));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With