Skip to content

taiphanvan2k3/video-download-techniques

Repository files navigation

Video Download Techniques

1. Progressive Download

βœ… Progressive Download is not a different protocol but rather how browsers progressively download and play video using HTTP Range Requests.

How it works:

  • When the browser encounters a <video> tag, it will:
    • Send requests with Range header to get a byte segment of the file
    • Server returns HTTP 206 Partial Content with that data portion
    • Browser buffers and plays immediately while continuing to download

πŸ‘‰ Progressive Download: fetch by range to play immediately without waiting for the entire file to download.

Technical Features:

  • Browser sends HTTP Range Requests to download video in parts
  • Any server returns HTTP 206 Partial Content for requested segments
  • <video> tag progressively loads and plays, allowing seeking to the middle of the video

Advantages:

πŸ‘€ Progressive Download is not a new protocol, just HTTP + range requests for video serving. β†’ No need for custom server if current server supports HTTP Range (Nginx, http-server, Express static, MinIO, S3, CDN all support it).

πŸ“Œ Whether local file or HTTP, browser still sends range requests and handles progressive download automatically.

Implementation Examples:

Custom server to return video file by range request: Custom Server

Video tag + local file still supports range request: Local File Support

Progressive Download doesn't require a "custom server" - it's simply using HTTP Range to download video in parts. The server can be any HTTP server that supports Range (static server, S3, MinIO, CDN, Express, Nginx,...)

2. HLS (HTTP Live Streaming) Download

HLS is a popular video streaming protocol that divides video into small .ts segments and uses .m3u8 playlist files for management.

🎯 Key Concept: HLS Doesn't Wait for Full Video Download

βœ… HLS doesn't require downloading the entire video before playing β€” it downloads in chunks (segments) and the player can start playing immediately when enough data from the first chunks is available. This is the core principle of HLS streaming over HTTP.

Why HLS Streams Quickly and Doesn't Wait for Full Video

πŸ“Œ HLS divides video into small segments (e.g., each ~5-10 seconds). These segments are listed in the .m3u8 playlist. When the player starts:

  • Player downloads the playlist (.m3u8) first β†’ knows the list of segments to load
  • Player only downloads the first few segments for buffering, then plays immediately β†’ no need to download the entire large video file first
  • While playing, player downloads the next segment in sequence β†’ each segment is loaded separately via HTTP GET β†’ streams in small chunks

Difference from Progressive Download

πŸ”Ή Progressive download loads byte ranges within the same MP4 file using Range requests. β†’ Browser can start playing when the first portion has enough buffer.

πŸ”Ή HLS loads small segment files, doesn't wait for the entire video to be on the client, because the player only needs the first few segments. β†’ HLS has a more structured approach for adaptive bitrate, live streaming, seeking, and fast-forwarding.

πŸ“Œ This is why you see:

βœ” HLS video starts playing almost immediately βœ” In DevTools you see each segment loaded separately (.ts files) βœ” Player doesn't download the entire video before playing β€” it streams in chunks like true streaming

⏱ This helps:

  • Reduce video startup time
  • Only load necessary data
  • Enable adaptive bitrate (load appropriate quality)
  • Work efficiently with live streaming or video on demand

🧠 Summary

πŸ“Œ HLS supports playback immediately when only the first few segments are loaded πŸ“Œ Doesn't "wait for the entire video to download" πŸ“Œ Player continuously downloads the next segment while playing πŸ“Œ This is the characteristic of adaptive, chunk-based streaming β‰  traditional progressive download

Create Simple HLS Files:

ffmpeg -i ubuntu_installation.mp4 -c:v libx264 -c:a aac -b:a 128k -f hls -hls_time 10 -hls_list_size 0 hls/ubuntu_installation/master.m3u8

This command will create:

  • 1 playlist master.m3u8
  • Segment .ts files in the hls/ubuntu_installation directory

Create HLS with Multiple Qualities (Adaptive Bitrate):

ffmpeg -i ubuntu_installation.mp4 \
  -vf "scale=1920:-2" -c:v libx264 -b:v 5000k -c:a aac -b:a 192k \
  -hls_time 10 -hls_playlist_type vod \
  -hls_segment_filename "hls/ubuntu_installation/1080p_%03d.ts" \
  hls/ubuntu_installation/1080p.m3u8 \
  -vf "scale=1280:-2" -c:v libx264 -b:v 2500k -c:a aac -b:a 128k \
  -hls_time 10 -hls_playlist_type vod \
  -hls_segment_filename "hls/ubuntu_installation/720p_%03d.ts" \
  hls/ubuntu_installation/720p.m3u8 \
  -vf "scale=854:-2" -c:v libx264 -b:v 1200k -c:a aac -b:a 96k \
  -hls_time 10 -hls_playlist_type vod \
  -hls_segment_filename "hls/ubuntu_installation/480p_%03d.ts" \
  hls/ubuntu_installation/480p.m3u8

HLS Creation

Run HLS Server:

http-server ./hls/ubuntu_installation -p 8080 --cors

Frontend Usage:

In the frontend, simply call the master.m3u8 file. The browser will:

  • Read the master playlist content
  • Select appropriate quality based on internet connection
  • Automatically download and play segments

Master Playlist

HLS Streaming

Quality Selection

HLS Server

3. HLS vs Progressive Download Comparison

πŸ”Ή 1) Fast Loading & Playback

βœ… Both HLS and Progressive Download allow fast startup without waiting for the entire video to download.

  • Progressive Download: Loads byte ranges within a single file β†’ starts when buffer is sufficient
  • HLS: Loads small segments β†’ starts when first few segments are ready

➑ But HLS usually starts faster and is more optimized, because the player only needs to load a few short segments instead of ranges within a large file.

πŸ”Ή 2) Adaptive Bitrate (Quality Adaptation)

πŸ“ This is HLS's biggest advantage:

πŸ”Έ HLS supports Adaptive Bitrate Streaming (ABR)

  • HLS has a master playlist listing different qualities
  • Player automatically switches to appropriate quality based on bandwidth (reduces stuttering/buffering when network is weak)

πŸ”Έ Progressive Download doesn't support Adaptive

  • Only has 1 quality in 1 MP4 file

πŸ“Œ Conclusion: If network is unstable or you want to optimize UX for multiple devices, HLS is better than Progressive.

πŸ”Ή 3) Bandwidth Optimization & CDN

πŸ”Ή HLS only loads segments that users actually watch β†’ If user only watches 1/3 of video, only the first few segments are loaded β€” saves bandwidth.

πŸ”Ή Progressive Download gradually loads the entire file even if user doesn't watch it all β†’ potential bandwidth waste.

πŸ”Ή HLS small segments help CDN cache efficiently, serving multiple users simultaneously better.

πŸ”Ή 4) Scalability & Distribution

⭐ HLS is widely used in real streaming systems, especially with CDN β€” because:

  • Player can load segments from different edge servers
  • Easy to distribute to millions of users globally

While Progressive Download is a simpler technique, good for small content or single-viewer environments.

πŸ”Ή 5) Live Streaming Support

❌ Progressive Download is not suitable for live streaming βœ” HLS supports live streaming by continuously providing new playlists and segments while video is playing.

πŸ‘‰ If you want to stream live events (live events, cameras...), HLS is the clear choice.

πŸ”Ή 6) Setup Complexity

βœ” Progressive Download is very simple: just HTTP server and standard MP4 file ❗ HLS requires additional steps: create segments + playlist, then set up server to serve segment directory

πŸ‘‰ HLS is slightly more complex, but the superior benefits β€” adaptive, CDN, live β€” make it the current standard method.

πŸ“Š Comparison Table

Feature Progressive Download HLS (HTTP Live Streaming)
File Structure Single MP4 file Multiple small .ts segments + .m3u8 playlist
Adaptive Bitrate ❌ Not supported βœ… Supported - Multiple qualities, auto-switch
Live Streaming ❌ Not supported βœ… Supported - Perfect for live events
CDN Compatibility ⚠️ Basic βœ… Excellent - Segment-based caching
Startup Speed βœ… Fast βœ… Faster - Only needs first few segments
Scalability ⚠️ Good for small audiences βœ… Excellent - Handles millions of users
Seek/Scrubbing βœ… Supported βœ… Supported - Better with segments
Setup Complexity βœ… Simple - Just HTTP server ⚠️ More complex - Requires segmentation
Network Recovery ⚠️ Fixed quality, may buffer on bad network βœ… Better - Can adapt quality
Storage Requirements βœ… Single file ⚠️ Multiple files (segments + playlist)

πŸ“Œ When to Use HLS?

🟒 Choose HLS when you need:

  • βœ… Unstable user networks - Adaptive bitrate prevents buffering
  • βœ… Large-scale distribution - Serving many users across countries
  • βœ… Quality adaptation - Automatic quality switching based on bandwidth
  • βœ… Live streaming support - Perfect for live events and real-time content
  • βœ… CDN optimization - Efficient bandwidth usage and global distribution

❗ Choose Progressive Download when:

  • βœ… Simple projects - Small video files, straightforward implementation
  • βœ… Single quality - No need for adaptive bitrate features
  • βœ… Limited audience - Not requiring CDN distribution
  • βœ… Basic functionality - Just need video to play reliably

Demo Files

  • progressive-download.html - Examples of progressive download (server-based and local file)
  • hls-basic.html - Basic HLS player with automatic quality selection
  • hls-quality-selector.html - HLS player with manual quality selection control

About

Simple trials with the Progressive Download and HLS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors