#! /bin/sh if [ -z "$1" ]; then echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [acodec=s] [abitrate=n] [ascale=s] [pass=n] [input_opts=input_opts] [output_opts=output_opts] [output=output.avi] [crop=w:h:x:y] $0 input1 [input2...]" exit 1 fi if [ -z "$vcodec" ]; then vcodec=mpeg4 fi if [ -z "$vbitrate" ]; then vbitrate=1600k fi if [ -n "$vscale" ]; then vscale="-s $vscale" fi if [ -z "$acodec" ]; then acodec=libmp3lame fi if [ -z "$abitrate" ]; then abitrate=256k fi if [ -z "$pass" ]; then pass=1 fi if [ -n "$crop" ]; then crop="-vf crop=$crop" fi if [ $# -eq 1 ]; then input="$1" else input=concat:"`echo \"$@\" | sed 's/ /|/g'`" fi if [ -z "$output" ]; then output=output.avi fi if [ "$vcodec" = mpeg4 ]; then vopts="-g 300 -bf 2" elif [ "$vcodec" = mpeg4-hq ]; then vcodec=mpeg4 vopts="-g 300 -bf 2 -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2" elif [ "$vcodec" = mpeg4-vhq ]; then vcodec=mpeg4 vopts="-g 200 -bf 2 -mbd rd -flags +mv4+aic+qprd+mv0 -flags2 skiprd -trellis 2 -cmp 2 -subcmp 2" elif [ "$vcodec" = x264 ]; then vcodec=libx264 elif [ "$vcodec" = x264-hq ]; then vcodec=libx264 vopts="-preset slow" elif [ "$vcodec" = x264-vhq ]; then vcodec=libx264 vopts="-preset veryslow" else echo "Unknown video codec $vcodec; known codecs are {mpeg4,x264}[-[v]hq], copy" >&2 exit 1 fi if [ "$pass" -eq 1 ]; then exec ffmpeg -threads auto $input_opts -i "$input" -c:v "$vcodec" $vopts $vscale -b:v "$vbitrate" -c:a "$acodec" -b:a "$abitrate" $output_opts $crop "$output" elif [ "$pass" -eq 2 ]; then ffmpeg -pass 1 -threads auto $input_opts -i "$input" -c:v "$vcodec" $vopts $vscale -b:v "$vbitrate" -an -f rawvideo -y /dev/null $output_opts $crop && exec ffmpeg -pass 2 -threads auto $input_opts -i "$input" -c:v "$vcodec" $vopts $vscale -b:v "$vbitrate" -c:a "$acodec" -b:a "$abitrate" $output_opts $crop "$output" else echo "Can only do 1 or 2 passes." >&2 exit 1 fi