AWS for M&E Blog
How to send live video to AWS Elemental MediaStore
In this blog post, I’ll describe how to send live HLS streams to AWS Elemental MediaStore.
AWS Elemental MediaStore is an AWS storage service optimized for media. It gives you the performance, consistency, and low latency required to deliver live streaming video content. In this blog post I will show you how to setup a simple live video workflow that uses MediaStore as its origin.
Outline
- Create AWS Elemental MediaStore Container
- Create Container
- Setup a container policy on your new container
- Add an optional CORS policy if you want to play the stream via an HTML HLS or HTML Dash video player
- Setup AWS Elemental MediaLive
- Create a RTMP input for the MediaLive channel
- Create the MediaLive channel
- Use your phone, desktop, or camera to stream to MediaLive
- Use OBS to stream to MediaLive
Part 1: Create AWS Elemental MediaStore Container
Step 1: Create Container
From the AWS console search for AWS Elemental MediaStore. Click “Create Container” and choose a name for your MediaStore container. After the container is done creating, move to the next step.
Step 2: Setup a container policy
After creating a container, add the following policy that allows anybody to view your live stream. By updating this policy, you can lock down your live stream, and restrict access to it, but for simplicity in this example we are creating a policy so anyone can view the live stream.
After selecting the newly created container, click on the “Container Policy” button. Copy the following JSON container policy into the box labeled “your container policy,” and make sure to replace AWS_ACCOUNT_NUMBER and CONTAINER_NAME with the name of your container and your AWS account number (found on the top right of your AWS console).
Container Policy
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PublicReadOverHttpOrHttps",
"Effect":"Allow",
"Principal":"*",
"Action":[
"mediastore:GetObject",
"mediastore:DescribeObject"
],
"Resource":"arn:aws:mediastore:us-west-2:AWS_ACCOUNT_NUMBER:container/CONTAINER_NAME/*",
"Condition":{
"Bool":{
"aws:SecureTransport":[
"true",
"false"
]
}
}
}
]
}
Step 3: Optionally setup a CORS policy
CORS stands for Cross-Origin Resource Sharing. CORS policies are used to grant permission to access selected resources when the request is from a server at a different origin.
If you want to view your live stream on the HLS JS video player demo page you will need to add a CORS policy on your container. To do so, click the “Edit CORS policy” button. Without the CORS policy you can still view your live stream in desktop players such as VLC or Quicktime.
The CORS policy below allows all headers to pass through, and any origin to watch the video. If you wanted to tighten the security on your live stream you would replace “*” in the “AllowedOrigins” list with the domain name of the website on which you are showing the video.
CORS Policy
[
{
"AllowedHeaders":[
"*"
],
"AllowedMethods":[
"GET"
],
"AllowedOrigins":[
"*"
],
"ExposeHeaders":[
"*"
],
"MaxAgeSeconds":3000
}
]
Part 2: Setup Live Encoder
For our live streaming needs, we will be using AWS Elemental MediaLive, which is a broadcast-grade live video processing service. It lets you create high-quality video streams for delivery to broadcast televisions and internet-connected multiscreen devices, like connected TVs, tablets, smart phones, and set-top boxes. I will describe how to use Open Broadcaster Solution (OBS) to send RTMP to AWS Elemental MediaLive and link to some other options.
Step 1: Create an RTMP input
- Search for AWS Elemental MediaLive in the AWS console
- Click “Create Channel”
- Click “Inputs” on the left side and create a new input. I called my input “RTMP_Input”
For push inputs, you will need to define an input security group. I used the default 0.0.0.0/0 security group. This will allow any IP address to send an RTMP stream to your channel. You can lock this down to your IP address for added security.
- Next, created an application name for Destination A and Destination B. I chose “stream1” and “stream2”
- Then for application instance, I put the names “a” and “b”
- Lastly click the “create” button
Step 2: Create the AWS Elemental MediaLive Channel
- Add a name for your MediaLive channel. (I named my “LiveChannel”.)
- Under IAM role, choose “Create role from template” if you have not created a role before, or select the MediaLiveAccess role if you have already created it. This role will provide PUT access to your MediaStore container as well as the other permissions required for your MediaLive channel.
- Under channel input choose your RTMP input from the drop-down box.
- You can customize your outputs, configuring video settings such as resolution, bitrate, and other encoding parameters, but for this example, I have used the “Live Event” Channel Template.
For the next step, you will need your container’s data endpoint, which can be found when clicking on the container on the AWS Elemental MediaStore console page. - In the upper left click on the HD (HLS) tab under the output groups. You will see HLS group destination A and HLS group destination B. Type in the endpoint for your MediaStore container: “mediastoressl://container_data_endpoint/path/main” for each output. We will only be using output A in this example. (Each output needs to be a unique path.)
- Now click the large orange “Create Channel” button.
Part 3: Stream RTMP to live encoder
There are many ways to send content to AWS Elemental MediaLive. I am going to step through how to use OBS, sending RTMP.
For instructions on how to send to MediaLive in other ways, there is a series of blog posts detailing other options:
Using AWS Elemental Live encoder
Using FFMPEG with RTP
Using FFMPEG RTMP
Using VLC with RTP
Using OBS
Stream from OBS to AWS Elemental MediaLive
- Downloaded and install OBS (Open Broadcaster Software)
- After opening OBS in the settings menu select “Custom Streaming Server” and use the “Input Destinations” from Step 2 of Part 2. This is the destination for the RTMP stream
- After setting this up your OBS encoder, go back to the MediaLive channel that you created and click the orange “Start Stream” button
- After the MediaLive channel changes from the Start to the Running state click “Start Streaming” in your OBS program
- You can now go to the MediaStore console page to check your container. You should have objects showing up in your container
To test your HLS live stream this is the URL to use to access it.
http://container_data_endpoint/livea/main.m3u8
Paste that link into VLC player’s network input or if you are on a Mac you can use Quicktime or paste it into the Safari URL bar.
For instructions on how to create an Amazon CloudFront endpoint that uses MediaStore as an origin, see this blog post.
In part 2 of this blog, I’ll describe how to send to MediaStore from other encoders, such as AWS Elemental Live, or any other encoder.