Skip to content

Instantly share code, notes, and snippets.

@ShahinSorkh
Last active August 9, 2020 14:14
Show Gist options
  • Save ShahinSorkh/be0d5dc7966f2ce1e959dc052dda93a1 to your computer and use it in GitHub Desktop.
Save ShahinSorkh/be0d5dc7966f2ce1e959dc052dda93a1 to your computer and use it in GitHub Desktop.
transcode a given video to different bitrate versions using ffmpeg
#!/usr/bin/zsh
INPUT=${1:a}
FRACTION=${2:-0.9}
BT=$(ffprobe -i $INPUT 2>&1 | grep Video | grep -o -E '[[:digit:]]+ kb\/s' | cut -d' ' -f1)
while [[ "$BT" -gt '50' ]]
do
BT=$(printf "%0.f" $(( $BT * $FRACTION )))
MX=$(( $BT + 50 ))
MM=$(( $BT - 50 ))
BS=$(( $BT / 2 ))
ffmpeg -y -i $INPUT -c:v libx264 -b:v ${BT}K -maxrate ${MX}K -minrate ${MM}K -bufsize ${BS}K ${INPUT:r}_bt$BT-mx$MX-mm$MM-bs$BS.mp4 &
done
wait
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment