Livepeer

Livepeer API Documentation

Livepeer supports live streaming, video on demand, and transcoding across video formats and protocols. The Livepeer API provides a secure, straightforward way to transcode video using Livepeer infrastructure. Please note that the Livepeer API product is under heavy development with new features added regularly.

API Endpoints

https://livepeer.com/api/stream

  • POST /stream - create a stream (Protected by Bearer API key auth)
  • GET /stream/:id - getting streams by ID (Protected by Bearer API key auth)

https://livepeer.com/api/broadcaster

  • GET /api/broadcaster a list of broadcasters

{broadcaster_url}/live/{stream_id}/{media_number}.ts

  • POST https://{broadcaster_url}/live/{stream_id}/{media_number}.ts MPEG-TS segment ingest point after getting the broadcaster URL (using POST)
  • This endpoint also works for .mp4 files. We recommend sending .mp4 files that are less than 120 seconds.

API Tutorial

In this tutorial you will transcode one source .ts segment into three renditions for playback. By the end of this tutorial, you will have an understanding of the basic Livepeer API calls and expected responses. And from there, you can start integrating your own platform with Livepeer's live transcoding service. Let's begin!

Note: this tutorial is most fitting for developers working on media servers or video services that involves transcoding. If you are building a video application, please refer to the Live Streaming API

Step 1: Create a "stream" with the transcoding profiles you want by sending POST to /stream with name and profiles. For example:

curl -X POST \
-H 'content-type: application/json' \
-H 'authorization: Bearer <API_KEY>' \
-d '{
"name": "test_stream",
"profiles": [
{
"name": "1080p",
"bitrate": 6000000,
"fps": 30,
"width": 1920,
"height": 1080
},
{
"name": "720p",
"bitrate": 2000000,
"fps": 30,
"width": 1280,
"height": 720
},
{
"name": "360p",
"bitrate": 500000,
"fps": 30,
"width": 640,
"height": 360
}
]
}' \
https://livepeer.com/api/stream

You will get back a json response that includes an id field. This represents the ID of the stream. You will need this later.

Step 2: Request a list of Livepeer broadcasters address from /broadcaster. For example:

curl https://livepeer.com/api/broadcaster \
-H "authorization: Bearer <API_KEY>"

You will get back a list of json objects that represent a list of broadcaster addresses. Pick any of the broadcaster addresses to send the source .ts segment.

Step 3: Now it's time to POST your .ts segment. to {broadcaster_address}/live/{stream_id}/{media_number}.ts, and get your results.

In this example, we will use munpack to unpack the multipart API response. To install munpack, use brew install mpack for macos, and apt install mpack for Linux.

Set Accept: multipart/mixed headers. A continuous livestream should start with the media_number set to 1.ts and count upward to 2.ts, 3.ts and so on for each segment.

Here is an example using the broadcaster address https://test-broadcast-url.live. You'll need to replace that URL a broadcaster address from Step 2.

curl -i -X POST https://test-broadcast-url.live/live/<stream_id>/1.ts \
-H "Accept: multipart/mixed" \
--data-binary "@source_segment.ts" | munpack

You should see 1080p_1.ts, 720p_1.ts, and 360p_1.ts in your directory. You should be able to play the separate .ts files using any video player. For example, ffplay 1080p_1.ts

Note: If there is a problem uploading a segment, you can try to make a new request for a list of broadcasters and POST to a different broadcaster address. You can still expect the stream to be at the same URL.

if you don't see 1080p_1.ts, 720p_1.ts, and 360p_1.ts most likely there was an issue with the request you sent. Please visit our support channel on Discord, or email [email protected].

You can save the response directly to a file if you don't pipe in into munpack. The content of the API response looks something like:

HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: openresty/1.15.8.2
Date: Mon, 27 Apr 2020 22:07:17 GMT
Content-Type: multipart/mixed; boundary=83212f107a67f532dbdc
Transfer-Encoding: chunked
Connection: keep-alive
Strict-Transport-Security: max-age=15724800; includeSubDomains
--83212f107a67f532dbdc
Content-Disposition: attachment; filename="1080p_101.ts"
Content-Length: 459284
Content-Type: video/MP2T
Rendition-Name: 1080p
...Data
--83212f107a67f532dbdc
Content-Disposition: attachment; filename="720p_101.ts"
Content-Length: 459284
Content-Type: video/MP2T
Rendition-Name: 720p
...Data
--83212f107a67f532dbdc
Content-Disposition: attachment; filename="360p_101.ts"
Content-Length: 459284
Content-Type: video/MP2T
Rendition-Name: 360p

Live Streaming API

You can send an RTMP video stream to the Livepeer API and get the transcoded HLS video stream. You can serve the transcoded outputs through a CDN or save them for future use.

Livepeer is currently testing this feature with select beta users. If you would like to use this today, email [email protected].

Looking for the open source project?

Go to https://livepeer.readthedocs.io.

Livepeer
16 Vestry St, Floor 4
New York, NY
10013
Privacy Policy