A Guide on HTTP Live Streaming (HLS)
So you’re watching a match of NLF on your iPhone through the ESPN app, and you notice a toast message that says “3 million people are watching.” That’s 3 million people watching the match in real-time at full-HD [or 4k if they want to see the sweat falling off of the players].
But did you ever wonder how ESPN could stream the match to so many people? Let’s have it; you’re here because you did.
Let’s look at the technology that allows ESPN [and others like Netflix, Disney+, et al.] to stream live video to millions of people.
For the uninitiated, live streaming is the broadcast of video and audio content over the internet, usually through a web viewer or an application. It has quickly become one of the most popular ways to consume online content because it gets viewers more engaged in the content when compared with pre-recorded videos or static blogs.
Live streaming has been a thing since the late 90s, but it caught steam in the mid-2000s with advancements in broadband and the subsequent fall in the per-gigabyte price.
There are tons of technologies out there today that help people create streaming platforms, like RTMP, HLS, SRT, and others.
This blog focuses on HLS. We go over what it is, how it works, and when you should consider using it over the other technologies.
What is HLS?
HTTP Live Streaming, or HLS, is a technology that allows you to create a platform to stream audio and video content over the internet in real-time. Top streaming companies like Apple, Facebook, and Netflix use it to deliver content to millions of people worldwide. And now, with Dyte, you can quickly add the ability to live stream to your product.
At its core, HLS dynamically segments and transmits media over HTTP—aka, breaks down the video content into smaller data segments, which are sent out to players in real-time.
This helps improve the consumption of your video content because now your viewers will have better control over the playback and can adjust it according to their network speeds and conditions.
A Brief History of HLS
HLS was developed by Apple Inc. and introduced in 2009 as part of the iPhone Operating System 3. HLS was revolutionary because it allowed audio and video content to be streamed over the internet reliably, even on slower connections [thanks to breaking down the video into small chunks of data].
Initially, it was limited in its capabilities, only allowing a few minutes of audio or video streaming on devices running Apple's iOS platform.
However, since then, it has seen incredible technological improvements that have allowed it to become one of the most popular streaming technologies today. HLS now allows multiple audio or video stream resolutions and can handle high-definition live streaming with little latency or buffering.
It also supports adaptive bitrate streaming, which adjusts streams based on bandwidth fluctuations, so there will not be any interruptions in playback experienced by viewers.
The longevity and success of HLS have made it the go-to streaming technology used by platforms such as YouTube, Netflix, Amazon Prime Video, Hulu, Twitch, Facebook, and more for both live and on-demand streaming needs.
It is truly remarkable how far HLS has come from its early days - proving once again that innovative thinking can benefit us all in the long run! The advantages of using HLS over other streaming platforms are numerous – from scalability and bandwidth efficiency to superior Quality of Service (QoS).
How Does HLS Work?
HLS divides media content into smaller data segments transmitted to players in real time.
This allows viewers to adjust the video playback according to their network speeds and conditions.
To illustrate, let's look at the following example:
Let's assume there is a video with ten seconds per segment that lasts one hour. That means you have a total of 360 segments. The segments are in .ts file format and are chronologically numbered, so the directory would look something like this:
segments/
00001.ts
00002.ts
00003.ts
Each segment is downloaded and played while the video is being streamed. You can configure segments as short as a few seconds that minimize the latency associated with live buffering. These segments are also cached in case the player loses connection to the network.
You can also create each video segment with different resolutions and bitrates with HLS. If you consider the above example, HLS allows you to create:
- 360 segments at 360p
- 360 segments at 720p
- 360 segments at 1080p
Now, let's see how the directory would look like:
360p/
00001.ts
00002.ts
00003.ts
720p/
00001.ts
00002.ts
00003.ts
segments/
1080p/
00001.ts
00002.ts
00003.ts
Depending on the available bandwidth and network strength, the video player can select segments that will be downloaded and played. That means if you are watching the stream at lower bandwidth, the player picks and plays video segments at 360p. If you have a stronger internet connection, you get the segments at 1080p.
What is Adaptive Bitrate Streaming?
Adaptive bitrate streaming is a key feature of HLS. It allows viewers to dynamically adjust the video playback according to their network speeds and conditions. This helps ensure that videos are delivered efficiently and reliably, even on low-bandwidth or unstable networks.
Adaptive bitrate streaming is especially useful in real-world applications such as live video broadcasts and online conferences, where there is often a large amount of variability in network conditions. However, even on-demand video streaming services can benefit from the improved performance and reliability of HLS
HLS Streaming Components
To fully understand how HLS works; it's important to take a closer look at some of the key components of this streaming protocol. These include media segmentation, delivery protocols (e.g., HTTP), and playback mechanisms.
HLS Server (Media Server)
The first step in HLS streaming is media segmentation, where the video content is split into smaller data segments. This typically involves using a specialized server called an HLS server or server, which divides the video content and then distributes it to viewers' devices via HTTP.
There are a variety of different HLS servers that you can use, depending on your specific needs and budget. For example, some popular HLS server options include Wowza Media Server, Kaltura, Adobe Dynamic Streaming, and Bitmovin.
Content Delivery Network (CDN)
A CDN is a network of servers worldwide that helps distribute the load of delivering content to viewers. When watching a live stream, your device will connect to a server in the CDN closest to your location. This helps to ensure no lag or buffering in the video feed.
HTML5 Player
The last component is the player itself. The software that you use to watch the live stream. Most people use an HTML5 player such as JW Player or VideoJS. These players are designed to work with a variety of different devices and browsers, which makes them ideal for live streaming purposes.
With all three of these elements in place, you'll be well on your way to providing a high-quality live-streaming experience for your viewers.
When to Use HLS Streaming?
- If you're streaming live video: The adaptive bitrates and built-in redundancy of HLS streaming will help ensure a smooth viewing experience for all your viewers.
- If you're looking for maximum compatibility: the HLS protocol can be played on any device.
- If you have the budget: While HLS streaming is a bit more expensive than some other protocols, it could be worth the investment depending on your needs.
- To prevent piracy: HLS is a video-on-demand technology that supports encryption (DRM), making it more difficult for pirates to access the content.
HLS Vs WebRTC Vs RTMP
Let’s have an unbiased look at the leading video streaming technologies so that you can decide what would work the best for your use case.
RTMP | HLS | WebRTC | |
---|---|---|---|
Protocol Type | Flash-based | HTTP-based | Open-source/peer-to-peer |
Supported Browsers/Devices | Almost every browser (except Safari), most encoders and media players | Several Android browsers and devices, Apple Safari and all recent iOS browsers and devices | Google Chrome, Firefox, and Microsoft Edge |
Use cases | Live broadcasts, on-demand content delivery, recordings | Live broadcasts, on-demand content delivery, and recordings | Live chat, gaming, remote collaboration |
Pros | Popular protocol with wide support It is easy to set up Suitable for high bitrate streams | Suitable for mobile streaming Can be used with existing HTTP infrastructure Scalable | Low latency Can be used without plugins or downloads Scalable |
Cons | Require Adobe Flash Player plugin which is discontinued by Adobe | Requires additional server infrastructure which is not supported by all browsers/devices | A newer protocol with limited browser support which requires additional infrastructure |
Advantages of HLS
In addition to its support for a wide range of internet connections, HLS also offers several other key advantages over streaming protocols such as WebRTC and RTMP. These include:
- Lower Bitrates: HLS typically allows you to achieve better compression ratios, which means fewer bits are needed to deliver the same quality video content online.
- Support for Live and On-Demand Video: HLS can be used for both live video broadcasts and on-demand streaming services, allowing you to deliver a high-quality viewing experience even under variable network conditions.
- Option to Use Third-Party CDNs: Whether you're delivering live or on-demand content, HLS also allows you to easily integrate with third-party content delivery networks like Akamai and Limelight.
- Support for Multiple Streaming Protocols: HLS is fully compatible with other streaming protocols, such as MPEG DASH, meaning it can coexist with existing video formats in your content delivery workflow.
Livestream HLS With Dyte
Dyte offers a platform for live streaming that is easy to use and set up. With Dyte, you can easily integrate HLS into your existing video workflow without any additional servers or infrastructure. You’ll have access to high-quality streams with low latency and wide device support.
To do so, sign up to Dyte first.
There are two modes of operation for Dyte Livestreaming:
1. Livestreaming Independently
2. Livestreaming a Meeting
You can use these modes to manage a variety of livestream scenarios. Here's what each of these means:
Independent Livestreaming: The best way to control what you stream and how it is distributed is to livestream independently. A livestream can be ingested from apps such as OBS, ffmpeg, and others, and played back using individual URLs.
Livestreaming a Meeting: If you want to stream a meeting to a large audience, this is a great option. With Dyte, you can automatically livestream a meeting and watch the livestream in high quality using APIs and SDK players. If you are creating a metaverse party or a hackathon, you could livestream it to an events platform, such as a virtual workspace for events.
Livestreaming Independently
You can generate credentials for an independent livestream by running the following command.
Request
curl --request POST \
--url https://api.cluster.dyte.in/v2/livestreams \
--header 'Authorization: Basic <token>' \
--header 'Content-Type: application/json'
Response
{
"success": true,
"data": {
"status": "OFFLINE",
"name": null,
"meeting_id": "188566bc-8770-4ca0-9eb3-24b594ecaf7e",
"ingest_server": "rtmps://2ec802dd47b0.global-contribute.live-video.net:443/app/",
"id": "7088bba8-f522-49a8-b59b-3cd0e946bbb0",
"stream_key": "sk_ap-south-1_AfnVpeYZjidO_fBpWKody7sDUOEfy9Zc6XAZegkR0Va",
"playback_url": "https://2ec802dd47b0.ap-south-1.playback.live-video.net/api/video/v1/ap-south-1.944908621410.channel.rVKA2KM5Lunt.m3u8"
}
}
To get a meeting's active livestream, run the following command.
Request
curl --request GET \
--url https://api.cluster.dyte.in/v2/meetings/{meetingId}/active-livestream \
--header 'Authorization: Basic <token>' \
--header 'Content-Type: application/json'
Response
{
"success": true,
"data": {
"status": "LIVE",
"name": null,
"meeting_id": "188566bc-8770-4ca0-9eb3-24b594ecaf7e",
"ingest_seconds": 0,
"viewer_seconds": 0,
"ingest_server": "rtmps://2ec802dd47b0.global-contribute.live-video.net:443/app/",
"id": "7088bba8-f522-49a8-b59b-3cd0e946bbb0",
"stream_key": "sk_ap-south-1_AfnVpeYZjidO_fBpWKody7sDUOEfy9Zc6XAZegkR0Va",
"playback_url": "https://2ec802dd47b0.ap-south-1.playback.live-video.net/api/video/v1/ap-south-1.944908621410.channel.rVKA2KM5Lunt.m3u8"
}
}
Livestreaming a meeting can be stopped by running the following command.
Request
curl --request POST \
--url https://api.cluster.dyte.in/v2/meetings/meetingId/active-livestream/stop \
--header 'Authorization: Basic <token>' \
--header 'Content-Type: application/json'
Response
{
"success": true,
"data": {
"message": "livestream stopped"
}
}
The Dyte livestreaming APIs are described in more detail on the Dyte Livestreaming APIs page.
Winding Up!
Whether you're a broadcaster looking to optimize your video workflow or a content creator looking for an efficient way to deliver high-quality video content online, HLS can help you achieve your goals. For this reason, many businesses and organizations today choose to use HLS streaming in their video content delivery workflows. And, with Dyte offering HLS out-of-box, you can easily integrate live streams into your product.