Skip navigation.

Log in | Sign up

photo of Lee Bigelow

The Way I Like Stuff

or My Perfect World

Script to encode video for my Ipod Touch using mencoder

For linux folk using mencoder, here's the bash script that I made to re-encode video for my Ipod Touch.
It defaults to 2 pass lavc encoding, which is fairly quick and works well for me.

If you want a quicker encode just use one pass encoding (it's still pretty good quality):
vid2ipod.sh -1 movie1.avi movie2.avi ...

For those with lots of time you can use the H264 encoding:
vid2ipod.sh -H movie1.avi movie2.avi ...

Modify at will.

vid2ipod.sh
#!/bin/bash

quiet=""
passes="2"
codec="lavc"
bitrate="448"
bitratemax="960"
width="320"
height="240"

usage () {
    echo "
Usage: `basename "$0"` [-q] [-1|-2] [-L|-H] [-b BITRATE ] [-m MAX_BITRATE] [-w WIDTH] [-h HEIGHT] MOVIE_FILE
-q              Quieter output.
-1              Use 1 pass encoding.
-2              Use 2 passes (default).
-L              Use lavc (default). Much quicker, but not as high quality.
-H              Use h264.  Slow, but high quality.
-b BITRATE      Defaults to 448, 192 for low quality, 768 for high
-m MAX_BITRATE  Defaults to 960, 768 for low quality, 1500 for high
-w WIDTH        Defaults to 320, ipod screen width.  Use 640 for tv out.
-h HEIGHT       Defaults to 240, ipod screen height.  Use 480 for tv out.
"
}

[ "$#" -lt 1 ] && usage && exit -1

while getopts "q12LHb:m:w:h:" Option; do
    case "$Option" in
        q) quiet="-quiet" ;;
        1) passes="1" ;;
        2) passes="2" ;;
        b) bitrate="$OPTARG" ;;
        m) bitratemax="$OPTARG" ;;
        w) width="$OPTARG" ;;
        h) height="$OPTARG" ;;
        L) codec="lavc" ;;
        H) codec="h264" ;;
        *) usage; exit -1 ;;
    esac
done
shift $(( $OPTIND - 1 ))

while [ "$1" ]; do
    infile="$1"
    ! [ -f "$infile" ] && echo Error, file not found \"$infile\"  && usage && exit -1

    outfile="${1%.*}.m4v"

    num=1
    while [ -f "$outfile" ]; do
        echo "output file exists, adding number"
        outfile="${1%.*}-$num.m4v"
        let "num += 1"
    done

    pass=0
    if [ "$codec" = "lavc" ]; then
        while [ "$pass" -lt "$passes" ]; do
            let "pass += 1"
            echo --- Pass $pass of $passes Pass LAVC Encoding ---
            echo $outfile
            echo $width x $height, $bitrate-$bitratemax
            sleep 1
            encopts="aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=$bitrate:acodec=libfaac:abitrate=128"
            [ "$passes" -gt "1" ] && encopts="$encopts:vpass=$pass"
            echo $encopts
            sleep 1
            mencoder "$infile" $quiet -ofps 30 -sws 9 -of lavf -lavfopts format=ipod \
                -vf scale=-10:$height,dsize=$width:$height:0,harddup \
                -ovc lavc \
                -lavcopts $encopts \
                -oac lavc \
                -alang en \
                -srate 22050 \
                -o "$outfile"
            EXIT_CODE="$?"
            [[ "$?" != "0" ]] && exit "$EXIT_CODE"
        done

    elif [ "$codec" = "h264" ]; then
        while [ "$pass" -lt "$passes" ]; do
            let "pass += 1"
            echo --- Pass $pass of $passes Pass H264 Encoding ---
            echo $outfile
            echo $width x $height, $bitrate-$bitratemax
            sleep 1
            encopts="bitrate=$bitrate:vbv_maxrate=$bitratemax:vbv_bufsize=2000:nocabac:me=hex:subq=4:frameref=2:trellis=1:level_idc=30:global_header:threads=auto"
            [ "$passes" -gt "1" ] && encopts="$encopts:pass=$pass"
            echo $encopts
            sleep 1
            mencoder "$infile" $quiet -ofps 30 -sws 9 -of lavf -lavfopts format=ipod \
                -vf scale=-10:$height,dsize=$width:$height:0,harddup \
                -ovc x264 \
                -x264encopts $encopts \
                -oac faac \
                -alang en \
                -faacopts mpeg=4:object=2:br=160:raw -channels 2 \
                -srate 48000 \
                -o "$outfile"
            EXIT_CODE="$?"
            if [[ "$?" != "0" ]]; then exit "$EXIT_CODE"; fi
        done
    fi

    shift
done

A Very Clean Opera

Ok, so I'm a keyboard sort of fellow and don't really use most of the buttons and toolbars that Opera has on display, so I thought I'ld turn everything off and see how it went. Turns out it works quit well, with a few caveats.

First off I'm using the nice and clean Dimple theme:


I wanted Ctrl-L to be an Address Bar toggle. If the Address Bar was hidden then I wanted it to be displayed and in focus for a nice period of time, then rehidden. If visible I wanted it to be hidden.
I also wanted the unused F6 to toggle the main menu visibility (don't really use it most of the time).

Here are my keybindings:

Set using Tools->Preferences->Advanced->Shortcuts [Alt-P]. You'll probably have to duplicate the default keyboard setup and modify the copy.


So once you've made a duplicate and selected the Copy and hit the Edit button you should see the keyboard editing window. Use it's search filter to find the 'l ctrl' entry and hit the Edit button. Tab over and change the keys action to:
View address bar, 0 | View address bar, 6 & Delay, 100 & Focus address field & Delay, 20000 & View address bar, 0



By Default there is no action set for the F6 key so go to setup the F6 menu bar toggle you'll have to create a new F6 entry. First clear the Search filter in the keyboard editing window then scroll right to the top and select the Application group header:


Now add a new F6 entry with the following action:
Disable menu bar | Enable menu bar



All my toolbars are turned off except the Tab Bar, and it is on "show only when needed". I have the Progress-Bar setting on "Pop up at bottom". These settings are found in Tools->Appearance->Toolbars [Shift-F12].



And tada functional fullscreen all the time. F4 still pulls up your side bar, Ctrl-L gives you your autohiding url bar, Alt-B still gives your bookmarks dropdown (actually all the drop down shortcuts should still work, if they don't F6 will toggle back your menubar), and when you have multiple pages open the tab bar pops up.
Who needs a back button, when Alt-Left works just fine, Ctrl-Space will take you home, no need to bring a mouse into it.
Beauty.



Oh, I'm using the oh so life changing Ion3 window manager, in case you were wondering.

Cheers