Skip to content

Commit

Permalink
Adding pages for adpative bitrate streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
allenheltondev committed Oct 9, 2024
1 parent 7d89e26 commit 5e784de
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 3 deletions.
56 changes: 55 additions & 1 deletion docs/mediastore/performance/adaptive-bitrates/dash.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 1
sidebar_position: 3
sidebar_label: DASH
title: Dynamic Adaptive Streaming over HTTP
description: Learn about the Dynamic Adaptive Streaming over HTTP (DASH) protocol and how it works
Expand All @@ -17,3 +17,57 @@ keywords:
- abr
- bitrate
---

# What is DASH (Dynamic Adaptive Streaming over HTTP)?

DASH (Dynamic Adaptive Streaming over HTTP) is an [adaptive bitrate streaming protocol](/mediastore/performance/adaptive-bitrates/how-it-works) that allows video to be delivered smoothly over the internet by adjusting the quality of the stream in real time based on a video player's available bandwidth. Like [HLS](/mediastore/performance/adaptive-bitrates/hls), DASH breaks video content into [segments](/mediastore/core-concepts/segments) and delivers them over HTTP. It allows players to dynamically switch between quality levels, ensuring a buffer-free experience, even when network conditions fluctuate.

## How DASH works

DASH works by dividing content into small segments and providing a **manifest file** (called an MPD — Media Presentation Description) that lists all available segments at different bitrates and resolutions. Aa video player uses this manifest to request the correct segments for playback based on current network conditions. If bandwidth is high, the player streams higher-quality segments, but if it drops, the player switches to lower-quality segments to avoid interruptions.

### The DASH workflow

DASH follows a similar workflow to other adaptive bitrate streaming protocols like HLS, but it uses different formats and segment structures. Here’s an overview of how it works:

1. **Encoding and segmenting** - The source video is encoded into multiple bitrates and resolutions. Each version of the video is divided into small segments, typically between **2 to 10 seconds** in length. These segments are stored using unique **key names**.

2. **Manifest file (MPD)** - An MPD file is generated, listing the available segments at different quality levels. The MPD file contains information about each segment’s bitrate, resolution, and the corresponding URL or key name for each segment.

3. **Segment delivery** - The video segments and MPD file are stored on the [origin](/mediastore/core-concepts/origin). The player retrieves the MPD and uses it to download the appropriate segments from a **content delivery network (CDN)**. The player dynamically adjusts the stream quality based on changing network conditions.

4. **Dynamic switching** - As network bandwidth fluctuates, the player dynamically switches between different quality levels by fetching different segments as specified in the MPD file.

## How DASH Differs from HLS

While both DASH and HLS are adaptive bitrate streaming protocols, there are a few key differences between them:

* **Compatibility** - HLS is natively supported by Apple devices (iOS, macOS), while DASH is more broadly supported across other platforms like Android and most web browsers.

* **File format**- DASH uses an *MPD* file as the manifest, whereas HLS uses an `.m3u8` playlist. The underlying segment format in DASH is typically `.m4s` (MPEG-4 Segment), while HLS uses `.ts` (MPEG-2 Transport Stream) segments.

## DASH with Momento MediaStore

Momento MediaStore stores both the **segments** and the **MPD file**. Each segment is stored with a unique **key name**, referenced by the MPD file, making it easy for the player to request the correct segment for playback. For example, a *1080p* segment might be stored as `segment-1080p-0001.m4s`, while a *720p* version of the same segment might be stored as `segment-720p-0001.m4s`.

The MPD file lists these key names, guiding the player on which segments to download based on current bandwidth conditions. Here's an example of how an MPD file might look for adaptive bitrate streaming (ABR) in DASH:

```xml
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.5S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
<Period>
<AdaptationSet>
<Representation id="1080p" bandwidth="5000000" width="1920" height="1080">
<SegmentTemplate media="segment-1080p-$Number$.m4s" startNumber="1" duration="2000" />
</Representation>
<Representation id="720p" bandwidth="3000000" width="1280" height="720">
<SegmentTemplate media="segment-720p-$Number$.m4s" startNumber="1" duration="2000" />
</Representation>
<Representation id="480p" bandwidth="1500000" width="854" height="480">
<SegmentTemplate media="segment-480p-$Number$.m4s" startNumber="1" duration="2000" />
</Representation>
</AdaptationSet>
</Period>
</MPD>
```

In this example, the player refers to the MPD to choose the appropriate segments for *1080p*, *720p*, or *480p* streams, depending on the available bandwidth. The player begins streaming by requesting the first segment based on the current available bandwidth. As the stream progresses, the player continually monitors network conditions and adjusts the bitrate accordingly. **Momento MediaStore** ensures fast, low-latency access to these segments, enabling quick switching between quality levels and minimizing buffering.
62 changes: 60 additions & 2 deletions docs/mediastore/performance/adaptive-bitrates/hls.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
sidebar_position: 2
sidebar_label: HLS manifests
title: HLS manifests
sidebar_label: HLS
title: HLS
description: Discover what an HLS manifest is and how to create one with Momento MediaStore.
pagination_next: null
hide_title: true
Expand All @@ -16,4 +16,62 @@ keywords:
- serverless
- abr
- bitrate
- hls
---

# What is HLS (HTTP Live Streaming)?

HLS (HTTP Live Streaming) is a widely-used [adaptive bitrate streaming protocol](/mediastore/performance/adaptive-bitrates/how-it-works) that breaks video content into small chunks called [segments](/mediastore/core-concepts/segments) and delivers them over HTTP. A video player can dynamically adjust the quality of the stream depending on network conditions, ensuring smooth playback with minimal buffering. HLS has become one of the most popular streaming protocols, supported by most modern devices and browsers.

## How HLS works

HLS works by dividing media into segments and providing a **playlist file** (typically an `.m3u8` file) that lists all available segments at different bitrates and resolutions. Video players use this playlist to fetch the correct segments for playback based on the available bandwidth. If the network is strong, the player can stream higher-quality segments (i.e. *1080p at 5mbps*). If the network slows down, the player switches to lower-quality segments (i.e. *720p at 3mbps*) to prevent buffering.

### The HLS Workflow

HLS involves several key components:

1. **Encoding and segmenting** - The source video is encoded into multiple bitrates and resolutions. Each version of the video is divided into segments typically between **2 to 10 seconds** in length. These segments are stored using unique **key names**.

2. **Playlist file (manifest)** - A playlist file (in `.m3u8` format) is generated that lists the available segments. The player refers to this playlist to download segments from a CDN point of presence (PoP). The playlist contains URLs or key names that point to specific segments.

3. **Segment delivery** - The segments and playlist file are stored on the [origin](/mediastore/core-concepts/origin). The player retrieves the playlist and uses it to download the appropriate segments.

4. **Dynamic switching** - As network bandwidth fluctuates, the player switches quality levels by fetching different entries from the playlist file.

## HLS Advantages

HLS offers several key benefits that have made it a dominant streaming protocol:

* **Wide compatibility** - Supported on a wide range of devices, including iOS, macOS, Android, and most web browsers, making it ideal for delivering content to a large, diverse audience
* **Scalability** - Delivered over standard HTTP, which works well with CDNs, enabling scalable content delivery to a global audience
* **Adaptive bitrate streaming** - Uses ABR to ensure the player always receives the best possible video quality without interruption
* **Support for live and on-demand content** - Supports both live streaming and video-on-demand (VOD) content

## HLS with Momento MediaStore

Momento MediaStore stores both the **segments** and the **playlist file**. Each segment is stored in Momento MediaStore using a unique key name, which is referenced in the playlist. For example, a segment for a *1080p* stream might have the key name `segment-1080p-0001.ts`, while a lower quality version like *720p* would be stored as `segment-720p-0001.ts`.

The playlist file (`.m3u8`) would then list these key names, directing the player to fetch the appropriate segment based on available bandwidth. Here's an example of how a playlist for [ABR (Adaptive Bitrate Streaming)](/mediastore/performance/adaptive-bitrates/how-it-works) might look when stored in Momento MediaStore:

```plaintext
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
segment-1080p-0001.ts
#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1280x720
segment-720p-0001.ts
#EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=854x480
segment-480p-0001.ts
#EXT-X-STREAM-INF:BANDWIDTH=600000,RESOLUTION=426x240
segment-240p-0001.ts
```

In this example, the player would begin by downloading the playlist, then request segments (`.ts` files) based on the network conditions. As the stream progresses, the player continuously monitors network conditions. If the network speed decreases, the player will request lower-quality segments to prevent buffering. Conversely, if the network improves, the player will switch to higher-quality segments.

This ability to seamlessly switch between bitrates is what makes **adaptive bitrate streaming (ABR)** powerful. The playlist ensures that the player always has access to the best segment for the current network conditions.

## How Momento MediaStore enhances HLS performance

With **Momento MediaStore**, the segments and playlist file are stored in an in-memory architecture, making it ideal for low-latency, high-performance HLS streaming. By including the segment **key names** in Momento Mediastore, video players can fetch segments directly from Momento extremely quickly, which is crucial for maintaining smooth, uninterrupted playback. When network conditions fluctuate, the player can rapidly switch between segments at different bitrates without delay.

In addition, Momento’s reliability and scalability ensure that the origin can handle high traffic and deliver segments efficiently, even during live events with large audiences. This minimizes latency and improves [zero buffer rate (ZBR)](/mediastore/core-concepts/zero-buffer-rate), providing viewers a seamless, buffer-free experience.
43 changes: 43 additions & 0 deletions docs/mediastore/performance/adaptive-bitrates/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,46 @@ keywords:
- abr
- bitrate
---

# How do adaptive bitrates work?

Adaptive bitrate streaming (ABR) is a technique that allows video players to deliver the best possible streaming experience under varying network conditions. By dynamically adjusting the quality of the video being streamed based on the viewer's available bandwidth, ABR ensures continuous playback with minimal interruptions like buffering. This method allows viewers to receive the highest quality video their connection can handle, while also preventing jarring playback pauses.

## How video players use adaptive bitrates

Video players use [ABR ladders](/mediastore/core-concepts/abr-ladder), a set of different video resolutions and bitrates, to provide smooth playback. When a video starts, the player first assesses the available network bandwidth by downloading a [segment](/mediastore/core-concepts/segments) of the video. Based on the speed of this download, the player initially selects a bitrate that matches the current bandwidth. As the video continues to stream, the player continuously monitors network conditions, adjusting the video quality on the fly.

### Dynamic quality adjustments

The heart of ABR lies in the ability of video players to dynamically switch between different **rungs** of the ABR ladder based on network conditions. If the bandwidth remains high, the player continues to stream higher-quality video (for example, *4K at 20mbps* or *1080p at 5mbps*). If the bandwidth drops, the player will automatically switch to a lower-quality version, such as *720p at 3mbps*, to ensure uninterrupted playback.

The player does this by downloading **segments** of the video in different bitrates and resolutions. Each segment represents a small chunk of video, typically a few seconds long, which allows the player to adjust the quality frequently without disrupting the viewer’s experience. The segments are stored on the [origin](/mediastore/core-concepts/origin) and delivered via a **content delivery network (CDN)**. The player can quickly request different quality segments as the network conditions change, ensuring that playback remains smooth.

### Manifests

To enable this flexibility, video players rely on a **manifest file** (known as an *MPD* in [DASH](/mediastore/performance/adaptive-bitrates/dash) or a *playlist* in [HLS](/mediastore/performance/adaptive-bitrates/dash)). This manifest provides a list of all available segments for a given video, along with the corresponding bitrates and resolutions. The player uses this file to decide which version of the video to download next.

For example, the manifest might list:
- **4K at 20 Mbps**
- **1080p at 5 Mbps**
- **720p at 3 Mbps**
- **480p at 1.5 Mbps**
- **240p at 600 Kbps**

The video player starts with one bitrate and resolution, and as the network fluctuates, it switches between these rungs by requesting the appropriate segments from the CDN.

## Look-ahead buffers

Another critically important part of how video players work with ABR is buffering. To avoid playback interruptions, video players maintain a **look-ahead buffer**, which contains several seconds or even minutes of upcoming content that has been preloaded. If the network connection slows down or drops temporarily, the player can continue to stream from this buffer without pausing.

ABR helps maintain this buffer by ensuring that the player always selects a bitrate it can sustain based on current network conditions. If the player detects that the buffer is depleting too quickly (due to slow segment delivery), it will switch to a lower bitrate to refill the buffer faster, preventing that jarring pause experience mentioned earlier. By utilizing Momento MediaStore as the origin for segments, players can quickly retrieve segments to refill their buffers, minimizing the chance of interruptions and maintaining smooth playback. This is critical for maintaining a high [zero buffer rate (ZBR)](/mediastore/core-concepts/zero-buffer-rate), which is the percentage of your viewers who stream with no buffering events.

## Improving the viewer experience

The key advantage of ABR is its ability to provide the best possible video quality without requiring the viewer to manually select the resolution. Whether a viewer’s network is fast, slow, or fluctuating, the player adjusts automatically between rungs of the ABR ladder. This results in:

* **Better quality when available** - Viewers can enjoy high-definition or 4K content when their connection supports it
* **Minimal interruptions** - Even on slower connections, the player ensures that playback continues at a lower quality rather than pausing or buffering frequently
* **Automatic adjustments** - Viewers don’t have to worry about manually switching resolutions when their bandwidth changes

By dynamically adjusting the video quality, ABR significantly improves the viewer experience, reducing frustration caused by buffering and pauses.

0 comments on commit 5e784de

Please sign in to comment.