A step-by-step introduction to live streaming, by iflix’s amazing software engineer, Belal.
STEP 1: MediaLive choosing the input
Figuring out the input depends on the encoder used by the live streaming source:
- RTP: this will generate the live RTP link, the source should push to the generated publishing point
- RTMP Push: this protocol also requires the source to send the stream to a fixed link, however part of the link is auto-generated and the other part is created. The Application Name and the Application Instance can given any title words such that the RTMP URL should look like this: rtmp://126.96.36.199:1935/live/event
- RTMP Pull: in this case the source should be provide an external link. MediaLive then pulls the stream from the provided link.
- HLS: this is a pull protocol as well, however it is using the external HLS URL
MediaLive doesn’t require a username or password for the stream therefore it is recommended to set up the right security group to match the source’s IP address. If the IP address is unknown, there is always the option of leaving the input public by setting up the security group to 0.0.0.0/0. In a production environment you shouldn’t expose the publishing points to public.
MediaLive will generate two inputs for different availability zones, just in case one fails.
STEP 2: Create MediaPackage channel
This service helps to create the HLS manifest and manages the quality profiles.
After creating the channel, the endpoint must be created to generate the HLS manifest, the link that should be set as the player source to watch the stream.
The options provided when creating the MediaPackage endpoint are important to define the configuration of the manifest and the player behaviour, such as setting up the bitrate in ascending order (start from lowest bitrate), which will eventually reflect on the way the player is going to handle the stream, by starting from the lowest quality and improving according to the highest bitrate.
The reason behind creating the MediaPackage channel before the MediaLive channel is because it is required to link the MediaLive channel with MediaPackage by the provided link, username and password.
IMPORTANT NOTE: this endpoint is limited, it can handle only 200 request per second. This is a soft limit however. If the request continues increasing over 200 requests per second, some users are going to lose the stream.
STEP 3: Create MediaLive Channel (output)
This is the hardest part if it’s being done for the first time. Once set up, however, after the first setup it become the easiest part.
Setting up the transcoding options for the first time could be quite a hassle, especially with the large number of options provided. As a shortcut MediaLive has offered templates that can be used or modified. To set up the channel correctly follow these steps:
- Choose the input (choose the right input because it can’t be edited after the channel is created)
- Pick a template (optional)
The template includes the HLS output with default qualities, bitrate and frame rate. Those numbers may be too high or too low for the required stream. It is possible to edit the qualities by clicking on the quality name on the left menu to update the configuration of the profile.
- Determine Output Destinations
By choosing a template it is easier to set up the HLS output, however MediaLive offers the archiving output which stores the stream in chunks between 150MB to 200MB. In the output group, it is required to set up the HLS group destination A and HLS group destination B. To do so it is required to create the MediaPackage service and pick up the URL, username and password from there.
If the source had a network issue or the stream stopped (stream ended), MediaLive will show a black screen as a default. It is possible to change that to any other colour or any image by amending the Global configuration and changing the Input Loss Image Slate option to input loss image slate and fill up the image URL in the text box after that.
Step 4: CDN (Akamai)
MediaPackage can only handle 200 request per seconds – alright if there are a few hundred users, but where there are more, it is highly recommended to think of another way to deliver the stream, such as Akamai.