Skip to content

Instantly share code, notes, and snippets.

@lisamelton
Last active November 29, 2017 22:48
Show Gist options
  • Save lisamelton/93d260c0a77c7bbc92e62c06314c7be5 to your computer and use it in GitHub Desktop.
Save lisamelton/93d260c0a77c7bbc92e62c06314c7be5 to your computer and use it in GitHub Desktop.
A wrapper script for `transcode-video` with an experimental average bitrate (ABR) ratecontrol system.
#!/bin/bash
#
# experimental-abr-transcode-video.sh
#
# Copyright (c) 2013-2017 Don Melton
#
die() {
echo "$(basename "$0"): $1" >&2
exit ${2:-1}
}
args=()
blu_ray=''
dvd=''
blu_ray_bitrate='6000'
dvd_bitrate='1500'
bitrate=''
while [ "$1" ]; do
case $1 in
--blu-ray|--bluray)
blu_ray='yes'
dvd=''
bitrate=''
;;
--dvd)
blu_ray=''
dvd='yes'
bitrate=''
;;
--big)
blu_ray_bitrate='8000'
dvd_bitrate='2000'
bitrate=''
;;
--small)
blu_ray_bitrate='4000'
dvd_bitrate='1000'
bitrate=''
;;
--bitrate)
bitrate="$2"
shift
;;
--abr)
;;
--target|--cvbr|--vbr)
die "unsupported argument: $1"
;;
*)
args=("${args[@]}" "$1")
;;
esac
shift
done
if [ ! "$bitrate" ]; then
if [ "$blu_ray" ]; then
bitrate="$blu_ray_bitrate"
elif [ "$dvd" ]; then
bitrate="$dvd_bitrate"
else
die 'missing argument: must include `--blu-ray`, `--dvd` or `--bitrate`'
fi
fi
transcode-video \
--abr \
--target $bitrate \
--encoder-option _qpmax \
--encoder-option vbv-maxrate="$((bitrate + (bitrate / 2)))" \
--encoder-option vbv-bufsize="$((bitrate * 2))" \
--encoder-option nal-hrd=vbr \
"${args[@]}"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment