Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lisamelton/83d8022dc9cb273f6f638ac746037a63 to your computer and use it in GitHub Desktop.
Save lisamelton/83d8022dc9cb273f6f638ac746037a63 to your computer and use it in GitHub Desktop.
A wrapper script for `transcode-video` with an experimental simple constrained ratecontrol system.
#!/bin/bash
#
# experimental-simple-transcode-video.sh
#
# Copyright (c) 2013-2018 Don Melton
#
die() {
echo "$(basename "$0"): $1" >&2
exit ${2:-1}
}
args=()
blu_ray=''
dvd=''
blu_ray_target='6000'
dvd_target='1500'
target=''
hrd_args='--encoder-option nal-hrd=vbr'
while [ "$1" ]; do
case $1 in
--blu-ray|--bluray)
blu_ray='yes'
dvd=''
target=''
;;
--dvd)
blu_ray=''
dvd='yes'
target=''
;;
--target)
case $2 in
big)
blu_ray_target='8000'
dvd_target='2000'
target=''
;;
small)
blu_ray_target='4000'
dvd_target='1000'
target=''
;;
[0-9][0-9]*)
target="$2"
;;
*)
die "unsupported argument: $2"
;;
esac
shift
;;
--abr)
die "unsupported argument: $1"
;;
-H|--handbrake-option)
args=("${args[@]}" "$1")
if [[ "$2" =~ ^encoder=x265 ]]; then
hrd_args='--encoder-option hrd=1'
fi
;;
*)
args=("${args[@]}" "$1")
;;
esac
shift
done
if [ ! "$target" ]; then
if [ "$blu_ray" ]; then
target="$blu_ray_target"
elif [ "$dvd" ]; then
target="$dvd_target"
else
die 'missing argument: must include `--blu-ray` or `--dvd`'
fi
fi
transcode-video \
--target $target \
--encoder-option vbv-bufsize="$target" \
--encoder-option _crf-max \
--encoder-option _qpmax \
$hrd_args \
"${args[@]}"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment