#! /bin/sh if [ -z "$1" ]; then echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [abitrate=n] [ascale=s] $0 input.avi" exit 1 fi if [ -z "$vcodec" ]; then vcodec=x264 else vcodec="$vcodec" fi if [ -z "$vbitrate" ]; then vbitrate=2200 else vbitrate="$vbitrate" fi if [ -n "$vscale" ]; then vscale="-Z $vscale" fi if [ -z "$abitrate" ]; then abitrate=320 else abitrate="$abitrate" fi if [ -n "$ascale" ]; then ascale="-s $ascale" fi if [ "$vcodec" = x264 ]; then vopts="--bitrate=$vbitrate" elif [ "$vcodec" = x264-hq ]; then vopts="--bitrate=$vbitrate --8x8dct --ref=2 --bframes=3 --b-pyramid --weightb" elif [ "$vcodec" = x264-vhq ]; then vopts="--bitrate=$vbitrate --8x8dct --ref=5 --bframes=3 --b-pyramid --weightb --partitions=all --me=umh" else echo "Unknown video codec $vcodec; known codecs are x264[-[v]hq]" >&2 exit 1 fi if [ -z "$pass" ]; then pass=1 else pass="$pass" fi # Video transcode -i "$1" -x auto,null -y yuv4mpeg,null -k -u 50 $vscale $ascale -o _tmp.y4m || exit 1 if [ "$pass" -eq 1 ]; then x264 $vopts --progress -o _tmp.mkv _tmp.y4m || exit 1 elif [ "$pass" -eq 2 ]; then x264 $vopts --progress -o /dev/null --pass=1 _tmp.y4m && x264 $vopts --progress -o _tmp.mkv --pass=2 _tmp.y4m || exit 1 elif [ "$pass" -eq 3 ]; then x264 $vopts --progress -o /dev/null --pass=1 _tmp.y4m && x264 $vopts --progress -o /dev/null --pass=3 _tmp.y4m && x264 $vopts --progress -o _tmp.mkv --pass=3 _tmp.y4m || exit 1 # pass=3 is not a typo! else echo "Can only do 1, 2 or 3 passes." >&2 exit 1 fi # Audio transcode -i "$1" -x null,auto -y null,ogg -g 0x0 -b "$abitrate" -m _tmp.ogg && exec mkvmerge -o output.mkv -A _tmp.mkv _tmp.ogg