Quick Start: Using RTMP Outputs for Live Events

Product(s)
Live
Role(s)
API Developer
Topic(s)
Live Streaming
API(s)
Live API

This tutorial will walk you through creating RTMP outputs to set up live events on YouTube Live and Facebook Live.

Overview

general-block-diagram
Block Diagram

This tutorial explains at the API level how to create a live streaming job in Brightcove live and then create RTMP outputs and re-stream them to YouTube Live and Facebook Live.

This tutorial will use curl to make the API requests, but you can easily make them in Insomnia, Postman or other REST clients instead.

Create a live job

First, we will create a live job. You will need an API-KEY for the Live API. If you do not, and are interested in obtaining access, please contact your account manager.

  1. Copy and paste the following curl command into a text editor:

    curl -X POST \
      https://api.bcovlive.io/v1/jobs \
      -H 'Content-Type: application/json' \
      -H 'x-api-key: {{bcov-live-api-key}}' \
      -d '{
        "live_stream": true,
        "region": "{{closest-region-encoder}}",
        "outputs": [{
          "label": "hls360p",
          "live_stream": true,
          "height": 360,
          "video_bitrate": 365,
          "segment_seconds": 6,
          "keyframe_interval": 60
        },
        {
          "label": "hls432p",
          "live_stream": true,
          "height": 432,
          "video_bitrate": 730,
          "segment_seconds": 6,
          "keyframe_interval": 60
        },
        {
          "label": "hls540p",
          "live_stream": true,
          "height": 540,
          "video_bitrate": 2000,
          "segment_seconds": 6,
          "keyframe_interval": 60
        },
        {
          "label": "hls720p3M",
          "live_stream": true,
          "height": 540,
          "video_bitrate": 2000,
          "segment_seconds": 6,
          "keyframe_interval": 60
        },
        {
          "label": "hls720p4.5M",
          "live_stream": true,
          "height": 540,
          "video_bitrate": 4500,
          "segment_seconds": 6,
          "keyframe_interval": 60
        }]
      }'
    
  2. Replace:

    • {{closest-region-encoder}} with the closest available region to your encoder, see closest available regions to your encoder. For instance: us-west-2
    • {{bcov-live-api-key}} with your Brightcove live API key. For example: abcdfeg-this-is-a-fake-api-key-FgJajjasd12hJHsZ
  3. After making those changes, copy and paste the code into Terminal or whatever command-line app you use and run it.
  4. The response should be something like this:

    {
        "id": "3b6871bf2f344acaa6b397d09b476018",
        "outputs": [... removed for simplicity ...],
        "stream_url": "rtmp://ep1-usw2.bcovlive.io:1935/3b6871bf2f344acaa6b397d09b476018",
        "stream_name": "alive",
        "static": false,
        "encryption": {},
        "playback_url": "https://bcovlive-a.akamaihd.net/3b6871bf2f344acaa6b397d09b476018/us-west-2/NA/playlist.m3u8",
        "playback_url_dvr": "https://bcovlive-a.akamaihd.net/3b6871bf2f344acaa6b397d09b476018/us-west-2/NA/playlist_dvr.m3u8"
    }

This jobs will create 5 renditions based on Apple recommendations.

Configure your encoder

The steps shown here will assume an Elemental live box encoder, which was used in testing the steps for this tutorial. If you have a different encoder, the settings should be similar.

The most important settings for this case are:

  • Configure timecode source as "system clock"
  • Set "OnFi timecode frequency" to 1
  • Check "time code insertion" inside video
  • Strongly recommended: Framerate = follow source

This is the config we used for this experiment:

elemental-live-job-config
Elemental live config

Test playback

You can use this VideoJS HLS demo page to test playback, just paste the value playback_url returned in the creation job response:

videojs-hls-playback
VideoJS HLS playback demo page

Add the live stream to YouTube live

We are assuming here that you have a YouTube account enabled for live streaming.

  1. Click go live, and you should see:

    youtube-go-live
    YouTube go live
  2. Click on "Encoder live streaming":

    youtube-encoder-live
    YouTube encoder live source
  3. Configure your live event YouTube metadata and use the "Encoder set up" data to connect the Brightcove live stream to YouTube:

    youtube-encoder-setup
    YouTube encoder setup
  4. Now that we have YouTube live set up, we will create the RTMP output for it from our Live job.

  5. Copy the curl command below into a text editor:

    curl -X POST \
      https://api.bcovlive.io/v1/jobs/{{bcov-live-job-id}}/rtmpouts \
      -H 'Content-Type: application/json' \
      -H 'x-api-key: {{bcov-live-api-key}}' \
      -d '{
      "url": "rtmp://a.rtmp.youtube.com/live2/{{youtube-secret-stream-name}}"
    }'
  6. Replace:

    • {{bcov-live-job-id}} with your Brightcove live job id. In our example this value would be 3b6871bf2f344acaa6b397d09b476018 - your value, from the response to your request to create the live job , will be different.
    • {{bcov-live-api-key}} for your Brightcove live API key. For instance: abcdfeg-this-is-a-fake-api-key-FgJajjasd12hJHsZ
    • {{youtube-secret-stream-name}} for the stream name / key that YouTube provides
  7. Paste the edited code into your command-line app and run it.
  8. The response should be something like this:

    {
              "connection_info": {
                "host": "a.rtmp.youtube.com",
                "port": 1935,
                "application": "live2",
                "streamName": "{{youtube-secret-stream-name}}"
              },
              "duration_history": [],
              "rtmp_out_id": "27aacdfa5bcf4436ade0519e6a748aba",
              "stream_start": 1542902218238
            }
  9. To test YouTube playback you can go to YouTube my channel:

    youtube-my-channel-playback
    YouTube my channel playback

Add the live stream to Facebook live

We are assuming here that you have a Facebook account enabled for live streaming.

  1. Click Live video

  2. Click connect and stream key to get the data needed to connect your Brightcove live job:

    facebook-live-config
    Facebook live config
  3. Next, create live output for Brightcove live job using "server url" and "stream key" from Facebook. Copy the curl command below and paste it into a text editor:

    curl -X POST \
      https://api.bcovlive.io/v1/jobs/{{bcov-live-job-id}}/rtmpouts \
      -H 'Content-Type: application/json' \
      -H 'x-api-key: {{bcov-live-api-key}}' \
      -d '{
      "url": "rtmp://live-api-s.facebook.com:80/rtmp/{{facebook-secret-stream-name}}"
    }'
  4. Replace:

    • {{bcov-live-job-id}} with your Brightcove live job id. In our example this value would be 3b6871bf2f344acaa6b397d09b476018 - your value, from the response to your request to create the live job , will be different.
    • {{bcov-live-api-key}} with your Brightcove live API key. For instance: abcdfeg-this-is-a-fake-api-key-FgJajjasd12hJHsZ
    • {{facebook-secret-stream-name}} with you stream name that Facebook gives you
  5. The response should be something like this:

    {
      "connection_info": {
          "host": "live-api-s.facebook.com",
          "port": 80,
          "application": "rtmp",
          "streamName": "{{facebook-secret-stream-name}}"
      },
      "duration_history": [],
      "rtmp_out_id": "59323c3d1e2b44748755853193fb126c",
      "stream_start": 1542904101097
    }
  6. To test your Facebook Live stream, click "Go Live" on your Facebook webpage.

    facebook-playback