iPod video guide

December 8th, 2009 Leave a comment Go to comments

Encoding videos suitable for iPods

Thanks to “cartman” on the FreeNode IRC network for testing and providing information for this guide.

The “new” higher resolution capability of the iPod video uses something Apple have dubbed a “Low Complexity” version of the Baseline Profile of H.264. Thankfully someone discovered what this meant. (See here for details – credit goes to Tyler Loch for this information.)

At first I wondered what the use of 640×480 video on a 320×240 screen would be but I was informed that these devices have a TV out. Fun. :) Anyway, on to the good stuff.


1.5Mbit/s 640×480 H.264 videos (for improved quality using TV out)

  • BIT_RATE <= 1500 kbps
  • 640×480
  • Up to 30 fps
  • “Low-Complexity” H.264 Baseline Profile
    • 1 reference frame
    • Up to H.264 level 3
    • 640 pixels maximum frame width
    • Sample Aspect Ratio (SAR) must be 1:1
    • UUID atom must exist containing the following hex data: 6B 68 40 F2 5F 24 4F C5 BA 39 A5 1B CF 03 23 F3

For one pass:

ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec libx264 -vpre hq -vpre ipod640 -b BIT_RATE -bt BIT_RATE -aspect WIDTH:HEIGHT -threads 0 -f ipod OUTPUT.mp4

For two pass:

ffmpeg -i INPUT -an -pass 1 -s WIDTHxHEIGHT -vcodec libx264 -vpre fastfirstpass -vpre ipod640 -b BIT_RATE -bt BIT_RATE -aspect WIDTH:HEIGHT -threads 0 -f ipod OUTPUT.mp4

ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -s WIDTHxHEIGHT -vcodec libx264 -vpre hq -vpre ipod640 -b BIT_RATE -bt BIT_RATE -aspect WIDTH:HEIGHT -threads 0 -f ipod OUTPUT.mp4



768kbit/s 320×240 H.264 videos

  • BIT_RATE <= 768 kbps
  • 320×240
  • Up to 30 fps
  • H.264 Baseline Profile up to level 1.3

For one pass:

ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec libx264 -vpre hq -vpre ipod320 -b BIT_RATE -bt BIT_RATE -metdata "title=SOME_TITLE" -threads 0 -f ipod OUTPUT.mp4

For two pass:

ffmpeg -i INPUT -an -pass 1 -s WIDTHxHEIGHT -vcodec libx264 -vpre fastfirstpass -vpre ipod320 -b BIT_RATE -bt BIT_RATE -metadata "title=SOME_TITLE" -threads 0 -f ipod OUTPUT.mp4

ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -s WIDTHxHEIGHT -vcodec libx264 -vpre hq -vpre ipod320 -b BIT_RATE -bt BIT_RATE -metadata "title=SOME_TITLE" -threads 0 -f ipod OUTPUT.mp4


IF ANYONE HAS FEEDBACK ON THE SETTINGS BELOW IT WOULD BE APPRECIATED!
2.5Mbit/s 640×480 MPEG-4 SP videos

  • BIT_RATE <= 2500 kbps
  • 640×480
  • Up to 30 fps
  • Simple Profile

For one pass:

ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec mpeg4 -b BIT_RATE -flags +aic+cbp+mv0+mv4 -trellis 1 -mbd 2 -cmp 2 -subcmp 2 -g 250 -maxrate 2.5M -bufsize 2M -metadata "title=SOME_TITLE" -f ipod OUTPUT.mp4

For two pass:

ffmpeg -i INPUT -an -pass 1 -s WIDTHxHEIGHT -vcodec mpeg4 -b BIT_RATE -flags +aic+cbp+mv0+mv4 -trellis 1 -mbd 2 -cmp 2 -subcmp 2 -g 250 -maxrate 2.5M -bufsize 2M -metadata "title=SOME_TITLE" -f ipod OUTPUT.mp4

ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -s WIDTHxHEIGHT -vcodec mpeg4 -b BIT_RATE -flags +aic+cbp+mv0+mv4 -trellis 1 -mbd 2 -cmp 2 -subcmp 2 -g 250 -maxrate 2.5M -bufsize 2M -metadata "title=SOME_TITLE" -f ipod OUTPUT.mp4

  1. skumar
    August 14th, 2009 at 07:44 | #1

    When I try the 2.5 mbit 640×480 command line I get an error saying it does not know the option “trell”

    but otherwise using Adobe CS3 and encoding at either 480×360 or 640×480 at 2.5Mbps works just fine on an iPhone.

    Would love to get it to work using ffmpeg

  2. skumar
    August 14th, 2009 at 07:56 | #2

    Using the first option (the TV one) I’m able to encode, but the audio is choppy, cracklly etc. just not correct.

  3. August 14th, 2009 at 08:27 | #3

    I’ve fixed the ‘-flags +trell’ issue. The option has since changed to -trellis.

    About the choppy, crackly audio – what are you using to play the file? What versions of FFmpeg, FAAC and x264 are you using? I suggest updating them all to their current versions before trying again.

  4. skumar
    August 14th, 2009 at 09:50 | #4

    Rob, thanks for the fix in the flags. I’ll try again.

    As regards the audio. I’m using the latest build by Ramiro Polla.
    FFmpeg revision number: 16573
    libfaac 1.26
    x264 0.65.1074M b6bb3d4

    I find that it’s like clipping in that as the volume rises (the music itself) the audio starts to clip but at times it sounds like a loose connection (if you know what I mean).

  5. skumar
    August 14th, 2009 at 09:58 | #5

    The audio issue seems to be related to the sampling frequency. If I leave it as default, I get th eissue. If I use the -ar switch and set it to say 11000 I don’t get the issue.

  6. skumar
    August 14th, 2009 at 10:05 | #6

    Ok, if I specifiy -ar 41000 then there is no issue with the audio

  7. skumar
    August 14th, 2009 at 10:47 | #7

    I’ll take that back. The audio is out of sync now and is faster than normal.

    Also tried the iPod 1 pass example. -metadata is unknown it seems. Removed that but audio issue persists.

  8. skumar
    August 14th, 2009 at 10:49 | #8

    plays on the iPhone though.

  9. skumar
    August 14th, 2009 at 11:21 | #9

    ok, I got it. I ws using the wrong audio sampling rate when I specified it. So by specifing the -ar switch with 44100 the problem is gone, audio is in sync and all is good.

    I’ll try the 2 pass version next.

  10. skumar
    August 14th, 2009 at 12:18 | #10

    The 2 pass command line works (had to remove the -metadata switch). However, can’t seem to find documentation on some of the switches such as -mbd -cmpd etc. I need to increase video quality but I’m maxed out in bitrate.

  11. koichi
    August 20th, 2009 at 06:58 | #11

    When I create a video with your settings, it works perfectly well when I sync that video via iTunes to an iPod. However, if I try to access that video directly from a link in an iPhone via browser or gmail (so that it opens up QuickTime Player), the video does not play. After trying things out, one minor thing that needs to be changed is the bpyramid option.

    To make a video iPhone-Safari-QT-Player playable, I had to do set flags2 to have -bpyramid.

  12. koichi
    August 20th, 2009 at 18:57 | #12

    @koichi
    I also confirmed that the same media that can be played on an iPhone through iTunes sync will not play when directly accessed via browser. I suppose there are two different media players on iPhones?

  13. skumar
    August 24th, 2009 at 12:32 | #13

    Hi Robert,

    Just discovered that the iPhone version plays fine on the iPhone, but does not play in Flash Player. I get audio, but no picture.

    I then used SUPER (in case you don’t know SUPER, it uses ffmpeg) to create an iPhone version and that video plays on the iPhone and Flash Player can handle it just fine.

    So something is a-miss in these settings. Do you know what it might be? Could it be the flags2 -bpyramid thing the poster above mentioned?

  14. skumar
    October 2nd, 2009 at 23:32 | #14

    At times I have the that koichi (above) seems to have, that is directly browsing to an mp4 file using iPhone and Safari the video does not play. This is not the case with all videos. That is using the i pass example above, I can encode multiple source files. They all play just fine on my PC but they don’t all play fine on the iPhone.

    So I’n not sure if the issue is related to “driectly browsing…). since I don’t want to install iTunes and I’d rather be able to simply encode using ffmpeg and use on iPhone I was wondering how I’d go about defiing the flags2 to have -bpyramid.

    Do I simply add a -flags2 -bpyramid to the command line above? I tied that, and the video encodes and play on my PC, but not on the iPhone.

  15. October 3rd, 2009 at 06:22 | #15

    Yes, you can just add ‘-flags2 -bpyramid’.

  16. qxgnxamy
    November 9th, 2009 at 18:50 | #16

    This page (http://yuo.be/wiki/dop:ipod_video) says that an iPod Classic with firmware 1.1.2 supports 5.0 Mbps video and 256Kbps audio. My 80GB iPod classic will play files with these bitrates.

    About the MPEG-4 SP settings: should the “-f ipod” be there? ffmpeg -formats says that this is iPod H.264 MP4 format.

    Can you explain what aic, cbp, mv0, trellis 1, mbd 2, cmp 2, subcmp 2, and bufsize are? With your one pass MPEG-4 SP instructions I was able to produce a file that works on my iPod. However I’d like to know how these options improve the encode. I think I know what the other options are already.

    One last question: are there any options necessary to speed up the encode by using SIMD acceleration? I have an Intel Core 2 Duo.

  17. HolyRoses
    November 14th, 2009 at 08:23 | #17

    rob, something has broken with ffmpeg svn or something has changed that I cant figure out…

    All encodes are defaulting to Main profile.

    [libx264 @ 0xa2a51b0]profile Main, level 2.1

    thats with using coder 0 and bf 0.

    This is happening on SVN-r20534

    Exact same encode strings do not do that on SVN-r19790

    I get [libx264 @ 0x8ccc870]profile Baseline, level 2.1

    Can you help?

  18. HolyRoses
    November 14th, 2009 at 19:50 | #18

    robert the problem may be due to an updated version of x264. I am trying out the auto builds of ffmpeg by http://ffmpeg.arrozcru.org/autobuilds/ and they are working fine and not defaulting to main.

  19. HolyRoses
    November 14th, 2009 at 20:39 | #19

    got my answer to the problem:

    it’s weightp
    there is currently no way to disable it in ffmpeg
    I will add the feature to ffmpeg when we deal with all the stability issues
    stick with the current stable x264, r1318

    http://git.videolan.org/gitweb.cgi?p=x264.git;a=commit;h=fe83a906ee1bb5170b112de717818e278ff59ddb

  20. wdhawes
    February 10th, 2010 at 19:06 | #20

    The H.264 examples work fine for me.

    Using the same source files, the MPEG4-SP examples result in files that the iPhone can play, but I don’t get any video, only audio and a Quicktime logo where the picture would normally be.

    The iPhone in question is a 16GB 3GS (I’ve tested two handsets running slightly different software versions, one with 3.1.3 and one with the previous version, with the same result on both).

  21. February 10th, 2010 at 19:18 | #21

    I don’t suppose you have any MPEG-4 Part 2 files which do work with the iPhone that I could use as a reference do you?

  1. April 4th, 2008 at 22:30 | #1
  2. July 10th, 2008 at 15:51 | #2
  3. August 29th, 2008 at 01:37 | #3
  4. September 19th, 2008 at 15:26 | #4
  5. September 28th, 2008 at 15:39 | #5
  6. November 15th, 2008 at 22:02 | #6
  7. December 28th, 2008 at 18:53 | #7
  8. May 22nd, 2009 at 05:02 | #8
  9. September 19th, 2009 at 04:17 | #9
  10. January 20th, 2010 at 23:52 | #10
You must be logged in to post a comment.