Live Streaming Basics - devrath/MediaAlchemySuite GitHub Wiki

How HLS (.m3u8) and DASH (.mpd) segment and deliver live video content:

πŸ”„ Core Concept: Segmented Streaming

  • Both HLS(Http Live Streaming) and DASH(Dynamic Adaptive Streaming over Http) deliver live(on demand) content.
  • They do this by,
    • Splitting the Live segment into small chunks(segments) of a few segments.
    • Using the manifest to list these segments
    • Using the player to adapt the bit-rate dynamically based on network conditions.

πŸ“Ί HLS (HTTP Live Streaming)

  • Manifest File: .m3u8
  • Segment duration is 2-6 seconds.
  • Live streaming uses a sliding window playlist by continuously removing old segments & updating new segments available.
  • Adaptive bit rate uses the master playlist pointing to multiple variant playlists (different resolution).
#EXTM3U
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:123
#EXTINF:6.0,
file123.ts
#EXTINF:6.0,
file124.ts

πŸ“¦ DASH (MPEG-DASH)

  • Manifest file: .mpd
  • XML-based manifest file.
  • Live Streaming: Also supports sliding window for live edge control.
  • AdaptationSet: Defines tracks for different qualities (bitrate/resolution/codec)
<AdaptationSet mimeType="video/mp4" codecs="avc1.42E01E" bandwidth="500000">
  <SegmentTemplate media="video_$Number$.m4s" startNumber="100" duration="2000"/>
</AdaptationSet>

Differences in HLS and DASH

Feature HLS DASH
Manifest File Extension .m3u8 .mpd
Segment Format .ts, .aac, .m4s .m4s
Live Window Support βœ… Sliding playlist βœ… Sliding or timeline-based
Bitrate Adaptation Master playlist w/ variants AdaptationSet in MPD
DRM Support FairPlay Widevine, PlayReady
Compatibility Best on Apple devices Broad cross-platform support

Segments

πŸ“¦ What are Segments (Chunks)?

A live stream is not sent as a single continuous file; instead, they are sent as smaller segments/chunks, usually 2 to 10 seconds long.

🧠 Why Use Segments?

  • βœ… Efficient delivery: Players can buffer small chunks quickly
  • 🌐 Adaptive bitrate: Player can switch between lower/higher quality between segments based on network speed.
  • πŸ” Seek & Rewind: Enables seeking within the live window.
  • 🧩 Caching & CDN: Makes it easier to cache content via CDNs.

Live Streaming with Segment Fetching

                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚     Live Video Source        β”‚
                 β”‚  (e.g., Camera, Encoder)     β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚     1. Segmenter creates small chunks      β”‚
        β”‚      (e.g., 6s .ts/.m4s segments)          β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ 2. Manifest (.m3u8 or .mpd) updated        β”‚
        β”‚    β†’ Lists segment URLs                    β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚     3. Player downloads the manifest       β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ 4. Player fetches the latest segment(s)    β”‚
        β”‚    β†’ Chooses bitrate based on bandwidth    β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚     5. Buffer + Decode + Display           β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Example Timeline (Live Window)

     Time ─────────────────────────────────────────▢

          [Segment 100] [Segment 101] [Segment 102] ...
          |   6 sec    |   6 sec     |   6 sec     |

               ↑
         Player is here (Live Edge)
  • The player continuously polls the manifest to check for new segments.
  • The manifest "slides" as new segments are added and old ones expire (live window behavior).
  • Adaptive Bitrate is handled by selecting the segment URL from a variant list.

🎬 HLS Playlist Types

Playlist Type Description Seekable? Grows Over Time? Ends?
VOD Static, pre-recorded content βœ… Yes ❌ No βœ… Yes
EVENT Like a live event with a defined beginning, but no end yet βœ… Yes (from start) βœ… Yes βœ… Eventually
LIVE Truly live stream; shows only a sliding window of recent segments πŸ” Only recent βœ… Yes ❌ No

πŸ“Š Live vs VOD - Timelines & Seekability

Feature VOD (Video on Demand) Live Streaming
Timeline Fixed, known from start to end Dynamic, grows as time passes
Seekability Full seeking allowed (start ↔ end) Limited seeking (within live window only)
Live Window Not applicable Sliding window (e.g., last 3–5 mins)
Start Position User can start at any point Usually starts at the live edge or behind by offset
Duration Known and static Unknown, increases continuously
Use Case Movies, shows, recorded content News, sports, events, webinars

VOD: Like watching a downloaded movie β€” you control everything.

Live: Like tuning into a TV channel β€” you’re limited to what's being broadcast now, with some ability to rewind if a live window exists.