What is HTTP live streaming (HLS)?
HLS, or HTTP Live Streaming, stands as a popular protocol for video streaming. Despite the term "live" in its name, HLS serves the purpose of delivering not only live content but also on-demand streaming. The protocol operates by segmenting video content into smaller, downloadable chunks that are transmitted over HTTP. These fragments are then retrieved by client devices, which seamlessly assemble and present them as a continuous video playback.
A key benefit of HLS is its compatibility with all devices connected to the Internet via HTTP, which simplifies deployment compared to other streaming protocols that might necessitate dedicated servers. Additionally, HLS streams have the capability to adjust the video quality dynamically based on network performance, enhancing or reducing resolution as needed without halting the video. This is observed when the video quality changes mid-stream, a characteristic referred to as "adaptive bitrate streaming" or "adaptive bitrate video delivery." Without this technology, poor network conditions could result in continuous buffering or even prevent the video from playing.
Originally developed by Apple for its products, HLS has since become widely adopted across various devices.
What does streaming mean?
Streaming enables the transmission of video and audio content to users via the Internet by progressively sending small segments of the media file to the user's device rather than transferring it in its entirety at once. The media file is hosted on a remote server, and for live streaming, it is produced in real-time using remote video or audio capturing equipment. Consequently, users can start playback of the video or audio without the necessity for their device to download the complete file beforehand.
What does HTTP stand for?
HTTP operates as a protocol at the application layer, facilitating the exchange of data between network-connected devices. It serves as the foundational technology for websites and applications available to end users. The HTTP data communication model primarily revolves around a request-response mechanism, with the majority of HTTP communications being categorized as requests or the corresponding responses to these requests.
In HTTP streaming, the conventional request-response model is not applicable. Instead, the client-server connection is maintained throughout the streaming session, allowing the server to continuously send video data to the client without the need for the client to request each individual video segment.
How does HTTP Live Streaming function?
Server: An HLS stream is sourced from a server which either stores the media file for on-demand streaming or generates the stream for live streaming. HLS utilizes HTTP, allowing a standard web server to initiate the stream.
The server primarily performs two processes:
- Transcoding: Video content is transformed to ensure compatibility across various devices. HLS mandates the utilization of either H.264 or H.265 codecs for this purpose.
- Chunking: The video is sliced into brief chunks, typically spanning several seconds. There is flexibility in chunk duration, but by default, it's 6 seconds, a reduction from the previous 10-second standard pre-2016.
- Chunking is accompanied by the generation of a playlist file that enumerates the sequence of the video chunks.
- Moreover, HLS produces multiple versions of these chunks at varying resolutions, such as 480p, 720p, 1080p, etc., to accommodate different bandwidth capacities.
Delivery: Upon request from client devices, the encoded video chunks are distributed across the Internet. To facilitate this, a content delivery network (CDN) is often used to ensure efficient streaming to clients in various locations. Additionally, the CDN caches the content to expedite delivery to the clients.
Client Device: This is the device that obtains the stream and plays the video content.. This can be any device used by end-users to watch the stream, such as smartphones, tablets, laptops, or desktop computers. Notably, one of the common client devices is a web browser, which allows users to view streaming content directly within the browser interface. The client device uses the index file as a reference for assembling the video in order and switches between different video qualities as network conditions change. For more details on integrating streams with web browsers, see How to embed RTSP stream in web browser.
What is M3U8 File Format
M3U8 files are essentially playlists used for HLS (HTTP Live Streaming) video content. They contain a list of .ts files (MPEG transport streams) that divide the content into manageable segments, enabling efficient data transfer and easier adaptive streaming.
For additional information about M3U8 files, refer to this article: What is m3u8 file?
What does adaptive bitrate streaming mean in the context of HLS?
A key benefit of HLS compared to certain other streaming protocols is its adaptive bitrate streaming feature. This capability enables the video stream to dynamically alter the video quality during playback in response to fluctuating network conditions. Consequently, this feature ensures continuous playback even under deteriorating network situations, while simultaneously optimizing the video quality to the highest level that the network conditions can accommodate.
When the user's video player senses a reduction in network speed, adaptive bitrate streaming automatically adjusts by decreasing the stream's quality to prevent playback interruption. Conversely, when additional network bandwidth is accessible, the streaming quality is enhanced by the adaptive bitrate technology.
HLS enables adaptive bitrate streaming by generating multiple segmented streams at varying quality levels during the segmentation phase. During video playback, the user's video player has the capability to switch between these different quality streams.
Is HLS based on TCP or UDP for its transport layer protocol?
TCP and UDP serve as transport layer protocols tasked with data delivery across the Internet. TCP is more reliable in data delivery compared to UDP, which offers faster transmission at the cost of potentially losing some data.
Some streaming protocols opt for UDP over TCP due to its speed advantages. Nonetheless, HLS employs TCP for a variety of reasons.
- HLS streaming operates over HTTP, which is typically paired with TCP, although there are some exceptions.
- The reliability and efficiency of the Internet have significantly increased since the early days of streaming. In numerous regions, particularly for mobile users, the connectivity has improved greatly, allowing sufficient bandwidth for consistent video frame delivery.
- Adaptive bitrate streaming is utilized to mitigate the slower data transmission that can be associated with TCP.
- Unlike videoconferencing, HLS streaming is not expected to be instant, so a slight delay is less detrimental to the viewing experience than missing frames would be.
Which other protocols are frequently utilized for streaming?
Several other protocols, such as MPEG-DASH and HDS, provide adaptive bitrate streaming over HTTP, akin to HLS. Adobe Flash, which operated on RTMP or HDS, was previously a dominant streaming technology, but it has fallen out of favor as many browsers have ceased to support Flash. RTMP, while still operational, is also experiencing a decrease in support.