QUICK START:PatternsErrors & FixesSecurityBenchmarksDevOps RecipesCheatsheetsInterviewCompareTopicsHTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsLinux & UbuntuKotlinSwiftC# / .NETJavaGoRustC++DSASystem DesignDevOpsCybersecurityAI / ML
AdvancedWeb & Load Balancing

FFmpeg HLS Video Transcoding & Adaptive Bitrate

Prepare video content for modern web streaming by encoding a master video file into multiple resolutions and generating HLS manifest playlists.

FFmpegBash

Prerequisites

  • FFmpeg installed (with x264/AAC support)

Configuration Files

transcode.sh./transcode.sh
ffmpeg -i input.mp4 \\\n  -preset fast -g 48 -sc_threshold 0 \\\n  -map 0:v:0 -map 0:a:0 -c:v:0 libx264 -b:v:0 2000k -s:v:0 1280x720 \\\n  -map 0:v:0 -map 0:a:0 -c:v:1 libx264 -b:v:1 1000k -s:v:1 854x480 \\\n  -c:a aac -b:a 128k \\\n  -f hls -hls_time 4 -hls_playlist_type vod \\\n  -master_pl_name master.m3u8 \\\n  -var_stream_map "v:0,a:0 v:1,a:1" stream_%v.m3u8
Explanation:Transcodes input into 720p and 480p streams, chunks them into 4-second .ts segments, and creates a master HLS playlist.

Verification Steps

1

Verifies the manifest file contains the generated streams.

$ffprobe master.m3u8
Expected OutputProgram 0 \n Stream #0:0: Video: h264

Production Gotchas

  • Keyframe interval (-g) must be aligned with the HLS segment time to ensure seamless segment switching for players.

Frequently Asked Questions

What does adaptive bitrate mean?

The video player automatically switches between different quality streams depending on the user's current internet speed.