Using a basic trick when using the YouTube Live Streaming API or avoiding duplication of user

We use the YouTube Live Streaming API in conjunction with the Google API PHP Client , and I cannot figure out how to make it primary (pre-installed), not custom.

Custom is fine, but for some reason, even if you call them by the same name, it constantly creates duplicates for each stream created.

So my question is, how can we use a basic trick or be able to select a custom one without creating a new one each time?

For example, here is a basic trick you can choose when manually setting up a stream in your YouTube account:

YouTube Encoder

Relevant php code:

// Create an object for the liveBroadcast resource snippet. Specify values // for the snippet 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 status, and set the // broadcast 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 snippet. Specify a value // for the snippet 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 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'], )); 
+6
source share
2 answers

Well, from what I can say, there is no way to use a basic meal, but I figured out how to get it to use an existing user meal.

You can create a stream through the code, if you want, or create it manually in the YouTube interface.

Once this is done, you will need to get the stream ID stream that you want to associate with the new translation you created; I could not say how to find out this information through the YouTube interface so that you could do it using the API.

You can use the following code to get a list of threads using the method:

 // Execute an API request that lists the streams owned by the user who // authorized the request. $streamsResponse = $this->youtube->liveStreams->listLiveStreams('id,snippet', array( 'mine' => 'true', )); $htmlBody .= "<h3>Live Streams</h3><ul>"; foreach ($streamsResponse['items'] as $streamItem) { $htmlBody .= sprintf('<li>%s (%s)</li>', $streamItem['snippet']['title'], $streamItem['id']); } $htmlBody .= '</ul>'; 

Please note that the above code is a stub; You can see the full example in the linked list method above; basically you will still need to call Google_Client , Google_Service_YouTube and make sure you have a valid access token, etc.

Once you have the thread id that you should get through the process above; you can do something like below to use that particular thread you want:

 // Create an object for the liveBroadcast resource snippet. Specify values // for the snippet 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 status, and set the // broadcast 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()); // Bind the broadcast to the live stream. $bindBroadcastResponse = $this->youtube->liveBroadcasts->bind( $broadcastsResponse['id'], 'id,contentDetails', array( 'streamId' => 'stream_id_here', // <-- Insert your stream ID here )); 

Again, the above code is a stub.

So basically the bottom line is - if you have your own thread id that you want to use, you can completely remove the creation of the thread code, and then just pass the thread id, which should already be in the bind method call, and you should be good.

Hope this helps someone else.

0
source

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

The equivalent of the encoder settings that you see on the web portal is the value cdn.format , provided that the interface for selecting a resolution pair by bit rate 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 on the web portal are the recommended bitrates for each resolution that are configured by your encoder, not the API.

Proper configuration of custom cdn formats cdn not lead to duplication of Live Stream objects. There may be an error in your code. If you think this is a defect in the API, I recommend opening a ticket for Google here .

+2
source

All Articles