Zencoder Live Streaming HLS to S3 Quickstart

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

There are a lot of moving parts involved in setting up a production-grade live stream, such as a player and a CDN for distribution. If you're just looking to try out Zencoder's Live service, you can get started by just publishing HLS outputs to Amazon S3. Although this setup isn't ideal for production, it's a great way to get a feel for Live.

Requirements

To use this guide you'll need:

Introduction

We'll start by sending an API request to Zencoder, which will respond with a stream url and name. We'll then use Flash Media Live Encoder (FMLE) to publish an RTMP stream. Zencoder will encode the stream and upload the HLS outputs to S3 as specified in the original API request. When we're done, you'll be able to watch your stream via players that support HLS.

S3 Setup

You'll need an S3 bucket, so let's set that up now. You can create a new bucket or use an existing one, but keep in mind that you'll be uploading quite a few files into it. In order to allow Zencoder to upload to your S3 bucket, you'll need to add your S3 access key and secret under credentials. Make note of the nickname used as you'll be using this to reference those credentials in the request.

Send the API request

Copy this API request and paste it into the Request Builder, then edit the S3 bucket for each output to be your own.

{
    "live_stream": true,
    "outputs": [
        {
            "label": "hls_300",
            "size": "480x270",
            "video_bitrate": 300,
            "url": "s3://YOUR_S3_BUCKET/awesomeness_300.m3u8",
            "credentials": "s3",
            "type": "segmented",
            "live_stream": true,
            "headers": { "x-amz-acl": "public-read" }
        },
        {
            "label": "hls_600",
            "size": "640x360",
            "video_bitrate": 600,
            "url": "s3://YOUR_S3_BUCKET/awesomeness_600.m3u8",
            "credentials": "s3",
            "type": "segmented",
            "live_stream": true,
            "headers": { "x-amz-acl": "public-read" }
        },
        {
            "label": "hls_1200",
            "size": "1280x720",
            "video_bitrate": 1200,
            "url": "s3://YOUR_S3_BUCKET/awesomeness_1200.m3u8",
            "credentials": "s3",
            "type": "segmented",
            "live_stream": true,
            "headers": { "x-amz-acl": "public-read" }
        },
        {
            "url": "s3://YOUR_S3_BUCKET/master.m3u8",
            "credentials": "s3",
            "type": "playlist",
            "streams": [
            {
                "bandwidth": 300,
                "path": "awesomeness_300.m3u8"
            },
            {
                "bandwidth": 600,
                "path": "awesomeness_600.m3u8"
            },
            {
                "bandwidth": 1200,
                "path": "awesomeness_1200.m3u8"
            }
        ],
        "headers": { "x-amz-acl": "public-read" }
    }
    ]
}

This request will create a live stream with 3 HLS outputs targeting different bitrates and an adaptive-bitrate playlist. The adaptive-bitrate playlist will allow devices that support HLS to switch between streams depending on available bandwidth.

Once you've replaced all the instances of YOUR_S3_BUCKET in the request, click "Execute". You should see a successful response appear at the bottom of the page.

successful request

Streaming from FMLE

Now we will set up streaming from Flash Media Live Encoder (FMLE).

Copy the stream URL and stream name into the text fields labeled "FMS URL" and "Stream" in FMLE and click "Connect." You should see the "Connect" button change to "Disconnect". Your stream out of FMLE should at least be the same bandwidth as your highest quality output, so set "Input Size" to 1280x720, "bitrate" to 1200, and "output size" to 1280x720.

Connect FMLE

If you're on a slower internet connection, you may need to adjust these settings to account for having less bandwidth available. Click "Start" and you should see "Streaming to Primary" in the bottom left hand corner.

success!

Your stream is now being uploaded to Zencoder, where it is encoded into the 3 outputs we specified earlier and uploaded to S3. To view the stream, simply open the master playlist we created in any player that supports HLS. From Quicktime you can open an HLS stream by going to File > Open Location or you can pull the stream up in Safari. Your URL should look like this: http://YOUR_S3_BUCKET.s3.amazonaws.com/master.m3u8; just replace the S3 bucket with your own.

There you have it! You should now be streaming an incredibly exciting video of yourself live on the internet. We'll go over adding an RTMP output in a future guide. Make sure to end the stream when you're done!

For more recommendations and general information about live, please refer to our guide on using live encoding.