Wednesday, September 22, 2010

Convert movies to iPhone friendly format with ffmpeg on a Mac

I wanted to make a bash script that parsed a given directory for movie files and then made them into an iPhone friendly format. In this script I use HandBrakeCLI and ffmpeg.

HandBrakeCLI is a no-brainer to install, just download the binary and run it, but ffmpeg is a bit harder to get working, so here are a brief and "technical" instruction on how I succeeded. Apple Developer Tools is required!

1. mkdir ~/source
2. cd ~/source

3. cvs -d:pserver:anonymous@lame.cvs.sourceforge.net:/cvsroot/lame login (press enter when asked for passwd)
4. cvs -z3 -d:pserver:anonymous@lame.cvs.sourceforge.net:/cvsroot/lame co -P lame
5. cd lame
6. ./configure
7. make
8. sudo make install

9. cd ~/source
10. cvs -d:pserver:anonymous@faac.cvs.sourceforge.net:/cvsroot/faac login
11. cvs -z3 -d:pserver:anonymous@faac.cvs.sourceforge.net:/cvsroot/faac co -P faac
12. cd faac
13. ./configure
14. make
15. sudo make install

16. cd ~/source
17. svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
18. cd ffmpeg
19. ./configure --enable-libmp3lame --enable-shared --disable-mmx --arch=x86_64 --enable-libfaac --enable-gpl --enable-nonfree --enable-avfilter --enable-postproc
20. make
21. sudo make install


And now, when you're done, you can convert movies to mp4 that is 480px wide and keeping the aspect ratio. This is what I use, found bits here and there and put it together to this:

ffmpeg -i INPUT.avi -acodec libfaac -ac 2 -vcodec mpeg4 -vf "scale=480:-1" -b 1000k -ab 128k -coder 1 -flags +aic+cbp+loop+mv4+naq -trellis 1 OUTPUT.mp4

I'm using ffmpeg SVN-r25157, Lame 3.98.4 and faac 1.28 on Mac OS X 10.6.4. If you download and compile the standard ffmpeg 0.6, the "-vf "scale=480:-1" bit will not work. So download the latest through cvs.

This is more or less a rip off of the instruction at stephenjungels.com. In the latest svn of ffmpeg, there is no support for faad, so I left that bit out.

This instruction is available "as is". I will not answer any questions about "How do I do this and that?"