1

Selecting 'go live' from the camera icon in YouTube, brings me to the studio where my default stream is.

I seem to need to navigate there (to enable it) before I can start uploading data via rtmp to that stream. Similarly, if there is a break in the stream for a minute or so, the stream automatically ends, and i need to go to the page and click the 'dismiss' button to start it again.

I found I can programmatically check if the stream is running with:

curl -H "Authorization: Bearer XXXXXXX_AUTHTOKEN" "https://www.googleapis.com/youtube/v3/liveStreams?part=snippet,cdn,contentDetails,status&mine=true"

where I get the an entry in the JSON with the same dn.ingestionInfo.streamName as the stream key on the studio page. The entry also shows contentDetails.isReusable=true and status.streamStatus=active (where I believe it needs to be 'ready' to be able to accept / start the stream.

    {
      "kind": "youtube#liveStream",
        "title": "Default stream key",
        "description": "Description for default stream key",
        "isDefaultStream": false
      },
      "cdn": {
        "ingestionType": "rtmp",
        "ingestionInfo": {
          "streamName": "XXXXXXXXXXXXXXX",
          "ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
          "backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1",
          "rtmpsIngestionAddress": "rtmps://a.rtmps.youtube.com/live2",
          "rtmpsBackupIngestionAddress": "rtmps://b.rtmps.youtube.com/live2?backup=1"
        },
        "resolution": "variable",
        "frameRate": "variable"
      },
      "status": {
        "streamStatus": "active",
        "healthStatus": {
          "status": "good"
        }
      },
        "isReusable": true
      }
    }

Is there an API set I can use to reuse this default stream and programmatically change its state from active to ready?

I tried doing this below, but it always gives a new streamName instead of changing the status.streamStatus of the default one.

curl -H "Authorization: Bearer AUTHTOKEN" -H "Accept: application/json" -H "Content-Type: application/json" --data "{'id':'STREAMID_FROM_DEFAULT_IN_STATUS_CALL','snippet':{'title':'test','description':'test.'},'status':{'streamStatus':'ready'},'cdn':{'ingestionType':'rtmp','frameRate':'variable','resolution':'variable','ingestionInfo':{'streamName':'STREAM_NAME_FROM_DEFAULT_IN_STATUS_CALL'}}}" --request POST "https://youtube.googleapis.com/youtube/v3/liveStreams?part=snippet,status,cdn".

However, this returns a different id, and a different cdn.ingestionInfo.streamName than the ones I specified in the call.

Thoughts or ideas on how I can reuse the default 'Go live' studio stream programmatically?

stvar
  • 6,551
  • 2
  • 13
  • 28
me_online
  • 371
  • 3
  • 11

1 Answers1

0

There's the LiveBroadcasts.transition API endpoint, that allows to change the status of your already created broadcast.

Issue the following curl command (exemplified below in bash's syntax), for to change the status of the broadcast identified by $BROADCAST_ID to live:

$ curl \
--request POST \
--header "Authorization: Bearer $ACCESS_TOKEN" \
"https://www.googleapis.com/youtube/v3/liveBroadcasts/transition?part=id,snippet,contentDetails,status&broadcastStatus=live&id=$BROADCAST_ID"

As per the official specification:

broadcastStatus (string)

The broadcastStatus parameter identifies the state to which the broadcast is changing. Note that to transition a broadcast to either the testing or live state, the status.streamStatus must be active for the stream that the broadcast is bound to.
[...]

prior to call this endpoint, you'll have to have your stream be active already.

Also, depending of the way you interact programmatically with your broadcast, you may well need have your broadcast set to automatic restart, via the respective broadcast property enableAutoStart.

stvar
  • 6,551
  • 2
  • 13
  • 28
  • I tried this, and it doesn't seem to work. I started with a stream that is active, created a broadcast with enableAutoStart=true, called bind to add the stream to the broadcast. verified the broadcast had the active streamId, and it had lifeCycleStatus=ready. (enableAutoStart I guess only works if the stream transitions and is not already running?) I then attempted to transition broadcastStatus=live with the call you suggested, though get a 403 --> Invalid Transition. – me_online May 18 '21 at 18:25
  • Have you first transitioned to `testing` and, after `lifeCycleStatus` became `testing`, transition to `live`? There's an official document that implies this sequence of events: [Life of a Broadcast](https://developers.google.com/youtube/v3/live/life-of-a-broadcast). – stvar May 18 '21 at 19:22
  • Yes I tried the call to move it to testing, which gave the same 403 error. curl --request POST H "Authorization: Bearer XXXX" "https://www.googlea pis.com/youtube/v3/liveBroadcasts/transition?part=id,snippet,contentDetails,status&broadcastStatus=testing&id=z--Lm8b1mU0" { "error": { "code": 403, "message": "Invalid transition", "errors": [ { "message": "Invalid transition", "domain": "youtube.liveBroadcast", } ] } } – me_online May 18 '21 at 19:47
  • I added more details on the problem in this question, since it's hard to fit it in a comment here. https://stackoverflow.com/questions/67592373/youtubedata-api-v3-transition-of-ready-to-live-broadcast-fails-with-an-acti – me_online May 18 '21 at 19:49