Converting video to play on your iPod with FFmpeg
So I’ve finally gotten to sit down and fiddle with my 5G iPod under Linux. I’ve gotten gtkpod working (though not the patches to support video syncing), and I think I’ve got FFmpeg generating good video content. Transcode and MEncoder seem to lack AAC support, and the iPod won’t play MP3 audio, so FFmpeg is the only option here.
The command I’m using is:
$ ffmpeg -vcodec xvid -b 300 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 96 -i input_file.avi -s 320x240 -aspect 4:3 ipod_output.mp4
You may want to change:
- -aspect (if your source is 16:9)
- -s (if you want 480×480 video for TV display)
- -b, -qmin, -qmax (if you want higher quality or are encoding higher rez video)
Since I don’t have video sync working, I can’t verify that this works, but I don’t see why it wouldn’t. One-pass encoding is about 2x realtime on my 2.4ghz P4, and file sizes are very reasonable - 70mb for a 20 minute TV episode. Quality is not fantastic, but should be fine for the iPod screen. Some tweaking should locate a sweet spot, with ~1.5 - 2x encoding and better quality.
Edited to add: It works, though I can’t seek in the video - lame. Quality is fine on the iPod screen. If you’re compiling gtkpod from CVS (needed for video syncinc), revert src/file_itunesdb.c to revision 1.65 - the last commit was bad. Also: Ripping my 14-disc Monty Python DVD set to iPod video now. Will it be done by Monday? Who knows!

November 21st, 2005 at 1:10 pm
Hi !
I have a problem when I encode my video using ffmpeg. There is no “index” on the video file. The problem is I can’t resume my video (still start at beginning) and I can’t use ffw /rwd (press center butter, fast circles with your finger). And idea here ?
November 26th, 2005 at 1:08 pm
Hello!
I wrote down my experiences with my new iPod with video. Have a look at http://home.c-otto.de/ipod/
Carsten Otto
November 27th, 2005 at 5:57 am
“I have a problem when I encode my video using ffmpeg. There is no “index” on the video file.”
Same problem here. No idea.
December 1st, 2005 at 9:33 am
Ian Eure : Have you tried “two-pass” mode ? Perhaps It will create the “index”. I didn’t try yet.
December 5th, 2005 at 2:21 am
Just so you know, the qmin and qmax settings will sometimes cause the bitrate to fluctuate by several hundred kilobits per second depending on the video file. I found that the bitrate setting was nearly useless when encoding at 480×480. The test video (an episode of Alias) settled in around 1100K/s because the qmax setting wouldn’t allow the quality to degrade more than 5. You probably need to increase qmax to 9 or 10 in order to keep within a reasonable proximity to 300Kb/s. I also fail to see the usefulness of setting qmin, since if you can get a better quality, why wouldn’t you want it? But perhaps I’m missing something.
I did a quick comparison between using and removing the qmin/qmax settings. I’m using a 43 minute episode of Alias recorded from HDTV as my source video. My command line was (with qmin/qmax):
ffmpeg -vcodec xvid -b 350 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 96 -ac 2 -i alias.s05e05.avi -s 320×240 -aspect 16:9 alias.s05e05.mp4
Here are the final stats with the settings:
frame=58766 q=3.0 Lsize= 119159kB time=2450.6 bitrate= 398.3kbits/s
video:89073kB audio:28715kB global headers:0kB muxing overhead 1.163105%
The overall bitrate (video bitrate + audio bitrate) is smaller than one might expect, because qmin forced some of the video to be no better than 3, when it could have been better quality.
This is without the qmin/qmax settings:
frame=58766 q=2.0 Lsize= 134562kB time=2450.6 bitrate= 449.8kbits/s
video:104475kB audio:28715kB global headers:0kB muxing overhead 1.029920%
I added an extra 15MB to the filesize when removing the qmin/qmax settings, but the overall video quality is 2 instead of 3. The bitrate is just about on the money (350K/s video + 96K/s audio = 446K/s total). This confirms that qmin was a problem in the first run.
So, what did I deduce from all this? I think qmin shouldn’t be used. It artificially degrades the video when it doesn’t have to. That’s what the target bitrate is for. However, I did see in the second run that qmax may have been useful. There were a few times when the quality went over 10. While I don’t think that’s a particularly important at these low resolutions, it will probably be more useful if you encode at 480×480 for TV. In those instances, setting qmax to 10 would probably be advisable.
December 5th, 2005 at 3:26 am
Additionally if you are transcoding a video file that is 16:9 (for instance, something captured from HDTV), then the output video file will stretch to fit the height of the iPod screen. This makes the video look quite distorted and causes additional video artifacts during playback. I’m looking into how to resolve this. Maybe you can specify only a width and allow the height to adjust dynamically?
December 5th, 2005 at 4:49 am
For widescreen videos, use -s 320×192. And if you want to transcode for TV output, you should use these resolutions:
widescreen: 480×288 (1.6666667)
fullscreen: 480×360 (1.3333333)
It appears that the iPod pretty much ignores the -aspect option. So I wouldn’t even bother with it. Here’s my current command line, when converting HDTV/widescreen videos:
ffmpeg -vcodec xvid -i input.avi -b 375 -qmax 10 -bufsize 8192 -g 300 -acodec aac -ab 96 -ac 2 -s 320×192 output.mp4
Note that I added stereo output (-ac 2) and bumped up the buffer size. I also dropped the -qmin option and increased -qmax to 10 so the final file size is more consistent. Even with the higher qmax, my final video quality is still 2 (which is great).
With all this fiddling around with ffmpeg, I’ve decided to start a project to create an tool similar to the Videora iPod Converter (which I believe is closed source). It will probably be Qt based, since I’m an avid KDE user.
December 5th, 2005 at 6:20 am
I did my own experiments beforehands and for me forward/backward skipping works (and everything else, too). Maybe it’s because I’m using “-f mov”?
Anyway, I wrote down what I did under http://www.julien-oster.de/pov/pmcms/entry/122
maybe it’s of any help.
December 5th, 2005 at 9:24 pm
It may be an issue with gtkpod that you aren’t able to seek. Perhaps some meta information is included when the video is copied to the iPod? I’m using ffmpeg on Linux for conversion, but I still use iTunes on my work laptop to copy the videos to my iPod. I can seek fine.
December 11th, 2005 at 6:44 pm
I tried the above command on ubuntu and I am getting “unknown codec ‘xvid’” error. I tried looking for xvid in apt-get but couldnt find one. COuld someone pls help on this error?
December 11th, 2005 at 10:33 pm
You can use mEncoder to build an index on a file that is missing one, I think.
December 13th, 2005 at 8:31 pm
I have succesfully used ffmpeg -i input.avi -f mov out.mov for my brand new 5g iPod.
December 22nd, 2005 at 2:20 am
Converting videos to iPod using GNU/Linux
The fastest way I’ve foud to convert videos to the iPod format using free software is by using the ffmpeg encoder.
It should work in any unix if you have ffmpeg installed. If you use Debian, you can find a good .deb package in nerim.net:
deb …
December 23rd, 2005 at 2:16 pm
Can someone please post their FFMPEG configure file? I’ve downloaded the latest FFMPEG CVS and enabled xvid, faad, and flaac, and then get tons of compile errors (under Fedora Core 3).
December 23rd, 2005 at 6:59 pm
Ok, lte me address a couple points here.
- Seeking. Definitely a GTKPod issue. I can convert with FFMpeg, put it on the iPod with iTunes, and I can seek fine.
- Unknown XviD codec on Ubuntu: Yup, Ubuntu ships with a pretty crippled FFMpeg. Get the source and recompile it.
- Fullscreen vs. widescreen. I haven’t had any problems. I just change -aspect. I have had no problems with aspect ratios when playing on my iPod or in iTunes.
- qmin setting. It was a concious decision to get more reasonable file sizes. For higher quality I have found that ignoring the q settings and going with ABR works well for me. I’m using: -maxrate 768 -b 512, which will get you an ABR of 512kb, with an upper limit of 768kb. Increasing the upper limit to 1M results in more quality still, and file sizes are still quite reasonable. Two-pass encoding at 768-1000k gives me very acceptable quality.
December 24th, 2005 at 9:39 am
These settings work fine for me (in a batch file, on windows)
ffmpeg -i %1 -f mp4 -r 25 -s 320×240 -b 768 -ar 44000 -ab 112 %1.mp4
December 24th, 2005 at 8:40 pm
Getting movies to ffw and rew with gtkpod:
Drag your movie over to your iPod with gtkpod
Right-click on the movie and click on “Edit details”
Go to the “General” tab and set the play time.
Click Apply and OK.
Sync
The problems comes from gtkpod setting a 0:00 play time for all movies. Manually setting it has worked for every movie I put on so far. I will see about making a patch so gtkpod does this automatically tomorrow.
December 28th, 2005 at 1:50 pm
Ubuntu breezy packages of libgpod (0.3.0) and Gtkpod (0.99.2) with video support available on my website : http://www.badcow.homelinux.net
December 28th, 2005 at 10:18 pm
With gtkpod 0.99.2 and manual setting of play time, I can use ffw and rew correctly but I still cannot use pause / resume. (Watch a video - pause - listen some music - resume video (doesn’t work). Any idea ?
January 29th, 2006 at 11:57 pm
This isn’t working for me, I’m trying to encode tv episodes that are encoded as xvid into ipod supported mp4 files. Here is my parameters:
ffmpeg -vcodec xvid -b 300 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 96 -i Scrubs.S05E08.PDTV.XviD-LOL.avi -s 320×240 -aspect 4:3 scrubs.mp4
The file plays in quicktime and iTunes fine, but won’t copy to the iPod.
I get this error http://www.flickr.com/photos/maddox/92819725/
Why the heck can’t I get these vids on the iPod?
February 23rd, 2006 at 4:31 am
Great post!
I’m curious though. I really don’t care about file size. I really just want to take a downloaded xvid and convert it so it’ll work on the ipod with little or no degration in quality. (I’m basically using my ipod to watch missed tv shows)
Is there some automated way I can do this… like a batch script which reads the bitrate, framerate, etc from the original and apply those settings to the converted ipod friendly version?
March 12th, 2006 at 3:40 am
i am using mandriva 10.2 cooker and an athln 64 running in 32 bit mode. i have successfully encoded my xvid files to mp4 using ffmpeg but the video will run fine for a cpl of sec and then freeze, if i do a ff it will be back to normal, its not gtkpod because i use it to xfr some vid dled off the net and it works perfectly, is anybody else getting these problem?
my ffmpeg is built with faac, faad. i had to remove xvid and x264 support to compile.
atm the scriipt is as follows: ffmpeg -i “$1″ -f mp4 -vcodec mpeg4 -b 700 -r 29.970030 -acodec aac -ac 2 -ar 48000 -ab 160 -s 320×240 -aspect 4:3 $2.mp4
April 22nd, 2006 at 7:11 am
iPod doesn’t play mp3 audio? Are you sure?
April 23rd, 2006 at 5:36 pm
“iPod doesn’t play mp3 audio? Are you sure?”
It didn’t seem to work for me. I’m specifically referring to MP3 audio tracks in a video file - of course it plays regular MP3 songs just fine.
May 1st, 2006 at 5:06 pm
[...] It took me most of yesterday afternoon to work out how to encode video for use on an iPod. ffmpeg will do the trick, as long as you compile it with aac support. The format is mpeg4 video with aac audio, 320×240. For those of you who are interested in the process, here’s a good ffmpeg command line. I encoded and uploaded a video study of mine Study One. Even though this video was designed for high-resolution projection and nearly every frame is different , the compressed version played on a ‘pod conveys quite a bit of the original. I also encoded and downloaded a great abstract film by Harry Smith ‘Court Metrage No. 7 (cocaine)’. This also looked great though the soundtrack was in mono — not necessarily a bad thing as the soundtrack on the version I have is made up of Beatle tunes. [...]
May 18th, 2006 at 6:34 am
I found a way to seek through videos encoded with ffmpeg and imported with gtkpod. The solution is quite easy.
When I was investigating what the problem could be, I thought the problem was in how ffmpeg dealt with the video’s metadata. But the problem was in gtkpod.
When you import a video with gtkpod, click on edit details in the video you just added. In the field “length” write the actual length of the video. The next time you play the video you will be able to seek through it.
When you import videos with iTunes it takes care of extracting the metadata of the video; gtkpod doesn’t. The ipod, therefore, doesn’t know where the video ends: you have to tell it.
I hope this can help people rid off the frustration (such as the one I had).
July 7th, 2006 at 11:20 pm
build mencoder with faac support for -oac faac aka aac encoding support.
August 2nd, 2006 at 11:24 am
Thought it might help to post my command. It overcomes the no indexing errors by using the moeg4 instead of xvid codec. I can seek fine in the videos, though I may have a newer gtkpod version (0.99.4).
ffmpeg -i input.avi -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 output.mp4
This is for widescreen. For regular, change the resolution to 320×240, and aspect to 3:4.
Also, you can change the q values and bitrates to your liking.
I am running ffmpeg version 0.4.9 with aac and xvid compiled in on a gentoo system.
Here are my use flags/version:
ffmpeg-0.4.9_p20051216 USE=”a52 aac encode ieee1394 imlib mmx network ogg oss sdl theora threads truetype v4l vorbis xvid zlib -debug -doc -dts -test
Hope this helps someone.
September 11th, 2006 at 2:20 am
Louis’ command line worked like a charm for me! The Tick is playing on my ipod right now, copied there by the cvs build of gtkpod.
January 10th, 2007 at 9:19 am
[...] I found this site. The command (slightly modified, see below): [...]
February 15th, 2007 at 1:05 am
what is FFmpeg?
February 19th, 2007 at 10:05 pm
If you can’t figure out what ffmpeg is on your own, you’ll never get this to work.
March 29th, 2007 at 8:04 am
Hi,
I am not able to use GSM file with ffmpeg on linux. ffmpeg is saying “Unknown Format”. Any idea why i am getting this?
August 10th, 2007 at 10:22 am
[...] Atomized » Blog Archive » Converting video to play on your iPod with FFmpeg [...]
October 18th, 2007 at 8:17 pm
[...] How to convert Video to iPod - [...]