ffmpeg on Mac Os X Lion

Now that I'm using a Mac (with Mac OS) at work I'm sorely missing truly essential tools such as ffmpeg. The only binary build I could find (without having to download fink and a ton more packages that I don't really need) was a build from 2006. Two thousand and six! Which in ffmpeg terms is like the Pleistocene.

So given that I have XCode installed anyway, I decided to build ffmpeg myself, just as I had done back in 2007. It should be as doable as back then! I found a post by Martin Los, which was pretty much all I needed to get started. I just changed a few things; for example you don't need to -enable-libfaad anymore with recent versions of ffmpeg as I think they have their own (experimental?) faad encoder, and don't rely on an external library. I also didn't install SDL as from what I remember it was only used for showing ffplay's output (mostly for opening a window, showing the decoded video, etc). In any case, ffmpeg compiled fine without having SDL, so I'm assuming it just didn't compile ffplay which frankly I don't use.

After I checked that Martin's method worked, I decided to convert his instructions into an script. Usually I would write this script with Python but I am trying to learn a bit more bash lately, so I made an effort (and several searches) and wrote it in bash --and a couple of other utilities such as sed which were already installed on Mac. I believe the only tool which isn't installed by default is Subversion, but I am not entirely sure about this (and I'm not going to format the system just to check!).

It was also interesting to use cURL (which is installed on a bare Mac Os) instead of wget, which I expected to be installed already (it wasn't). Apparently SourceForge (which is where the libraries' sources are hosted) makes some sort of redirection even if you're using a direct link. The -L option allows it to follow through 30x redirections until it finds a 200 code or similar.

And here is the script for your enjoyment and all that:


# Thanks to Martin Los for his guide: http://www.martinlos.com/?p=41

URLS=("http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.3.tar.gz" "http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz" "http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz")

for i in "${URLS[@]}"
    echo $i
    curl -O -L $i

for i in $( ls *.tar.gz ); do
    tar -xzvf $i

for i in $( ls -d */); do
    cd $i
    sudo make install
    cd ..

svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-libmp3lame --enable-libfaac --enable-gpl --enable-nonfree --enable-shared --disable-mmx --arch=x86_64 --cpu=core2
sudo make install

Using this shiny fresh build of ffmpeg I was able to convert several .MOV files which were rendered for iOS devices into MP4 files that Android devices could palate. This is the script I wrote (also with bash, to practise even more):

for i in $(ls *.mov); do
    ffmpeg -i $i -r 30 -vcodec mpeg4 -acodec libfaac -ac 1 -ar 44100 -vf scale=$WIDTH:$HEIGHT -b $BITRATE  -y $i.mp4
for i in *.mov.mp4; do j=`echo $i | sed 's/.mov.mp4/.mp4/'`; mv "$i" "$j"; done

Hope it's useful!