Munging video into an ipod

On my way to work this morning, two seemingly unrelated ideas crossed my mind and created a desire to learn how to do something new.

Both ideas originated from the circumstances I found myself in. I was sitting on a bench. It was cold and windy. I had a very bad cold, a very sore throat, and a runny nose. I was waiting for a delayed train to work. I had nothing to do but wait.

The first thought that crossed my mind was that time spent commuting is wasted.
Regrettably, time spent waiting for your chosen mode of transportation, if not occupied with activities such as reading, writing, typing, or thinking, is wasted time. And with every moment that is wasted, an opportunity is forever lost.

The second thought was that my ipod is a video ipod and that it would be a pity non to take advantage of its capabilities.

These two thoughts combined led me to the (not so logical) conclusion that I had to figure out a way to get video content on my ipod so that I would have something instructive or entertaining to watch when faced with the prospect of a long and wasteful wait.

As it turns out, this can be easily accomplished, thanks to the excellent free software tool ffmpeg.

Obtaining ffmpeg is straightforward, if you are using Debian.
Add Debian Multimedia repository to your apt sources, then apt-get update, and apt-get install ffmpeg.

Converting a video clip input is as easy as:

ffmpeg -i input -acodec aac -ab 128 -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title title output.mp4

or

ffmpeg -i input -f mov -b 1800 -maxrate 2500 -vcodec xvid -qmin 3 -qmax 5 -s 320x240 -acodec aac -ab 128 output.mp4

Newer versions of ffmpeg like the following arguments better:

ffmpeg -f mp4 -vcodec mpeg4 -qmin 3 -qmax 5 -g 300 -s 320x240 -ab 64k -b 296k -i input output.mp4

or

ffmpeg -f mp4 -vcodec mpeg4 -qmin 3 -qmax 5 -g 300 -s 320x180 -padtop 30 -padbottom 30 -ab 64k -b 282k -i input output.mp4

Finally, upload the converted video onto your shiny ipod using gtkpod.
Create a playlist "Videos", if it does not exist already, and add foo.ipod.mov there.

Remember to look away from your ipod to watch where you are going.