Create Livestream - Publishing Stream To LiveAPI

This page explains how to create a live stream and broadcast them to your audience from LiveAPI.

There are 2 steps for pushing a live stream:

1. Sending stream source to LiveAPI

There are 2 ways for sending a stream source to LiveAPI:

  • Publishing or pushing stream using encoders. This will be explained in the latter part of the article.
  • Pulling an existing stream to LiveAPI using a supported URL. This feature is in development and will be released in a couple of weeks. Follow our changelog to know when it's released.

2. Broadcast the stream to your audience

Once LiveAPI has received your stream source, there are 2 ways to broadcast the stream to your audience, including:

  • Use our out-of-the-box player to embed it on your website or application conveniently. We use Theo Player as our default player, so you have a wide range of options to customize the player and integrate analytics according to your need. Learn more about using the player here.

  • Stream to 3rd party platforms such as Facebook or Youtube using RTMP ingest. Learn more how to do it here.

Before you start

You will need access to LiveAPI Access Token. Refer to the Authentication in LiveAPI section to learn how to generate an access token via the LiveAPI dashboard.

Also, if you're not already using an encoder or similar software/hardware to send the stream source to LiveAPI, you can try to check out some suggested encoders here. For the purpose of demonstration, in this article, we will use OBS, which is a free and open-source software for video recording and live streaming.

Create a livestream

Live stream objects can easily be created by sending a request to the Create a new Livestream endpoint.

Sample request:

curl --location --request POST 'https://api.liveapi.com/live_streams' \
--header 'Content-Type: application/json;charset=UTF-8' \
--header 'Authorization: {your_authentication}'

The endpoint returns a Live Stream object with the ingest information: server and key for putting into your encoder. It also returns all playback URLs and additional information about the Livestream.

You can refer to POST /live_streams article for a detailed explanation of each field in the response.

Sample Response:

{
    "_id": "621c8dda6ebae022f13ee87u",
    "enabled": true,
    "ingest": {
        "server": "rtmp://ingest.liveapi.com/static",
        "key": "lv_16833a90987411ecb1de8570eafe89432?password=1bda8f83"
    },
    "playback": {
        "embed_url": "https://player.liveapi.com/lv_16833a90987411ecb1de8570eafe89432",
        "embed_audio_url": "https://player.liveapi.com/lv_16833a90987411ecb1de8570eafe89432?onlyAudio=true",
        "hls_url": "https://live.liveapi.com/620e0ba1ce8f11ddde571d1c/lv_16833a90987411ecb1de8570eafe89432/index.m3u8"
    },
    "platforms": [],
    "settings": {
        "pulling_mode": {}
    },
    "user": "620e0ba1ce8f11ddde571ve3",
    "environment": "production",
    "organization": "620e0ba2ce8f11ddde57143d",
    "creation_time": "2022-02-28T08:54:50.339Z"
}

Start broadcasting

LiveAPI uses the Real-Time Messaging Protocol (RTMP) as a communication protocol for live streaming the data over the Internet. You can use both software and hardware encoders to broadcast the Livestream.

To broadcast a live stream, you must pass the ingest.server URL and the ingest.key value returned by the Create Live Stream URL to your encoding device and stream live video data to it.

"ingest": {
        "server": "rtmp://ingest.liveapi.com/static",
        "key": "lv_16833a90987411ecb1de8570eafe89432?password=1bda8f83"
    }

In our example here, we will demonstrate broadcasting the live video using the Open Broadcaster Software (OBS):

13421342

Adding server and stream key to OBS.

Once the Server and Stream Key are added, you are ready to go live, make sure you have selected stream sources in your OBS and click Start Streaming to start sending data to LiveAPI.

13521352

Check stream source and Start streaming.

Then you can watch your stream in action by using one of the playback options provided in the response.

  • For embed_url and embed_audio_url, you can open them directly with any browser.
  • For hls_url, you can open them via VLC (Open network stream option) or use any HLS player online such as Castr HLS player.
"playback": {
        "embed_url": "https://player.liveapi.com/lv_16833a90987411ecb1de8570eafe89432",
        "embed_audio_url": "https://player.liveapi.com/lv_16833a90987411ecb1de8570eafe89432?onlyAudio=true",
        "hls_url": "https://live.liveapi.com/620e0ba1ce8f11ddde571d1c/lv_16833a90987411ecb1de8570eafe89432/index.m3u8"
    }

Stop Broadcasting

Once you are done with the live streaming, you can stop the encoder, and the stream will be automatically disconnected from the LiveAPI server.

For emergency stop, you can call the Update Livestream endpoint and set the enabled parameter to false then the stream will stop receiving stream data from the encoder immediately.

Webhook supported for Livestream

You can get a list of webhook events we supported for Livestream here.


What’s Next