Home   web-development  

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

  1. 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.

  2. Segmented Media: The media content is divided into small segments, typically around 10 seconds each. This allows for efficient streaming and buffering.

  3. 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.

  4. 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

  1. Media Segmentation: The media (audio/video) is divided into small segments.
  2. Index File (Playlist): A playlist file is created, listing the segments and providing information about the stream.
  3. Server Delivery: The media segments and playlist file are delivered over HTTP.
  4. 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

Published on: Jul 05, 2024, 11:49 AM  
 

Comments

Add your comment