Create a live stream and connect live video

🚧

Development on our current live streaming product (v.1.0) is paused.

We are focusing on building a new end-to-end live streaming product (v.2.0).
All current live streaming functionality will continue to work as expected.

Creating a live stream is simple with api.video. After you create it, you have a variety of options for connecting live video and beginning broadcasting. This guide will cover how to set up your live stream with api.video and then use OBS to broadcast.

Associated API reference documentation

Choose an api.video client

The clients offered by api.video include:

Installation

To install your selected client, do the following:

go get github.com/apivideo/api.video-go-client
composer require api-video/php-api-client
npm install @api.video/nodejs-client --save

...or with yarn: 
  
yarn add @api.video/nodejs-client
pip install api.video
Using Nuget
  
Install-Package ApiVideo

Retrieve your API key

You'll need your API key to get started. You can sign up for one here: Get your api.video API key!. Then do the following:

  1. Log in to the api.video dashboard.
  2. From the list of choices on the left, make sure you are on API Keys
  3. You will always be able to choose to use your Sandbox API key. If you want to use the Production API key instead, enter your credit card information.
  4. Grab the key you want, and you're ready to get started!

Create a live stream container

The first part of setting up your live stream to broadcast is to create a live stream container. Once you create the container, you can use it for live streaming. Here is the code to create the container:

curl --request POST \
     --url https://ws.api.video/live-streams \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2NDI4MTQxNDUuMjE2Mzc2LCJuYmYiOjE2NDI4MTQxNDUuMjE2Mzc2LCJleHAiOjE2NDI4MTc3NDUuMjE2Mzc2LCJwcm9qZWN0SWQiOiJwclJ6SUpKQTdCTHNxSGpTNDVLVnBCMSJ9.GSDqqMzBxo-wOwl9IVbOnzevm8A6LSyaR5kxCWUdkEneSU0kIdoNfhwmXZBq5QWpVa-0GIT8JR59W6npNO-ayhaXmV3LA6EQpvv0mHd_dAhg3N8T96eC0ps0YIrkmw0_Oe6iRgEDI-wJ9nc6tQWi9ybbMHi1LDBjxW4rbFlq7G59C1QZGabd14QO7uqAUUSNqHC1l42z_m7BTK1AhFiBEXmMcfW7X0VmGcaEUy7NiNda8rmq_nrdvkxgN8KHguXzxMsw_4GE_d0eQwHcZvS1q-FebI6b8AoqpoltFOZvUACCrfXH_D_UPshHuJM3apXbD2dg_zQicc8oWBHVGiobLQ' \
     --header 'Content-Type: application/json' \
     --data '
{
     "record": false,
     "name": "My Live Stream",
     "public": true,
     "playerId": "pt240hxAaDBLCYxUIPh0Fb2"
}
'
package main

import (
    "context"
    "fmt"
    "os"
    apivideosdk "github.com/apivideo/api.video-go-client"
)

func main() {
    client := apivideosdk.ClientBuilder("YOUR_API_TOKEN").Build()
    // if you rather like to use the sandbox environment:
    // client := apivideosdk.SandboxClientBuilder("YOU_SANDBOX_API_TOKEN").Build()
        
    liveStreamCreationPayload := *apivideosdk.NewLiveStreamCreationPayload("My Live Stream Video") // LiveStreamCreationPayload | 

    
    res, err := client.LiveStreams.Create(liveStreamCreationPayload)

    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `LiveStreams.Create``: %v\n", err)
    }
    // response from `Create`: LiveStream
    fmt.Fprintf(os.Stdout, "Response from `LiveStreams.Create`: %v\n", res)
}
<?php
require __DIR__ .'/vendor/autoload.php';

use Symfony\Component\HttpClient\Psr18Client;
use ApiVideo\Client\Client;
use ApiVideo\Client\Model\LiveStreamsApi;

$apiKey = 'your API key here';
$apiVideoEndpoint = 'https://ws.api.video';

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new ApiVideo\Client\Client(
    $apiVideoEndpoint,
    $apiKey,
    $httpClient
);

$payload =(new \ApiVideo\Client\Model\LiveStreamCreationPayload())->setName("Live Stream")->setPublic(true);
$livestream = $client->liveStreams()->create($payload);
const ApiVideoClient = require('@api.video/nodejs-client');

(async () => {
    try {
        const client = new ApiVideoClient({ apiKey: "YOUR_API_TOKEN" });

        const liveStreamCreationPayload = {
            name: "My Live Stream Video", // Add a name for your live stream here.
            record: true, // Whether you are recording or not. True for record, false for not record.
            _public: true, // BETA FEATURE Please limit all public = false (\"private\") livestreams to 3,000 users. Whether your video can be viewed by everyone, or requires authentication to see it. A setting of false will require a unique token for each view.
            playerId: "pl4f4ferf5erfr5zed4fsdd", // The unique identifier for the player.
        }; 

        // LiveStream
        const result = await client.liveStreams.create(liveStreamCreationPayload);
        console.log(result);
    } catch (e) {
        console.error(e);
    }
})();
# Create a live stream. 
import apivideo
from apivideo.apis import LiveStreamsApi
from apivideo.exceptions import ApiAuthException

api_key = "your api key here"

client = apivideo.AuthenticatedApiClient(api_key)

# If you'd rather use the sandbox environment:
# client = apivideo.AuthenticatedApiClient(api_key, production=False)

client.connect()

live_stream_api = LiveStreamsApi(client)

live_stream_creation_payload = {
    "record": False,
    "name": "My live stream"
}

# Create the live stream
response = live_stream_api.create(live_stream_creation_payload)
print(response)

Connect live video to your live stream container

You'll want to grab your live stream's streamKey from the response. It's required for use with OBS. To get started:

  1. Install OBS if need be. You can grab the software here: OBS Studio

  2. Establish a source. In the sources section, choose a video feed to share. You could choose to share your screen or to share your camera (on a Mac: Video Capture Device, and then in the "Device" dropdown, select the camera). You should now see the video source in the main OBS window.

  3. Connect OBS to api.video. Under Settings, choose Stream. You'll see a choice for service - select custom.

  4. The server should be rtmp://broadcast.api.video/s, and the streamKey is the value you received in the JSON response when you created the stream.

  5. Click OK to accept the changes.

  6. Press Start Streaming.

  7. Share the embed, iFrame, so that others can watch your stream!

Live stream immediately from your dashboard

If you don't want to set up your live stream programmatically, api.video allows you to demo live streaming from the dashboard with the click of a button. Do the following:

  1. Log in to your dashboard.

  2. Click Start live stream. You'll get a pop up like this:

964964
  1. The pop-up contains all the live stream information you'll need if you choose to broadcast using something else like OBS. You can pause the live stream at any time by clicking pause on the video. If you don't see your live stream start right away, give it a few minutes to get ready.

Conclusion

There are many ways to set up a live stream. OBS is one of the most popular ways to get started.


Did this page help you?