Skip to content
← ALL POSTS

Streaming with AWS Media Services

Have you ever been curious about the inner workings of video streaming and how you can leverage AWS media services to create one. A stream of your own?

ISRAJUR RAHMAN6 MIN READ

Have you ever been curious about the inner workings of video streaming and how you can leverage AWS media services to create one. A stream of your own?

Lets create a video stream from a local machine to understand the process and how to use AWS Media Services for video streaming. This article will explain how to create a video stream using AWS Media services.

Tools we will be using:

  1. FFmpeg
  2. AWS MediaConnect
  3. AWS MediaLive
  4. AWS S3

What we need:

  1. A machine to run FFmpeg
  2. A video file
  3. VLC Media player (or any network streaming tool)
The pipeline end to end. A local machine sends the video with FFmpeg over SRT into the AWS cloud, where MediaConnect passes it to MediaLive, which writes an HLS playlist to an S3 bucket that a video player reads

4. Video Streaming Overview

In this article we will be using a downloaded video file but you can also use any live camera feed directly into stream to show live feeds.

Let’s Start!

STEP 1

Go to AWS Elemental MediaConnect in console and create a new MediaConnect flow with below settings-

The MediaConnect source details dialog. The flow is named craftsmen-flow, protocol SRT listener, inbound port 5555, whitelist CIDR block 0.0.0.0/0, with a warning that this block leaves the flow open to public access

AWS MediaConnect Source Detail

Here we are using 0.0.0.0/0 (this is not recommended; you should always use your public ip/range) CIDR block to make the flow publicly accessible for this article. We are using SRT Listener. To know more about SRT click here. We will be using inbound port 5555 to connect to this flow. After creating start the flow.

The MediaConnect flow craftsmen-connect-flow, active in eu-west-1a with public outbound IP 52.18.155.2. Its one source shows inbound IP 52.18.155.2, port 5555, protocol srt-listener and source health Connected

A MediaConnect Flow with IP: 52.18.155.2 and Port: 5555

STEP 2

Now, Before Creating a MediaLive channel we need to create an IAM role and MediaLive input.

Create an IAM role with S3, MediaLive and MediaConnect full access (this just simplifies the role hunting).

The IAM role’s attached policies: AmazonS3FullAccess, AWSElementalMediaLiveFullAccess, and an inline craftsmen-emx-all-policy whose JSON allows the action mediaconnect:* on every resource

IAM role policies

The Trust relationships tab of the same IAM role, listing medialive.amazonaws.com as the one identity provider allowed to assume it, with no conditions attached

IAM Role Trust relationships

STEP 3

Create an s3 bucket (ex. my-bucket) and give public access to it so that we can use it publicly.

STEP 4

Now Go to MediaLive Inputs and create a new input with settings below:

The MediaLive Create input form. The name is craftsmen-live-input, input type MediaConnect is selected out of the ten options, the craftsmen-connect-flow ARN is chosen as Flow A, and a custom MediaLive role ARN is supplied

MediaLive Input Settings

We have selected input type MediaConnect and added our MediaConnect Flow and the IAM role in this MediaLive input.

STEP 5

After creating MediaLive input we will create a MediaLive channel. Attaching the input we have created earlier and the IAM role.

The MediaLive channel form for craftsmen-live. The input attachment is craftsmen-live-input, the output group is one HLS group named CHLS, and the existing craftsmen-medialive-role is selected as the IAM role

MediaLive Channel Setting

For this demo we will be using SINGLE_PIPELINE.

The channel class set to SINGLE_PIPELINE, described as creating only one encoder pipeline, above input specifications of MPEG2 codec, HD resolution and a maximum bitrate of 20 Mbps

MediaLive Channel Setting

Now add Output groups

The HLS output group settings. Destination URL is s3://my-bucket/index, CDN setting is HLS S3, input loss action is EMIT_OUTPUT, and one output is listed with the name modifier _640x360_800k

MediaLive Channel Output Group Setting

We have selected HLS output. As destination url we have used our newly created s3 bucket and we want our MediaLive output file named as index.

The individual HLS output settings: name modifier _640x360_800k, standard HLS with an M3U8 manifest, and a video stream named video_640_360 at 640 by 360 encoded with H264

MediaLive Channel Output Setting

Now if we go to our MediaConnect and check output we will find a MediaLive output connected to our flow.

The Outputs tab of the MediaConnect flow, now listing a single output named MediaLive-140cd21dc52d and typed Managed by MediaConnect

MediaConnect Output

STEP 6

We need a sample video file we want to use and download FFmpeg on our local machine.

To download FFmpeg: wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz

Unzip the FFmpeg folder and use command ./ffmpeg -stream_loop -1 -i in terminal.

Example: ./ffmpeg -stream_loop -1 -i /home/user/Downloads/test_video_file.mp4 -f mpegts srt://52.18.155.2:5555

We are using -stream_loop cause our sample video file too short so we are looping our file for continuous stream and since we declared SRT listener in MediaConnect we are using srt://52.18.155.2:5555

FFmpeg running in a terminal. It reports the input file as 3840 by 2160 H264 at 24 frames per second, maps the streams to mpeg2video and mp2, and streams the output to srt://52.18.155.2:5555

After running FFmpeg command in terminal

Note: Make sure you have started MediConnect and MediaLive and both are running.

We will see something like this in MediaConnect

The MediaConnect source now Connected, with the source bitrate chart flat at zero and then jumping to roughly nine megabits per second once FFmpeg starts

In MediaLive

The MediaLive channel craftsmen-live with channel state Running, one pipeline running, and no active alerts

And in s3 bucket

The S3 bucket filling with output: twenty-four objects, a run of roughly 7 MB .ts segments written about eleven seconds apart, plus the index.m3u8 playlist

We will see an index.m3u8 file, it’s a playlist file generated by Medialive in our s3 bucket. Now if we copy the object url of this m3u8 file and start a network stream in our VLC player.

TADAAAAAAAAA………

Thank you for reading! 

Let’s show you a fun trick by adding a logo in live streaming- 

Upload a logo in the bucket and copy the object url then follow the steps. 

Got to MediaLive channel and select schedule

The Schedule tab of the MediaLive channel, empty, with a Create button for adding the first schedule action

Select settings below, add the logo url and create

The Create schedule action form. The action is named craftsmen_logo, starts Immediate, is typed Static Image Activate, and points at the logo’s S3 URL on layer 7

MediaLive Schedule Settings

Here we go!

Video Streaming with Logo.

Special Thanks to Sakibul Alam for contributing and sharing AWS Media Service related knowledge.

NEWSLETTER

One engineering letter a month

New writing from our engineers, no marketing filler.

[ ONE CONVERSATION AWAY ]

Rather ask an engineer than read another post?

Thirty minutes, no sales script. Bring the problem you are actually stuck on and we will tell you honestly whether we are the right partner for it.