From Spotify to Netflix, streaming services are now a part of everyday life for many consumers all over the world. In the U.S. alone, 62% of adults currently subscribe to at least one streaming service as accessing and enjoying content via streaming becomes the norm for consumers of all ages.
Whether audio or video content being streamed, there is a lot of technology built into consumer AV product design that works behind the scenes to deliver streaming content — and streaming protocols are what make doing so possible. Regardless of whether you’re watching live video via an app on your smartphone or on-demand content on your TV, the likelihood is high that the HTTP Live Streaming (HLS) protocol is involved.
In this blog post, we’ll discuss what the HLS protocol is, how it works and best practices for implementing HLS streaming solutions.
What is HLS?
Developed by Apple, HTTP Live Streaming (also known as HLS) is an HTTP-based adaptive bitrate streaming communications protocol that delivers audio and video media over the web, from media servers to viewers’ devices.
HTTP, or Hypertext Transfer (or Transport) Protocol, is the data transfer protocol that runs the world wide web. Because it’s completely ubiquitous in the network, there’s a lot of infrastructure in place for servers and clients, and the HLS protocol takes advantage of that and uses the existing infrastructure to distribute streaming content.
When you generate HLS video or HLS audio content, you can produce the content with varying quantity or quality. The quality is directly proportional to the bitrate. With HLS, the highest quality has the highest bitrate, and the lowest quality has the lowest bitrate. Let’s say you’re watching a high-definition movie at 1920×1080 (1080p), as your device plays the content back, it plays along fine. But when your kids jump on the network, your available bandwidth goes down. When the client network can’t keep up and you experience some glitches, the protocol adapts to a lower bitrate.
Support for HLS is widespread in media players, web browsers, mobile devices and streaming media servers, and because it’s an industry standard, all Mac, Android, Microsoft and Linux devices can play streams delivered using HLS, making it the most popular over-the-web playback mechanism.
How does HLS work?
When content producers and broadcasters create streamable content, they make two sets of files:
- Text files — These text-based playlist or manifest files are easy to produce. They are written to a web server, then the client reads that. The file contains tags or instructions in the playlist that will describe what content is available, what the bitrates are and whether it’s live or playback (video on demand (VOD)). Then, it describes the various media files needed to go fetch the actual media and play back the stream.
- Media files — These media files are associated with the text files, and they are fetched from the same web server. As such, servers deliver enough audio or video content (in five- to 10-second pieces) to play for a while before going and getting more when it starts to run out.
So, media delivered using the HLS format are not “streams” per se, they’re instead progressive downloads that send segments of content data from regular web servers to devices, delivering the highest media quality and best playback experience possible for users — regardless of the connection, software or device being used.
To deliver the highest media quality, players monitor changing bandwidth conditions, checking the original text-based manifest file for the location of additional streams before looking to the stream-specific media file for the URL of the next chunk of media data, seamlessly switching between chunks.
The Advantages and Disadvantages of HLS
In terms of media streaming quality, HLS offers some major advantages:
- HLS is easy to deploy and designed for reliability.
- HLS is flexible. It allows you to play back audio, video and closed captioning of various bitrates.
- HLS is versatile. Content creators often have the option to encode the same livestream at multiple quality settings and viewers can dynamically request the best option available, given their specific bandwidth at any given moment. The adaptive bitrate means if the network is congested or if viewers/listeners have a poor network connection, they can go to a lower bitrate and get a smaller resolution video or lower bitrate audio.
- HLS is highly scalable. Due to the web technology that underlies HLS, it can easily scale for delivery using ordinary web servers across a global content delivery network (CDN).
- HLS is cost efficient. As noted, HLS is supported by just about every device — there’s no need to use a specific device to watch or listen to the content. Plus, standard web servers can handle HLS delivery without issues. And because HLS works through standard web servers, there isn’t a lot of (new) infrastructure involved to distribute it. Additionally, you can use your old authentication and encryption techniques.
- HLS can work as a playback mechanism. As such, any video, movie, song or podcast can be put into a web server and served up. Or live media content can be produced and added as time goes on. Clients will keep up and keep refreshing the new media to play it back.
- Through tags, HLS allows content creators and broadcasters to insert ads, closed captions and subtitles, fast forward and reverse playback, and alternate audio and video renditions in a simple standardized fashion.
In terms of disadvantages, the only disadvantage it used to have — which is being fixed now — is latency. Historically, HLS favored stream reliability over latency. Consequently, when content creators or broadcasters would go live with HLS, there would be a significant gap between live, or what’s happening right now, and the time the client would actually see the playback. But speed is the name of the game in livestreaming.
Fortunately, Apple heard the industry’s calls for lower latency and delivered an extension of the HLS protocol: Low-Latency HLS. Low-Latency HLS enables low-latency content streaming, promising to achieve sub-two-second latencies at scale, while also offering backward compatibility to existing clients. In May, the Low-Latency HLS specification was incorporated into the overarching HLS standard.
How To Deploy an HLS Stream — A Tutorial
As an industry standard, HLS has a lot of industry support. Many security cameras and other media hardware directly provide HLS as a source and clients to play their media over a network. Industry frameworks such as Amazon Kinesis Video Streams, VLC, FFmpeg, GStreamer and Wowza Streaming Engine support it. Therefore, all of the players and encoders based on those frameworks support it as well. Most tools that users need to create basic HLS production and consumption are already made or can easily be scripted to produce it.
In order to deploy HLS, users require just three things:
- Either an HTML page or a client app. A webpage can be complex and support trick modes and timelines or as simple as a single HTML video tag. Client applications require more work but will also provide more flexibility and support, as well as a more customized user experience.
- A web server or CDN. Hardware devices that support HLS will supply their own web server, and any client can stream media directly from them. Other systems will need to copy media and manifest files to a web server. This can be done in a variety of ways — through AWS or Azure, on a file system or via complex network protocols. Systems that anticipate heavy traffic will need to use or develop a content delivery network (CDN). Many CDNs allow for virtually infinite traffic and are very easy to scale.
- A method for encoding source material or livestreams as fragmented MPEG-4 media files containing high-efficiency video coding (HEVC) or H.264 video and advanced audio coding (AAC) or AC-3 audio. Hardware devices that support HLS will not need to be transcoded and can be directly streamed. Almost any media can be transcoded to a format supported by HLS standards. There are many tools available to do this. Many of the best ones are free, but there are commercial products that can import media and then export HLS to just about any destination. This is the stage where a system defines the bitrates (file sizes) that it will support.
With those three requirements in place, deploying HTTP live streaming is as simple as creating an HTML page or client application, configuring your web server as normal (or using a CDN), validating your streams using a media stream validator that both simulates an HLS session and verifies that the index file and media chunks conform to the specification, encrypting key media files and publishing your content.
A great solution for media distribution, HLS is simple, scalable and secure, and it ensures the best possible viewing experience from any device, anytime, anywhere. If you’re interested in delivering content everywhere, give us a call! Our expert engineers leverage decades of cable and video industry experience to make sure you and your customers will have the best possible streaming experience.