#!/bin/bash # http://gentoo-wiki.com/HOWTO_Mencoder_Introduction_Guide # http://electron.mit.edu/~gsteele/ffmpeg/ # http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-libavcodec.html # http://web.njit.edu/all_topics/Prog_Lang_Docs/html/mplayer/encoding.html # http://www.linux.com/article.pl?sid=06/08/22/2121258 # transcode -f 15 -w 800,250,100 -y divx5,lame -N 0x55 -o test.avi -i $1 # enable PAL on PVR350 mpeg2 encoder #v4l2-ctl --set-input 2 #v4l2-ctl -s 2 #v4l2-ctl --set-ctrl=video_peak_bitrate=8000000 #v4l2-ctl --set-ctrl=video_bitrate=6000000 # dumpstream stream# file.tivo dumpstream () { mplayer tivo://tivo/$1 -demuxer 33 -dumpstream -dumpfile "$2" } die () { echo "${1:-}" exit 1 } #mplayer -vf cropdetect enquete.vob #vidcomp -h -vf crop=336:320:12:126 enquete.vob # Aspect ratio has to be forced with codecs other than xvid #vf='-vf scale=480:370' vf="-vf kerndeint" codec=h264 br=2400 abr=128 rot="" aud_channels="" aud_srate="" time="" # -ss 10 -endpos 1:54:00 if [[ $0 == *tivo* ]]; then echo "Tivo Mode" # tivo files are sometimes mis-detected: force the right demuxer demux="-demuxer 33" # Aspect ratio has to be forced with codecs other than xvid aspect='-force-avi-aspect 1.333' # and remove crap we don't want (tivo inserts a line of crap at the top) vf="-vf crop=352:476" elif [[ $0 == *pal* ]]; then # Couldn't quite get this to work yet, crop overrides it :( vf='-vf scale=540:405,crop=512:384' # problem with divx is that pass2 can fail with br too low errors codec=dvix br=800 elif [[ $0 == *camvidrecomp ]]; then codec=h264 br=3400 abr=128 # old cameras # abr=48 # br=2400 # aud_channels="-channels 1" # aud_srate="-srate 22050" fi while [ ! -z "$1" ] && [[ "$1" =~ ^-.* ]] do if [ "$1" = "-w" ]; then shift codec=win fi if [ "$1" = "-d" ]; then shift codec=divx fi if [ "$1" = "-D" ]; then shift codec=divx1 fi if [ "$1" = "-F" ]; then shift codec=flv br=400 abr=56 aud_srate="-srate 22050" vf='-vf scale=512:384' fi if [ "$1" = "-h" ]; then shift codec=h264 fi if [ "$1" = "-x" ]; then shift codec=xvid fi if [ "$1" = "-m" ]; then shift move=1 fi # try instead of rotate if [ "$1" = "-f" ]; then shift rot="-vf flip,mirror" fi if [ "$1" = "-r" ]; then #rot="-vf mirror,rotate=$2" # works with -r 3 rot="-vf rotate=$2" shift 2 fi if [ "$1" = "-br" ]; then br="$2" shift 2 fi # -ss 10 -endpos 1:54:00 if [ "$1" = -time ]; then time="$2" shift 2 fi # for instance -vf scale=540:405,crop=512:384 if [ "$1" = -vf ]; then vf="-vf $2" shift 2 fi done test $# -eq 1 || test $# -eq 2 || die "$0 file_src file_dest" test $# -eq 2 && test -f "$2" && die "file_dest should not exist" src="$1" dest="${2:-$src.new}" if [ "$codec" = win ]; then nice -19 mencoder $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc lavc -lavcopts vcodec=msmpeg4v2:vhq:vbitrate=$br $rot -o "$dest" "$src" elif [ "$codec" = divx1 ]; then nice -19 mencoder $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc lavc -lavcopts vcodec=mpeg4:vhq:trell=yes:v4mv=yes:vbitrate=$br -ffourcc DX50 $rot -o "$dest" "$src" elif [ "$codec" = flv ]; then # http://www.jeremychapman.info/cms/mencoder-avi-to-flv-conversion nice -19 mencoder $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc lavc -lavcopts vcodec=flv:vbitrate=$br:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -of lavf $rot -o "$dest" "$src" elif [ "$codec" = xvid ]; then nice -19 mencoder $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc xvid -xvidencopts bitrate=$br $rot -o "$dest" "$src" else pass="$dest".pass for i in 1 2 do echo "DOING $codec PASS $i" echo "------------------" if [ "$codec" = h264 ]; then #vf=$vf,dsize=4/3,scale vf=$vf,scale # Trellis searched quantization nice -19 mencoder -passlogfile "$pass" $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc x264 -x264encopts bitrate=$br:turbo=1:pass=1:threads=0 $rot -o "$dest" "$src" || die "multipass failed on pass $i" elif [ "$codec" = divx ]; then # Trellis searched quantization nice -19 mencoder -passlogfile "$pass" $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc lavc -lavcopts vcodec=mpeg4:vhq:trell=yes:v4mv=yes:vbitrate=$br:vpass=$i -ffourcc DX50 $rot -o "$dest" "$src" || die "multipass failed on pass $i" fi done /bin/rm $pass *.pass.mbtree &>/dev/null fi