#! /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] $0 input [output]" 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 input="$1" shift if [ -n "$1" ]; then output="$1" shift else output=output.avi fi if [ "$vcodec" = mpeg4-hq ]; then vcodec=mpeg4 vopts="-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2" fi if [ "$vcodec" = x264 ]; then vcodec=libx264 fi if [ "$vcodec" = x264-hq ]; then vcodec=libx264 vopts="-preset slow" fi if [ "$vcodec" = x264-vhq ]; then vcodec=libx264 vopts="-preset veryslow" fi if [ "$pass" -eq 1 ]; then exec ffmpeg $input_opts -i "$input" -c:v "$vcodec" $vopts $vscale -b:v "$vbitrate" -g 300 -bf 2 -c:a "$acodec" -b:a "$abitrate" $output_opts "$output" elif [ "$pass" -eq 2 ]; then ffmpeg -pass 1 $input_opts -i "$input" -c:v "$vcodec" $vopts $vscale -b:v "$vbitrate" -g 300 -bf 2 -an -f rawvideo -y /dev/null $output_opts && exec ffmpeg -pass 2 $input_opts -i "$input" -c:v "$vcodec" $vopts $vscale -b:v "$vbitrate" -g 300 -bf 2 -c:a "$acodec" -b:a "$abitrate" $output_opts "$output" else echo "Can only do 1 or 2 passes." >&2 exit 1 fi