Natalia Kharchenko

@nataliakharchenko

How to Set Up Live and On-Demand Streaming in AWS Media Services

How to Set Up Live and On-Demand Streaming in AWS Media Services

AWS Media Services represent a set of cloud-based solutions created to assist with video processing. They process, store and deliver video content using OTT (Over-the-Top) technology.

These services offer a pay-as-you-go pricing model which means they’re great for building scalable solutions within a pretty short timeframe.

A bit of theory

Underneath, I’ve listed the solutions that come into AWS Media Services family and explained what they serve for in a nutshell:

  • AWS Elemental MediaConnect. This is a service optimized for safe and reliable video stream transfer.
  • AWS Elemental MediaConvert. This one is responsible for video files processing and creation of streaming Video on Demand content.
  • AWS Elemental MediaLive. The service allowing to convert video content for broadcasts in a real-time mode.
  • AWS Elemental MediaPackage. It’s used to prepare and protect video content delivery over the internet. Using one source, MediaPackage creates video streams utilizing different formats and standards (MPEG-DASH, Smooth Streaming, HLS, CMAF) for playback on a variety of devices (TVs, PCs, smartphones, tablets, game consoles).
  • AWS Elemental MediaStore. The AWS storage optimized for real-time video content. It provides low read and write latency at a large number of queries so you could give users a high-quality service.
  • AWS Elemental MediaTailor. This service allows video providers to embed ads into their video streams on the server-side.

Benefits of AWS Media Services

So why AWS Media Services are worth using? First of all, they reduce infrastructure expenses and optimize the content delivery process for broadcast organizers and media content providers.

For content owners, they allow creating content in the format of on-demand video for broadcasts of any scale. While media companies can broaden their audience due to OTT technology.

The main use cases

  • Creation of video broadcasts in a real-time (Live Streaming).
  • Creation of a Video on Demand content library.

Setting up a real-time video streaming

Let’s get to practice now.

The real-time video streaming can be built by means of the following services:

  1. AWS Elemental MediaLive. The conversion/encoding of video and audio streams with the help of various codecs. It’s also in charge of adding subtitles and watermarks.
  2. AWS MediaStorage. Optimized media content storage to let you store records of video streams with their further on-demand delivery (optional). It sometimes can function incorrectly, so Amazon recommends using AWS S3.
  3. AWS Elemental MediaPackage. The transfer of a recoded video stream to target devices using different technologies (Apple HLS, MPEG-DASH, CMAF, Microsoft Smooth Streaming).
  4. AWS CloudFront. The CDN service to fasten the delivery across different geographical regions (optional).

Here is a short version of what you need to do for setting up a live video broadcast:

  1. Create a channel in AWS MediaPackage.
  2. Create an endpoint for the channel.
  3. Create a source (input) for the AWS MediaLive channel (and input security group if needed).
  4. Create an AWS MediaLive channel to convert video from source and transfer it to AWS MediaPackage.
  5. Start video broadcasting.

Let’s consider the aforementioned points in more detail.

1. Establish a channel in AWS Elemental MediaPackage

The first step to undertake is the creation of AWS MediaPackage channel for processing the recoded video stream. You can do so by using the AWS SDK or developers console.

(The following examples are based on working with developers console, but it’s pretty easy to do it with SDK as well.)

To create a channel you should specify its ID and description (optional). As for now, AWS Elemental MediaPackage works with HLS protocol only. So keep that in mind.

2. Configure endpoints

The next step is to configure endpoints (addresses that end-users need to follow to get a streaming video).

Here are all the supported options:

  • Apple HLS
  • Microsoft Smooth
  • Common Media Application Format (CMAF)
  • MPEG-DASH

3. Tune the MediaLive

Once MediaPackage is all set you can proceed with tuning AWS MediaLive. First, you need to create the Input (source of a video stream).

MediaLive can receive at the input :

  • An MP4 file.
  • A stream transferred via RTMP/ RTP/HLS protocols.
  • A stream transferred using AWS MediaConnect.

As an example, let’s create an input receiving a screen record via OBS (Open Broadcaster Software) using RTMP protocol.

4. Create a video stream processing channel in MediaLive

For this, you need to specify the name, create an IAM role (or pick already existing one). Then you should choose the previously created input along with output group (destination for converted media stream) to provide the rights needed for integration with other services.

As an output, AWS MediaLive supports:

  • Apple HLS
  • Archiving video stream to S3
  • RTMP (transfer of a video to streaming services like YouTube, Twitch, and others)
  • Microsoft Smooth
  • UDP/RTP

It’s possible to create your own output group or pick one from templates. Let’s take a ‘Live event’ template as an example for the creation of an output HLS stream with the support for four resolutions (240p, 480p, 720p, and 1080p).

In the settings of the output stream, you should specify the destination address. (For example, in the case with HLS output, it can be such services as MediaPackage, MediaStore, S3 or Akamai CDN). One more thing to specify is an input address of the MediaPackage channel.

After that, you’ll be able to change the video’s encoding settings or add outputs for other screen resolutions and bitrates. Finally, by clicking the ‘Create channel’ button, you’ll create the channel itself.

5. Launch MediaLive channel

To finally start broadcasting, you should specify the address you’ve got during the creation of RTMP.

The broadcast view will be available at the addresses created in the MediaPackage endpoint.

If there is a necessity to save the broadcast, you should use MediaStore or S3 instead of MediaPackage.

Setting Up a Video on Demand

AWS Elemental MediaConvert is used to deliver on-demand video content. It works similarly to MediaLive with the only difference that MediaLive processes video streams in a real-time, while MediaConvert does the same with video files taken from the S3 storage.

Amazon gives developers an open-source solution which takes several steps to be tuned:

  1. Load the source file to S3 with a tag for archiving in AWS S3 Glacier.
  2. The source video is then validated and the AWS MediaConvert template is chosen based on metadata. The received data are saved to a database.
  3. The task (Job) for video processing is created in AWS MediaConvert based on the profile.
  4. At the end of video conversion, the result is transferred to S3 and the database record is updated.
  5. The processed data from S3 are cached to CloudFront to speed up the delivery across various geographical regions.
  6. The bugs are caught with the help of CloudWatch.

Underneath I’ve left a schematic picture illustrating how it all works.

More by Natalia Kharchenko

Topics of interest

More Related Stories