Skip to content

Instantly share code, notes, and snippets.

@rlaphoenix
Created April 18, 2022 17:26
Show Gist options
  • Save rlaphoenix/7e123a05c7171e39010ba5cd2a173ff3 to your computer and use it in GitHub Desktop.
Save rlaphoenix/7e123a05c7171e39010ba5cd2a173ff3 to your computer and use it in GitHub Desktop.
FFMPEG HLS script.
ffmpeg -i sample.mp4 \
-filter_complex \
"[0:v]split=4[v1][v2][v3][v4]; \
[v1]scale=w=1980:h=1080[v1out]; \
[v2]scale=w=1280:h=720[v2out]; \
[v3]scale=w=854:h=480[v3out]; \
[v4]scale=w=640:h=360[v4out]" \
-map [v1out] -c:v:0 libx264 -profile main -b:v:0 5000k -minrate 4500k -maxrate 5300k -bufsize 5000k -preset slow -g 120 -keyint_min 120 -sc_threshold 0 \
-map [v2out] -c:v:1 libx264 -profile main -b:v:1 3000k -minrate 2500k -maxrate 3200k -bufsize 3000k -preset slow -g 120 -keyint_min 120 -sc_threshold 0 \
-map [v3out] -c:v:2 libx264 -profile main -b:v:2 1500k -minrate 1250k -maxrate 1600k -bufsize 1500k -preset slow -g 120 -keyint_min 120 -sc_threshold 0 \
-map [v4out] -c:v:3 libx264 -profile main -b:v:3 800k -minrate 700k -maxrate 900k -bufsize 800k -preset slow -g 120 -keyint_min 120 -sc_threshold 0 \
-map a:0 -c:a:0 aac -b:a:0 192k -ac 2 \
-map a:0 -c:a:1 aac -b:a:1 128k -ac 2 \
-map a:0 -c:a:2 aac -b:a:2 128k -ac 2 \
-map a:0 -c:a:3 aac -b:a:3 96k -ac 2 \
-f hls \
-hls_time 4 \
-hls_playlist_type vod \
-hls_segment_type mpegts \
-hls_segment_filename stream_%v/file%03d.ts \
-master_pl_name master.m3u8 \
-var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2 v:3,a:3" stream_%v/stream.m3u8
# ABR HLS VOD streaming
# Bitrates from https://docs.peer5.com/guides/production-ready-hls-vod/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment