Overview

The Multistream API allows a source stream and transcoded renditions to be pushed to multiple RTMP(S) or SRT targets, such as Facebook Live, Twitch, and Youtube Live.

To add, manage, and delete Multistream Targets, navigate to the Streams page (livepeer.com/dashboard/streams) and click on a stream name. On the stream detail page, on the Overview tab, you can view all configured targets. You must configure new Multistream Targets for each stream. This will apply the multistream configuration to that stream. Multistream Targets do not carry over when you create new streams.

To add a new target, select Create on the right side of the Multistream Targets section. You'll be asked to name your target, provide the Ingest URL and a stream key, being Ingest URL the only required value. The Ingest URL and stream key should be provided by the platform that you're streaming into and can be of the RTMP, RTMPS or SRT protocols. Select the rendition profile that you'd like to send to that target and click Create Target. Once created, you can toggle the targets on and off.

To edit a Mulitstream Target, click on the three dots to the right of the target name and then on Edit to open up the target settings. Select Update target when you've completed your changes.

To delete a multistream target, click on the three dots to the right of the target name and then on Delete.

Note: Any changes to Mulitstream Targets, including creating new targets, will apply only to the next active session. If you make changes while a stream is active, those changes will not apply until the current session has ended and a new session begins.

You can also manage Multistream Target objects from the API. Each target represents a specific endpoint where a stream could be multistreamed to. More details in the API reference.

Notice that the existence of a Multistream Target object itself is not enough for the multistream to happen. You also need to reference the target from the Stream object that should be multistreamed. To avoid managing the separate Multistream Target objects, you can also create the targets inlined in the Stream creation and update APIs. Check the Stream Object section for more information.

Create

Request: POST /api/multistream/target
curl -X POST 'https://livepeer.com/api/multistream/target' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
    "name": "Eli\'s Twitch",
    "url": "rtmp://rtmp.twitch.tv/live/SECRET"
}'

Supported Protocols: RTMP, RTMPS and SRT.

Response
{
  "id": "{id}",
  "userId": "USER123",
  "name": "Eli's Twitch",
  "url": "rtmp://rtmp.twitch.tv/live/SECRET"
}

Read

You can fetch a specific Multistream Target with their ID, returned on the creation request. The destination url will not be returned since it contains sensitive user data. This way the application developer doesn't have to worry about storing and securing their users' stream keys.

Request: GET /api/multistream/target/{id}
curl 'https://livepeer.com/api/multistream/target/{id}' \
-H 'authorization: Bearer {api-key}'
Response
{
  "id": "{id}",
  "userId": "USER123",
  "name": "Eli's Twitch"
}

You can also list all existing Multistream Targets in the account by omitting the {id} segment in the above request.

List Request: GET /api/multistream/target
curl 'https://livepeer.com/api/multistream/target' \
-H 'authorization: Bearer {api-key}'

The response is an array of Multistream Target objects, as returned from the read API above. The pagination should be done exactly the same as the other Livepeer.com list APIs.

Update

You can change an existing target properties at will, and it will affect any stream that is currently using it. Notice that changes will only take effect when the next stream session is started.

One of the updateable properties is the disabled field. It can be used to disable multistreaming to a specific target without the need of removing them from streams nor deleting the target completely.

Request: PATCH /api/multistream/target/{id}
curl -X PATCH 'https://livepeer.com/api/multistream/target/{id}' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
    "name": "Not Eli\'s Twitch",
    "url": "rtmp://rtmp.twitter.com/SECRET",
    "disabled": true
}'

All request fields are optional. There is no response on a success (HTTP 204 No Content).

Delete

Finally, you can also delete a Multistream Target object completely by calling the delete API. You should not do this if any Streams are still referencing that target or a broken reference will be left. So first update (PATCH) any Stream removing the reference to the Multistream Target and only then actually delete it.

Request: DELETE /api/multistream/target/{id}
curl -X DELETE 'https://livepeer.com/api/multistream/target/{id}' \
-H 'authorization: Bearer {api-key}'

There is no response on a success (HTTP 204 No Content).

To actually use a Multistream Target, you need to reference it from a Stream object.

The reference is made in the targets sub-field of the multistream field in the Stream resource (stream.multistream.targets[]). It is represented as an array of target reference objects, each with a profile that should be multistreamed and the id of the corresponding Multistream Target.

The profile field must reference an existing transcoding profile on the same stream, or "source" to multistream the same original video as ingested. The same profile can be mulsitreamed to several Multistream Targets, but there can be only 1 multistream to a given URL. You can also set the videoOnly field to true to mute the stream audio and stream only a silent video to the target.

To avoid managing separate Multistream Target objects, you can also create targets inlined in the Stream object on the same mutation request (create or update). In that case, the target reference object in the multistream.targets field should have a spec instead of an id with the payload for creating a new Multistream Target. Notice that spec is a write-only field, meaning that Stream objects returned from reads (GET) will always have only a profile and id in the targets. To get the current state of a Multistream Target, fetch from its own read API using that id.

Creating a Stream with Multistream Targets

You can create a Stream already with some Multistream Targets. Either reference an existing Multistream Target by id or create a new Multistream Target inline with the spec field. You can also use both types of targets on the same payload (reference and inline) as long as they are separate entries in the multistream.targets array.

By Reference
curl -X POST 'https://livepeer.com/api/stream' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
    "name": "test_multistream_reference",
    "profiles": [
      { "name": "720p", ... },
      { "name": "480p", ... },
      { "name": "360p", ... }
    ],
    "multistream": {
      "targets":  [
        { "id" :"0bf161f3-95bd-4971-a7b1-4dcb5d39e78a", "profile": "source" },
        { "id" :"95bd0bf1-61f3-a7b1-4971-39e78a4dcb5d", "profile": "720p" }
      ]
    }
}'
Inline
curl -X POST 'https://livepeer.com/api/stream' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
    "name": "test_multistream_reference",
    "profiles": [
      { "name": "720p", ... },
      { "name": "480p", ... },
      { "name": "360p", ... }
    ],
    "multistream": {
      "targets": [
        {
          "profile": "720p",
          "videoOnly": true,
          "spec": {
            "name": "Eli\'s Twitch",
            "url": "rtmp://rtmp.twitch.tv/live/SECRET"
          }
        },
        {
          "profile": "360p",
          "spec": { "url": "rtmp://rtmp.twitter.com/SECRET" }
        }
      ]
    }
}'

Updating Multistream Targets of a Stream

You can also update an existing Stream to add or remove Multistream Targets. The schema of all fields is the same as the creation API, with the targets being referenced with an id or created inline with a spec. You can also add, remove or update multiple Multistream Targets on the same API call.

Notice that changes to an existing Stream will only take effect when the next stream session is started.

Adding Multistream Targets

Since you can combine inlined and referenced Multistream Targets on the same request, it's really easy to add a target by URL to an existing stream:

1. GET the current state of the Stream
curl 'https://livepeer.com/api/stream/{id}' \
-H 'authorization: Bearer {api-key}'
{
  "name": "test_multistream_reference",
  "profiles": [
    { "name": "720p", ... },
    { "name": "480p", ... },
    { "name": "360p", ... }
  ],
   "multistream": {
     "targets":  [
       { "id" :"0bf161f3-95bd-4971-a7b1-4dcb5d39e78a", "profile": "source" },
       { "id" :"95bd0bf1-61f3-a7b1-4971-39e78a4dcb5d", "profile": "720p" }
     ]
   }
}
2. PATCH the Stream with the new target
curl -X PATCH 'https://livepeer.com/api/stream/{id}' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
     "multistream": {
        "targets":  [
          { "id" :"0bf161f3-95bd-4971-a7b1-4dcb5d39e78a", "profile": "source" },
          { "id" :"95bd0bf1-61f3-a7b1-4971-39e78a4dcb5d", "profile": "720p" },
          { "profile": "720p", "spec": {"url": "rtmp://rtmp.twitter.com/SECRET"} }
        ]
      }
    }'

The PATCH can also add new Multistream Targets by id instead of inline, just like on Stream creation.

Removing Multistream Targets

To remove a Multistream Target from a Stream, you can use the same PATCH request as above to either remove or completely clear the multistream.targets array.

After removing the reference from the Stream, you can also delete the Multistream Target object completetly by calling the separate Delete Multistream Target API. Make sure that no other Stream has a reference to that Multistream Target before doing so.

Removing a single Multistream Target

To remove a specific target, we need to make a PATCH request maintaining only the targets that we want to keep in the stream, after removing the desired one.

e.g.: Removing only the first target from the example above:

curl -X PATCH 'https://livepeer.com/api/stream/{id}' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
     "multistream": {
        "targets":  [
          { "id" :"95bd0bf1-61f3-a7b1-4971-39e78a4dcb5d", "profile": "720p" }
        ]
      }
    }'

We kept only the remaining targets in the PATCH, i.e. the second one.

You can also use a single API call to change the profile that should be multistreamed to a specific target. For that, just change the profile field for the given target when building the PATCH request payload.

Removing all Multistream Targets
curl -X PATCH 'https://livepeer.com/api/stream/{id}' \
-H 'content-type: application/json' \
-H 'authorization: Bearer {api-key}' \
-d '{
     "multistream": {
        "targets":  []
      }
    }'

While a session is active that has multistream targets configured, you'll be able to see if a destination is "Active" or "Offline". NOTE: There may be a slight delay between starting the stream and the push destinations connecting. When starting to stream to multistream targets, use these indicators to understand whether it has connected to its target(s).

On the stream page where you've configured your multistream targets, select the "Health" tab at the top. While a session is active, you'll see the ingest rate of the source stream.

We have 3 webhooks to help you monitor the state of your Multistream Targets::

  • multistream.connected: When we have successfully connected to the Multistream Target and you're also online in the other service you are multistreaming to.

  • multistream.error: In case any error has occurred during connection to the Multistream Target. This means some kind of problem with the configuration or the other service you are multistreaming to.

  • multistream.disconnected: Sent after a stream is ended to indicate that Multistream has also ended for the respective target.

For more information on how to use webhooks, please consult our Webhooks Documentation.