Skip to content

Instantly share code, notes, and snippets.

@dawaltconley
Last active October 14, 2022 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawaltconley/9c31f3a8e2dd429606309f2bc55dd31d to your computer and use it in GitHub Desktop.
Save dawaltconley/9c31f3a8e2dd429606309f2bc55dd31d to your computer and use it in GitHub Desktop.
ABR Background Videos

ABR Background Videos

An ffmpeg command that produces abr video assets suitable for silent web background video. I'm using shaka-player to stream the resulting files.

I went through several iterations of this, and other variations could work as well. I believe this produces all the assets needed for cross-browser compatibility. Safari needs mp4, and iOS Safari (at least the version my old MacBook can simulate) will only play HLS, even with shaka-player.

#!/bin/bash
# uses ffmpeg version 4.4.2
source=$1
outdir=$2
ffmpeg -re -i $source -an -dash 1 -tile-columns 4 -frame-parallel 1 \
-map 0 -c:v:0 libvpx-vp9 -filter:v:0 scale=-2:360 -b:v:0 500k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:1 libvpx-vp9 -filter:v:1 scale=-2:360 -b:v:1 800k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:2 libvpx-vp9 -filter:v:2 scale=-2:360 -b:v:2 1400k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:3 libvpx-vp9 -filter:v:3 scale=-2:480 -b:v:3 750k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:4 libvpx-vp9 -filter:v:4 scale=-2:480 -b:v:4 1200k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:5 libvpx-vp9 -filter:v:5 scale=-2:480 -b:v:5 2100k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:6 libvpx-vp9 -filter:v:6 scale=-2:720 -b:v:6 1500k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:7 libvpx-vp9 -filter:v:7 scale=-2:720 -b:v:7 2400k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:8 libvpx-vp9 -filter:v:8 scale=-2:720 -b:v:8 4200k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:9 libvpx-vp9 -filter:v:9 scale=-2:1080 -b:v:9 3000k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:10 libvpx-vp9 -filter:v:10 scale=-2:1080 -b:v:10 4800k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:11 libvpx-vp9 -filter:v:11 scale=-2:1080 -b:v:11 8400k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:12 libx264 -filter:v:12 scale=-2:360 -b:v:12 500k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:13 libx264 -filter:v:13 scale=-2:360 -b:v:13 800k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:14 libx264 -filter:v:14 scale=-2:360 -b:v:14 1400k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:15 libx264 -filter:v:15 scale=-2:480 -b:v:15 750k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:16 libx264 -filter:v:16 scale=-2:480 -b:v:16 1200k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:17 libx264 -filter:v:17 scale=-2:480 -b:v:17 2100k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:18 libx264 -filter:v:18 scale=-2:720 -b:v:18 1500k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:19 libx264 -filter:v:19 scale=-2:720 -b:v:19 2400k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:20 libx264 -filter:v:20 scale=-2:720 -b:v:20 4200k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:21 libx264 -filter:v:21 scale=-2:1080 -b:v:21 3000k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:22 libx264 -filter:v:22 scale=-2:1080 -b:v:22 4800k -keyint_min 60 -g 60 -sc_threshold 0 \
-map 0 -c:v:23 libx264 -filter:v:23 scale=-2:1080 -b:v:23 8400k -keyint_min 60 -g 60 -sc_threshold 0 \
-f dash \
-single_file 1 \
-use_template 1 \
-use_timeline 1 \
-seg_duration 2 \
-adaptation_sets "\
id=0,streams=0,1,2,3,4,5,6,7,8,9,10,11 \
id=1,streams=12,13,14,15,16,17,18,19,20,21,22,23" \
-single_file_name '$RepresentationID$-$Bandwidth$.$ext$' \
-hls_playlist 1 \
"$outdir/manifest.mpd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment