HLS Part 2
In the previous post, HLS Part 1, we gave an introduction to HLS and how it differs from traditional media servers. Let’s continue from where we left off and dive into how HLS works.
Connecting to a primary playlist
- A URL is provided, let’s say it’s a master or a primary playlist.
Say the primary playlist is provided in the endpoint: https://www.example.com/index.m3u8
When we query the HLS primary playlist, the response should be be a list of variant playlists or media playlists. Each of the provided variant playlist should provide audio in different bitrates for the consumers.
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/low/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/lo_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/hi_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/high/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5"
http://example.com/audio/index.m3u8
In the above example, we can see multiple variants of the streams and the consumers should decide which stream to use to play audio files. A client can measure the speed that the user connects to the stream and then choose whether they should be provided with the stream with a high bitrate, and hence better quality, or whether they should choose a lower bit rate variant.
Connecting to the primary playlist should only be done on the initial request. Once the consumers decide which variant to connect to, they can use the variant endpoint until the stream ends or they want to change bitrates.
Using the variant or media playlist
Once a variant playlist has been chosen, a consumer can then connect to it using a simple HTTP Get request.
Say the variant chosen is the stream with a high bitrate, http://example.com/high/index.m3u8
Connecting to the endpoint would give us a list of audio files that we can download and play.
#EXTINF:11.947,comment="ML13218-1623242282.031917-476.5"
#EXTINF:10"
https://example.com/ABC/128k/audio-1.aac
#EXTINF:11"
https://example.com/ABC/128k/audio-2.aac
#EXTINF:12"
https://example.com/ABC/128k/audio-3.aac
The consumers will then need to download and play the audio files for the users.
How big are the audio files?
Each audio files will roughly be about 10 - 12 seconds long. The variant playlist will upload new files when it is available and the consumers can query the variant playlist endpoint often to get the newly updated audio file.
TBC
References
https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis