Table of contents of the article:
This blog focuses on HLS, or HTTP live streaming, which is one of the most popular protocols used today for streaming video. The HLS format is a bitrate-adaptive live video streaming protocol. Originally developed by Apple for use on iOS devices, Mac OS and Apple TV, HLS streaming has become the most widely used live video protocol.
This article will look at the pros and cons of HTTP live streaming. We will also compare it to some alternative formats. We will also look into the history of the HLS format and ask where it came from and why.
How HTTP Live Streaming (HLS) works.
HLS video is delivered over the HTML5 web communication protocol, the latest online standard for web content. HTML5 video players support online video delivered over a variety of protocols. These include HTTP Live Streaming (HLS) and MPEG-DASH.
You can think of the streaming protocol as the method that defines what format the video uses, how it is compressed, the size of the blocks sent, and so on.
HLS was developed to provide an alternative to Flash video. Technically speaking, it uses H.264, AAC or MP3 video compression for audio compression and transmits streams using the MPEG-TS container format.
Video streaming via HLS works by cutting an MP4 video stream into short video blocks of approximately 10 seconds. Streams are described using M3U8 playlists created by the HTTP server. This playlist, also called a manifest file, indexes video blocks.
Advantages of using the HLS protocol
In recent years, the HLS format has become a standard protocol for web video, and with good reason. HLS capture is pretty easy to set up, it's free, and it's supported on a variety of devices. Let's look at some of the benefits of using the HLMS protocol for video streaming.
Benefit no. 1: Deliver on all devices
First, HTTP Live Streaming supports video on almost all devices. Although originally created for use on Safari and iOS devices, the HLS format is now supported on all modern web browsers: mobile, desktop, tablet, and so on.
If you and your viewers access content on a smartphone, tablet, desktop or laptop, smart TV, set-top box, or any other device, the HLS video will play. Most web browsers also support the main alternative, MPEG-DASH, but iOS and Safari don't. This is a big plus. For this reason, HLS remains the de facto standard.
By using HTML5, developers no longer worry about which browser or which extension their visitors are using.
Advantage #2: Excellent quality
The HLS video format uses a method called Adaptive Bitrate Streaming. This method measures the Internet speed available to each viewer of a particular video. Hence, the quality of the videos that are served is adjusted dynamically.
For example, you might start watching a video at home, where you have a fast Wi-Fi connection. Then, you can leave the house and get in the car with a friend and continue watching the video with a mobile connection. This internet connection may be slower. You may also cross areas with limited bandwidth availability. Even a dedicated home or work Internet connection can have a significant variation in Internet speed.
Adaptive streaming technologies share several critical aspects. First, they produce multiple files from the same source file to distribute to viewers watching on different devices powered by different connection speeds. Second, they distribute files adaptively, modifying the delivered stream to match changes in actual throughput and available CPU cycles on the playback station.
Third, they all work transparently to the user, so that the viewer clicks one button (rather than multiple buttons as with the movie trailer experience where users select the bitrate and video quality) and all the flow switching happens behind the scenes. The viewer may notice a slight change in quality as the streams change, but no action is required from him.
All technologies also share similar operational characteristics, although there are some key differences. For example, all adaptive streaming technologies monitor factors such as the state of the video buffer to evaluate actual throughput and CPU usage, and dropped frames to evaluate the processing power available at the playback station. This information is used to determine when to switch streams.
For example, if the video buffer is full and CPU usage is low, the adaptive streaming technology may switch to a higher quality stream to improve the viewing experience. If the buffer falls below certain levels or CPU usage exceeds certain thresholds, the technology may switch to a lower quality stream.
The main implementation difference between the technologies is the involvement of a streaming server. Specifically, some technologies require a streaming server and constant communication between server and player. If a stream switch is needed, the server implements it by sending a different stream to the viewer.
Other technologies work without a streaming server. The different quality streams are sent to different addresses on a web server or multiple web servers. The player monitors operational heuristics such as CPU usage and buffer status, decides when a stream switch is needed, and starts catching up data from a different stream when appropriate.
Either way, adaptive streaming technologies allow producers to deliver exceptional quality streams at the high end of the bandwidth/power spectrum because they also serve the low end. Without adaptive streaming, most manufacturers would deliver a single average quality file that appears below average in the optimal viewing configuration, or create multiple files and force the viewer to select the desired configuration.
Video delivered using the HLS format, when configured correctly, will dynamically provide you with the best possible video quality with minimal buffering and lag. This approach leads to a superior user experience. The video will try to continue playing as much as possible. The quality will increase as long as your internet connection is fast enough to handle the load.
Benefit #3: Cost Efficient
Another big advantage of the HLS format is its lower cost. As we said, the format is supported by almost all devices through HTML5 and Media Source Extensions. You don't need to use a specific device to watch the content. Standard web servers can handle HLS delivery without problems (depending on load and other factors).
For example, the NGINX web server that we use in the company natively supports HLS support also in the Free and Open Source version.
Cons of using the HTTP Live Streaming protocol
No protocol or technology is perfect and HTTP Live Streaming is no different. There are some disadvantages to using the HLS format. Let's look at one of the most common problems: latency.
Latency refers to the time between when an event occurs in the real world and when viewers can see it. Essentially, it's the time it takes for video to be recorded by a camera, processed by an HLS encoder, transmitted over the Internet, distributed to "edge" servers, and decoded for viewing.
Note that latency does not take into account slowdowns due to internet speeds and bottlenecks; these are largely separate issues.
HLS was designed to maximize quality, not minimize absolute latency. Its keyframe interval, packet size, and playback buffer requirement are simply not suited for super-fast live streaming. Therefore, it usually adds a 20-60 second delay to your stream. These live streaming software platforms offer integrated low latency solutions and those are the ones to consider.
This is usually only an issue for a small subset of live streamers, especially gamers and sports fans. In these situations, speed matters. However, most users can easily ignore the small latency of hosting an HLS stream as it will have no impact on viewer satisfaction or experience. For nearly all viewers, high-quality video that can be watched anytime, on any device, is more important than latency.
Solutions to the latency problem
Flash video provided low latency live streams. But with the decline of Flash, Internet video is in a period of transition. There are no fantastic solutions to the HLS latency problem yet. But many different companies are working on it, including top-tier CDN provider Akamai. Replacements for HLS are in the works (like fragmented MP4), but devices aren't ready to play them yet. The next round could still be in a few years.