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 slow -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 slow_firstpass -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 slow -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 slow -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 slow_firstpass -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 slow -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
Pingback: pete’s blog » MP4 for the iPod-touch
Pingback: Howcast Tech Blog » Blog Archive » Podcast Transcoding with FFmpeg and AtomicParsley
Pingback: Howcast Tech Blog » Blog Archive » Podcast Transcoding Re-visited
Pingback: Convert Sage recordings to iPhone « onlydarksets
Pingback: ipod videos | 2-cents
Pingback: Del.icio.us op 15 november 2008 | Michel Vuijlsteke's weblog
Pingback: でっつ :: Entries :: FlowPlayerで再生するためのファイル件
Pingback: Convert any video file for iPhone in Intrepid (Ubuntu 8.10) | En.dogeno.us - CaiLog
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
Using the first option (the TV one) I’m able to encode, but the audio is choppy, cracklly etc. just not correct.
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.
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).
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.
Ok, if I specifiy -ar 41000 then there is no issue with the audio
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.
plays on the iPhone though.
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.
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.
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.
@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?
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?
Pingback: aubonbeurre sandbox » ffmpeg iPod guide
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.
Yes, you can just add ‘-flags2 -bpyramid’.
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.
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?
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.
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
Pingback: HOWTO: Install and use the latest FFmpeg and x264 debian / ubuntu » Unika Tek Boutik
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).
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?
Pingback: Install FFMPEG correctly on ubuntu 9.0.4 www.chaoman.com
Cool!
This article really helpful to me.
Thx, man