Introduction to HTTP Live Streaming (HLS) Adaptive Bitrate Protocol
In today’s digital age, we are surrounded by a plethora of streaming services such as YouTube, Netflix, Hotstar, Prime Video, and many others. Although each of these services offers different content and experiences, they all share a common feature — the use of HTTP Live Streaming (HLS) Adaptive Bitrate Protocol.
Does it sound too technical for you? Let me simplify it. Have you ever wondered how streaming services allow you to watch videos without buffering them first? It seems like a continuous video, regardless of how slow your internet speed is. You may have also noticed that the quality or resolution of the video decreases, but the video still plays smoothly.
This became possible because of Apple Inc.’s development of the HLS protocol, which was released in 2009. In this article, we will dive deeper into the HLS video format, its functioning, and why it is a crucial component of the video streaming ecosystem.
I am not attempting to turn you into an expert in Video Streaming Protocols, but it’s something I feel you should know to understand how the videos you stream daily play smoothly even on poor internet speeds. 😉
Video Streaming Before HTTP Live Streaming (HLS)
Before the introduction of HTTP Live Streaming (HLS), video streaming was a challenging task that was not suitable for low-bandwidth networks. The video was delivered in one file format and was either streamed or downloaded entirely before it could be viewed. This method was problematic because the video content was not optimized for the user’s device or network speed, resulting in buffering and low-quality playback.
Real Time Streaming Protocol (RTSP)
The first video streaming technology was developed by Real Networks in the mid-1990s, called Real Time Streaming Protocol (RTSP). This technology used a separate control protocol to manage the flow of data between the server and the client. However, RTSP had limited support for adaptive bitrate streaming, and it was not widely adopted due to its complexity and lack of compatibility with web browsers.
Flash Video (FLV) format
Later, Adobe developed the Flash Video (FLV) format in the early 2000s, which allowed video to be streamed progressively, enabling users to watch the video while it was still being downloaded. However, this approach was still not suitable for low-bandwidth networks, and the video quality was not optimized for the user’s device or network speed.
HTTP Live Streaming (HLS)
In 2007, Apple Inc. developed the first version of , which solved many of the issues with previous video streaming technologies. HLS is an adaptive bitrate streaming protocol that dynamically adjusts the quality of the video based on the user’s device and network speed. It breaks the video into small chunks and sends them over HTTP, allowing the video to be streamed efficiently over low-bandwidth networks. Since its release, HLS has become the most widely used streaming protocol and is now supported by most major browsers and devices.
So video streaming has come a long way since its inception in the mid-1990s. With the introduction of HTTP Live Streaming (HLS), video streaming has become more accessible, efficient, and optimized for the user’s device and network speed, providing a seamless viewing experience for users worldwide.
How HTTP Live Streaming (HLS) works?
In a very simple and Lehman term HLS works by breaking down video content into small, discrete chunks that are downloaded and played sequentially by a video player. This approach allows for more seamless streaming experiences and better video quality.
To achieve this, video content is encoded into multiple versions of varying quality and bitrates, which are then broken down into small chunks, typically 10 seconds in length. These chunks are assigned unique URLs, which are made available on the server.
When a video player requests a video, it downloads a playlist file that contains the URLs for each of the video chunks. The video player then selects the best quality video chunk it can play based on the user’s internet speed, device capabilities, and other factors. As the user watches the video, the video player continues to request and download the next chunk in the sequence, seamlessly switching between different qualities if needed.
One of the key advantages of HLS is its ability to dynamically adjust the quality and bitrate of the video being streamed based on the user’s internet connection and device capabilities. This means that users with slower internet connections can still enjoy the video without experiencing buffering or interruptions, while users with faster internet connections can enjoy higher quality video.
The HLS protocol employs a master playlist, known as M3U8 also called as master playlist, that lists all the available variants or renditions for a video stream and provides information about different resolutions, bitrates, codecs, and audio channels available for the content. It also includes the URL for each variant, allowing the client to choose the appropriate rendition based on available bandwidth and device capabilities. The Media playlist contains a list of segments for a specific rendition, with each segment having a unique URL and duration of a few seconds. The client requests these segments one after another to create a seamless video stream. Additional information like encryption keys and subtitles can also be included in the media playlist.
The HLS playlist is an essential part of the HLS protocol, enabling adaptive bitrate streaming, which ensures a smooth and uninterrupted playback experience for viewers even in challenging network conditions.
See this example master playlist
#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
Tags in M3U8 Playlist
- #EXTM3U: This tag indicates that the file is an M3U playlist file.
- #EXT-X-VERSION: This tag indicates the version of the protocol used in the playlist.
- #EXT-X-MEDIA-SEQUENCE: This tag specifies the sequence number of the first segment listed in the playlist.
- #EXT-X-TARGETDURATION: This tag specifies the maximum duration of each media segment.
- #EXT-X-ALLOW-CACHE: This tag specifies whether the client can cache downloaded media segments.
- #EXT-X-PLAYLIST-TYPE: This tag specifies the type of playlist, which can be VOD (video on demand) or EVENT (live event).
- #EXT-X-STREAM-INF: This tag identifies a variant stream and specifies the properties of the stream, such as bandwidth and resolution.
- #EXT-X-DISCONTINUITY: This tag indicates that a discontinuity in the video stream has occurred.
- #EXT-X-ENDLIST: This tag indicates that the playlist file has reached the end.
- #EXT-X-KEY: This tag is used to specify the encryption key for the media segments.
Some Example Playlists
Video on Demand
In Video on Demand (VOD) sessions, the media files representing the entire duration of the presentation are available. In this case, the index file remains static and includes a complete list of URLs to all media files created since the beginning of the presentation. Such sessions allow the client full access to the entire program.
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
http://example.com/movie1/fileSequenceA.ts
#EXTINF:10.0,
http://example.com/movie1/fileSequenceB.ts
#EXTINF:10.0,
http://example.com/movie1/fileSequenceC.ts
#EXTINF:9.0,
http://example.com/movie1/fileSequenceD.ts
#EXT-X-ENDLIST
Live Playlist (Sliding Window)
During live streaming sessions, the M3U8 index file is dynamic and updated in real-time. As new media files are created and made available, the index file is updated by removing media URIs from the file. Unlike Video on Demand (VOD) sessions, the EXT-X-ENDLIST tag is not present in the live playlist, indicating that new media files will be added to the index file as they become available. This allows the client to keep receiving and displaying the latest available media segments during the live streaming session.
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10.0,
fileSequence1.ts
#EXTINF:10.0,
fileSequence2.ts
#EXTINF:10.0,
fileSequence3.ts
#EXTINF:10.0,
fileSequence4.ts
#EXTINF:10.0,
fileSequence5.ts
Event Playlist
The playlist type called “Event” is identified by the EXT-X-PLAYLIST-TYPE tag with the value set as EVENT. Unlike VOD sessions that have a complete list of media files, an event playlist doesn’t have an EXT-X-ENDLIST tag initially. This signifies that new media files will be appended to the playlist as they become available during the event.
#EXTM3U
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.00,
fileSequence0.ts
#EXTINF:10.0,
fileSequence1.ts
#EXTINF:10.0,
fileSequence2.ts
#EXTINF:10.0,
fileSequence3.ts
#EXTINF:10.0,
fileSequence4.ts
Multivariant Playlist
The Multivariant Playlist is a collection of playlists that contain different versions of a video stream at different bitrates. Each playlist represents a variant that offers the same content but at a different bitrate. These playlists are organized in a master playlist, which provides information about the available variants, their characteristics, and their location. The client player can automatically switch to the most appropriate variant based on the available network bitrate, ensuring that the playback is smooth and uninterrupted, providing a seamless streaming experience for the user. The ultimate goal is to minimize stalling or buffering of the video stream, providing the best possible viewing experience for the user.
#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
That’s all about the HTTP Live Streaming (HLS), thank you for taking the time to read this story “Introduction to HTTP Live Streaming (HLS) Adaptive Bitrate Protocol.” I hope that it has helped you understand the basics of this important protocol for video streaming.
If you have any questions or feedback, please feel free to reach out. I would love to hear your thoughts and continue the conversation.
Again, thank you for your time, and I hope you found this article informative and useful.