converting avi to an ipod video

posted @ 11:30 pm on Thursday, November 9, 2006

Something I was going to add to the last post, but probably deserves its own.. is how I convert my downloaded tv episodes to a format readable by my Video iPod.. Once you have the resulting mp4 file, it can be copied to the iPod using the usual method.

ffmpeg -i battlestar.galactica.306.avi -f mp4 -vcodec mpeg4 \
-maxrate 2000 -b 1500 -qmin 3 -qmax 5 -bufsize 4096 -g 300 \
-acodec aac -ar 44100 -ab 128 -s 320x180 -aspect 16:9 \
battlestar.galactica.306.mp4

You can script this in any number of ways. What I personally do is have a script that monitors a certain directory that is run from cron, when it sees a new avi file there it will go off and pump out a ‘video iPod friendly’ mp4 file of of a similar name. This is handy as I can then plug in the iPod later and the conversion is already done and I don’t have to remember the command to convert it again ;)

Thinking about it.. one could also add something similar to this to my .bashrc file:

avi2ipod() {
fn="${1}"
if [ -f ${fn} ]; then
out=”$(echo ${fn}|sed ’s/avi$/mp4/’)”
ffmpeg -i ${fn} -f mp4 -vcodec mpeg4 \
-maxrate 2000 -b 1500 -qmin 3 -qmax 5 -bufsize 4096 -g 300 \
-acodec aac -ar 44100 -ab 128 -s 320×180 -aspect 16:9 \
${out}
fi
}

And then you can just go off and do something like:

avi2ipod /mnt/media/tv/battlestar_galactica/battlestar.galactica.306.avi

Which will in the above example create you a suitable file called /mnt/media/tv/battlestar_galactica/battlestar.galactica.306.mp4 :)