HLS - HTTP live streaming protocol
HLS stands for HTTP Live Streaming. It is a streaming protocol developed by Apple to deliver audio and video media to various devices over the internet. HLS is widely used because it is adaptive, meaning it can adjust the quality of the media stream in real-time based on the user's network conditions, ensuring a smoother viewing experience.
Key Features of HLS
-
Adaptive Bitrate Streaming: HLS can dynamically switch between different quality levels (bitrate levels) based on the current network conditions and device capabilities. This helps prevent buffering and ensures a better viewing experience.
-
Segmented Media: The media content is divided into small segments, typically around 10 seconds each. This allows for efficient streaming and buffering.
-
Playlist (Manifest) File: HLS uses a playlist file (usually with a
.m3u8
extension) that lists the locations of the media segments and provides metadata about the stream. The playlist can also include multiple quality levels for adaptive streaming. -
Compatibility: HLS is natively supported by iOS devices (iPhone, iPad), Safari browser, and many streaming services. It can also be supported in other browsers via JavaScript libraries like HLS.js.
How HLS Works
- Media Segmentation: The media (audio/video) is divided into small segments.
- Index File (Playlist): A playlist file is created, listing the segments and providing information about the stream.
- Server Delivery: The media segments and playlist file are delivered over HTTP.
- Client Playback: The client (e.g., web browser or media player) downloads the playlist file, fetches the segments, and plays the media.
Example of HLS Playlist
Here is a simple example of an HLS playlist (playlist.m3u8
):
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=1280000
http://example.com/low.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2560000
http://example.com/mid.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5120000
http://example.com/high.m3u8
Each line beginning with #EXT-X-STREAM-INF
specifies a different bitrate stream, and the client can choose the appropriate stream based on current network conditions.
Use Cases
- Live Streaming: HLS is commonly used for live streaming events, such as sports, news broadcasts, and webinars.
- Video on Demand (VoD): HLS is also used for delivering on-demand video content, allowing users to start playback instantly and smoothly.
- Adaptive Streaming: It provides a seamless viewing experience by adjusting the video quality in real-time based on the user’s internet speed.