HLS (HTTP Live Streaming) is a communication protocol (not to be confused with a format) for streaming media over HTTP, developed by Apple as part of the QuickTime, Safari, OS X, and iOS software. Its core operation is based on the principle of breaking a continuous stream into small segments that are downloaded sequentially via HTTP. The stream is continuous and can theoretically be infinite.
At the beginning of the session, a playlist in M3U8 format is downloaded, containing metadata about the available embedded streams. HTTP Live Streaming (HLS) is not only the most widely used but also one of the oldest HTTP-based video streaming protocols.
One advantage of HLS is that all internet-connected devices support the HTTP protocol, making it easier to implement compared to streaming protocols that require specialized servers. Another benefit is that HLS streams can adjust video quality up or down depending on network conditions without interrupting playback. This is why HLS video quality might improve or degrade mid-stream while a user is watching. This feature is known as “adaptive bitrate streaming,” and without it, poor network conditions could completely halt video playback.
Where to Use
-
Live Streaming Events: HLS live stream is commonly used for live events like sports broadcasts or news coverage.
-
On-Demand Content: Streaming services such as Netflix and Hulu use HLS video for on-demand content.
How HLS Works
HLS operates over HTTP, which uses TCP (Transmission Control Protocol) to ensure reliable delivery of data. Here’s a breakdown of how HLS functions:
Segmentation
HLS divides video content into small, manageable chunks or segments, typically ranging from 2 to 10 seconds in length. This approach makes it easier to deliver the HLS video over the internet. Imagine slicing a movie into individual scenes; each scene can be delivered separately, allowing for smoother playback.
Manifest Files
The M3U8 manifest file lists all the segments and their order. It acts like a table of contents, guiding the video player through the segments to ensure proper playback. Think of it as a playlist that tells your video player which segments to fetch and in what order.
TCP Protocol
HLS uses HTTP, which is based on TCP, to ensure that video segments are delivered reliably. TCP handles data transmission with error checking and retransmission, making sure that the HLS media segments arrive intact and in the correct order.
Adaptive Streaming
HLS supports adaptive streaming, which means it can adjust the video quality based on the viewer’s internet speed. If your connection slows down, HLS will switch to a lower quality version of the HLS video to prevent buffering. It’s similar to automatically changing a video’s resolution to match your internet speed.
Encryption and Security
HLS can encrypt video segments to protect content from unauthorized access. This is akin to storing valuable items in a locked safe, ensuring that only authorized users can access the HLS media.
This code is an example of a Live Playlist as it appears at the beginning of a session:
HLS Architecture
HLS uses a standard web server for on-demand video delivery but requires specialized software to handle real-time content streaming.
Server Side
The server encodes and wraps incoming media into a format suitable for delivery. The content is then prepared for distribution by segmenting it. Media is segmented into chunks of equal length, stored as .ts files. An index file is also created, containing links to these segments or other index files; it is saved as an .m3u8 file. Video and audio are encoded into appropriate formats:
* Audio Codecs: AAC-LC, HE-AAC+ v1 & v2, xHE-AAC, FLAC, Apple Lossless (ALAC).
* Video Codecs: H.264 (AVC), H.265 (HEVC).
Video is encoded in H.264 or H.265 format, and audio in MP3, HE-AAC, FLAC or AC-3.
HLS originally utilized MPEG-2 Transport Stream (TS) containers. In 2016, Apple introduced support for the fragmented MP4 (fMP4) format, which has since become the preferred container for HTTP-based streaming protocols, including MPEG-DASH and Microsoft Smooth. Today, fMP4 is widely used due to its efficiency. Typically, these video files contain AVC/H.264 encoded video and AAC encoded audio.
Distribution
Operating as a standard web server, the server handles requests from clients and delivers all the necessary files for playback.
Client
There are two modes of HLS operation — “on-demand” and live streaming. In “on-demand” mode, the playlist contains links to all segments from the first to the last. In live streaming mode, the playlist contains only links to the most recent segments, and as the playlist is updated, the segments will change, reflecting the current state of the HLS live stream. The client software downloads the initial index file via URL and then several available HLS media files. The playback software assembles everything into a sequence for playback.
To learn more about how it works, refer to the Apple documentation.
Advantages of HLS
-
Compatibility: HLS is compatible with a wide range of devices and platforms, including smartphones, tablets, and desktop computers. This broad support ensures that viewers can access content regardless of the device they are using.
-
Scalability: HLS is designed to efficiently deliver video to large audiences. It handles high traffic volumes effectively, much like a buffet setup that accommodates many guests at once.
-
Adaptability: The protocol’s ability to adjust video quality based on network conditions enhances the viewing experience. It’s similar to automatically adjusting the resolution of a video to suit your internet speed, ensuring smooth playback.
Flussonic Media Server is a powerful solution for managing and distributing video content via the HLS protocol. It can ingest video streams in any quality and deliver them in the highest possible quality with consistent, predictable stability. Whether you’re streaming live events or on-demand content, Flussonic Media Server ensures efficient and reliable video delivery, offering a comprehensive platform for handling HLS streams with optimal performance and reliability.