This is the second part of the series about Amazon Elastic Transcoder.
In this article we will see how we can deliver a dynamic stream using Amazon CloudFront.
To accomplish this goal, we will need to use multiple services from AWS. We will use Amazon S3, Amazon CloudFront and Amazon Elastic Transcoder. Each has its purpose and we will see how they should be used.
VMware Training – Resources (Intense)
In this article we will discuss how to:
Create multiple bit-rate versions of a source file using Elastic Transcoder.
Deliver the content using Amazon CloudFront.
Before we start, let’s discuss a few concepts that will be used throughout the article:
HTTP Live Streaming (HLS) is a streaming protocol that can dynamically adjust playback quality based on the available network resources. Multiple quality versions of the original source are created and each one of them is broken into multiple parts. The client can select a stream of different bit-rates based on the bandwidth available.
Bit-rate stream is the rate at which the source file is streamed to the client. There are multiple bit-rate streams that can accommodate different network conditions
The stream can be played on any device that supports HLS. Since Apple created HLS, iOS devices can play the stream without any problem.
So, let’s start with the S3 bucket. As you can see, I have one S3 bucket that contains a folder and inside is our sample video that will be played on a mobile device:
The next step is to create the Amazon CloudFront distribution through which the content will be streamed out. Select the CloudFront service from the AWS Management Console and then click on “Create Distribution”:
Select the web method of delivering content and click on “Get Started”:
We only need to fill a few details and change just a few values from default. Select as “Origin Domain Name” the S3 bucket that was created earlier. Optionally, you can configure it in such a way that the content can only be accessed through the CloudFront distribution and not by directly accessing the S3 bucket.
This is what I did below. You need to restrict the bucket access and then make sure that the S3 bucket policy is updated. You can do this later manually if you want to, but it’s easier to leave this task to Amazon CloudFront.
Basically, this is how this section should look like:
The rest of the configuration options can be left at their default values and you can now create the CloudFront distribution:
The CloudFront distribution will be deployed after several minutes so we will get back to it after we configure the Amazon Elastic Transcoder server:
Now moving on to the Amazon Elastic Transcoder. Once you open the service, the only thing that you can do is to create a pipeline. Click on “Create a new Pipeline”:
Give the pipeline a name of your choice and as input bucket, provide the name of the S3 bucket that was created earlier. Use the default role created to allow read/write access to the S3 bucket:
On the next section, again provide the name of the S3 bucket created earlier and leave the storage class at its default value:
In the last section, provide and use the same settings as in the previous section:
And then create the pipeline:
You can review various details about the pipeline that was just created:
It’s time to create a job that will transcode the input file into multiple bit-rates. Select “Jobs” from the left menu and click on “Create New Job”:
Select the pipeline to which this job belongs. Also, you will need to provide the input value (the video that will be transcoded) and the output directory where the multi-bit rates will be found. The output folder doesn’t need to exist before you reference it. If it doesn’t exist, it will be created when the job runs:
Now it’s time to create the output files. In this case, we will create three of them, each with a different bit-rate. This is the first one with a bit-rate of 2Mbps as you can see from the preset selected, HLS 2M. The default value for this preset is 10, so we can use this value. In the output key, insert a unique prefix that will identify the segments created for this preset:
We need to create two more bit-rates. Clicking on “Add Another Output” does this:
This is the second bit-rate of 1.5Mbps. The rest of the details are the same. The output key has to be unique:
And this is the third bit-rate of 1Mpbs:
Now it’s time to create the master playlist that will combine all the bit-rates and provide a unique URL for devices to playback the stream. Click on “Add Playlist”:
Give a name to the master playlist, select the format as HLSv3 and then add the three bit-rates in the master playlist:
Then create the job:
You can see the job created:
In order to test the playback of the dynamic stream, you will need to construct the URL that will be used on the mobile device.
The URL derive from the CloudFront domain name. You can get it by going to the CloudFront service and writing down the domain name:
The second part of the URL is the path to the master playlist in the S3 bucket. In our case, it will be in the output folder similar to this. Also, you can see that each bit-rate stream has been divided into 4 segments. This is because we chose a segment duration of 10 seconds and the original source has a length of 32 seconds:
The general URL format is:
In our case, this will be the URL:
One way or another, have this link be available on your mobile device and open it on a browser:
The stream will be played in the mobile device and segments will be requested based on the available bandwidth:
And this concludes how you can use HLS to play media files on iOS devices through the means of Amazon S3, Amazon CloudFront and Amazon Elastic Transcoder services.
Let’s see what has been done throughout the series: we discussed Elastic Transcoder’s components and the settings that are specified when a pipeline and a job are created. In the second part we saw how we can transcode a file into multiple formats and then deliver the content to a mobile device through a CloudFront distribution.