Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

iPod video encoding guide for Linux users

Filed under: Tutorials and HOWTOs by Hari
Posted on Wed, May 23, 2007 at 17:54 IST (last updated: Wed, Oct 1, 2008 @ 22:15 IST)

I have a 30GB video iPod and I have to say that it is one of the most finicky music and video playing devices you can ever own. I've managed to corrupt the ever-so-delicate darling (the iTunes DB) several times as a result of which I've had to remove and recreate the music database from scratch and getting your videos to the exact format required by the video player is a real pain in the rear. All in all, I must say that I regret purchasing an iPod and would have bought any other player in the market if only I had known whether those would work under Linux or not. This is probably the last Apple product I ever purchase. It's truly a shoddy, hyped overpriced product.

Having said that, I've struggled with guides on the internet telling me how to encode videos for the iPod and most of them have not worked for me. After a lot of tweaking around I wrote a simple script using ffmpeg to get the precise format recognized by the iPod. If you have DVDs, you need to rip them first. I suggest acidrip, as it's quite a simple GUI to mencoder. However, the videos produced by mencoder will *not* work with the iPod. I have tried with several options, but it won't work at all.

So here's how I encode DVDs to iPod format in Linux.
  1. Rip the DVD chapter by chapter, using acidrip. It's the most convenient way of doing it. I generally scale the video to the iPod size (320x240) at this stage since ripping becomes less time consuming. Other parameters don't matter much since you won't be using this format anyway. I also set the audio to MP3 using LAME (you need liblame for this) and bit rate to 64. You can set other parameters if you wish.
  2. Convert the resulting mpeg file(s) one by one to mp4 (with h264 codec) using the script (see below).
  3. Take a long coffee break ;)
  4. Use a tool like gtkpod to transfer the mp4 file to your iPod. Hopefully it should play properly now.

The script is very simple. It's just a wrapper for ffmpeg with all the options you need to get the correct iPod-compliant format. Copy this code, save it to a text file (say ipodenc.sh) and make it executable using the command chmod +x ipodenc.sh.
#!/bin/bash
#Encode iPod Video

input_file=$1 output_file=$2

ffmpeg -i "${input_file}" -vcodec h264 -b 150k -bufsize 244 -maxrate 768k -s 320x240 -bf 0 -level 13 -f mp4 -acodec aac -ar 48000 -ab 64 "${output_file}"

The script's usage is (from the command line):

./ipodenc.sh inputfile.mpg outputfile.m4v

You can alter some of those ffmpeg settings if you want to. I deliberately kept the bit rate low because the encoder will always choose higher bit rates. But you need the -bf 0 and the -level 13 parameters if you want the video to play (with the h264 format). I found this obscure bit of information on a mailing list archive. Earlier, when I encoded with h264 without those flags, it refused to play on the iPod.

This is more like a reminder to myself, but I hope you find this useful anyway. :)

4 comment(s)

  1. Well, I don't have an iPod, video or otherwise. But I do have a GP2X, which of course is also a portable device that plays video. So I did have a play with ffmpeg, but the sheer number of command-line options it requires turned me away from it rather - I don't blame you for needing/wanting to script the whole process :)So when I wrote the guide for Linux users to rip DVDs for the GP, I suggested using dvd::rip instead. It's not as good for "batch jobs", admittedly, but I only have one DVD drive, so it wasn't that big an issue :wink:

    Comment by Dominic (visitor) on Wed, May 23, 2007 @ 19:11 IST #
  2. Yes, Dominic. That's a good, comprehensive guide you have there. iPod and gtkpod is a real pain. It keeps corrupting the iTunes database and even the file copying process seems to be problematic. Sometimes the copied file doesn't play and I have to repeat the process. And even if it works, the audio and video keeps having glitches - freezing on occasions and sometimes freezing permanently. Pain, pain, pain!My brother's next music player will be a Cowan. I wish I could just give the iPod away.

    Comment by hari (blog owner) on Wed, May 23, 2007 @ 19:32 IST #
  3. That's a good guide, Hari. Too bad I don't have an iPod and too bad I don't have Linux. But if I ever do, I know who to ask!

    Comment by RT Cunningham (visitor) on Wed, May 23, 2007 @ 21:53 IST #
  4. Get Linux. Avoid the iPod like a plague. Get any other player - iRivers are much better.

    Comment by hari (blog owner) on Thu, May 24, 2007 @ 11:16 IST #

Comments closed

The blog owner has closed further commenting on this entry.