Convert for iPhone using mencoder/ffmpeg

June 13th, 2008 | Categories: iPhone | Tags:

UPDATE: Check out my even newer post for detailed instructions.

UPDATE: Check my newer post for detailed instructions.

I found this through the Google cache of I found this at http://www.dudek.org/blog/82.  I’m not sure why I couldn’t access it before, but, like Mark Twain, the reports of its death were greatly exaggerated.  For me, the most relevant part is the ffmpeg command line:

iphone video
INFILE=”$1″
OUTFILE=”$2″
ffmpeg -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 480×320 -aspect 4:3 -i “$INFILE” “$OUTFILE”
This should be fine with any ipod-like device, but it is customized for the iPhone screen size. The -s 480×320 refers to the size of the iPhone screen; customization for the video iPod would use the same incantation, but with a screen size of 320×240 to produce slightly smaller files. On the other hand, showing the video on TV would benefit from the larger size, or even 640×480. The Apple TV uses as much as 1280×720. (It is never worth using a larger size than your input footage, however, which is often limited to 640×480 for NTSC.)

I’ll look into whether ffmpeg can do dynamic aspect ratios like mencoder when I get a chance.

  1. June 18th, 2008 at 09:37
    Reply | Quote | #1

    The original web cite you cite should be up (it’s mine) and it includes a few minor adjustments and updates.

  2. June 18th, 2008 at 09:42
    Reply | Quote | #2

    Interesting – I still can’t access your site, but I see it’s not down. Did you switch DNS servers lately?

    Edit: OK, now I can see it. Not sure what was going on. I took down the bulk of the text, since I only posted it because I thought it would get lost in the ether.

  3. March 3rd, 2009 at 09:19
    Reply | Quote | #3

    My commutes will be more fun now. Thanks!

  4. March 3rd, 2009 at 16:36
    Reply | Quote | #4

    Whups I spoke too soon, this doesn’t work at all. For starters you should have -i a lot earlier on the line. There are some other errors as well, here is what I got so far:

    INFILE=”$1″
    OUTFILE=”$1.mp4″
    ffmpeg -i “$INFILE” -f mp4 -vcodec mpeg4 -maxrate 1000k -b 700k -qmin 3 -qmax 5 -bufsize 4096k -g 300 -acodec libfaac -ab 192k -s 480×320 -aspect 4:3 “$OUTFILE”

    Sadly it still doesn’t produce any results to be proud of, the video encodes into a half-speed, double-length monster. Audio plays back fine.

  5. Wouter
    May 23rd, 2009 at 10:41
    Reply | Quote | #5

    @Martin
    So… why isn’t iTunes importing my files? When I use ‘add file to library’, nothing seems to happen. I don’t get this.. I used the syntax like the ones above, file command says:

    root@mybox:/home/pino# file *.avi
    24.S07E01.720p.HDTV.X264-DIMENSION.avi: ISO Media, MPEG v4 system, version 1
    24.S07E02.720p.HDTV.X264-DIMENSION.avi: ISO Media, MPEG v4 system, version 1

    Any thoughts/help?

  6. chris
    November 2nd, 2009 at 17:16
    Reply | Quote | #6

    since i solved the same problems, but were able to handle them, here are my personal ffmpeg (version 0.5.*) settings for a one-pass ffmpeg encode to an ipod 5G compatible mp4 with reasonable speed:

    for 320×240 (ipod):
    ffmpeg -i INPUT.AVI -acodec libfaac -ac 2 -vcodec mpeg4 -s 320×240 -b 500kb -ab 96kb -coder 1 -flags +aic+cbp+loop+mv4+naq -trellis 1 OUTPUT.MP4

    and for 640×480 (iphone, appletv…):
    ffmpeg -i INPUT.AVI -acodec libfaac -ac 2 -vcodec mpeg4 -s 640×480 -b 1000kb -ab 96kb -coder 1 -flags +aic+cbp+loop+mv4+naq -trellis 1 OUTPUT.MP4

    the aspect ration will always be honoured, but since i only used these settings with an ipod, i can just expect the iphone to play them correctly — may the force be with you *hehe*

    ps: i assembled a script to make it very easy to do that job, interested?

  7. onlydarksets
    November 2nd, 2009 at 21:21
    Reply | Quote | #7

    Sure – please post it. I’m using DTb and Handbrake these days, but always looking for ways to tweak the process.

1 trackbacks

Comments are closed.