Blog archives

HOWTO install and use FFmpeg on Mac OS X Leopard

72 comments

ffmpeg_mac.jpg

Notice: this article is pretty outdated, and things have gotten a lot simpler. For now i would recommend installing Homebrew, and simply typing brew install ffmpeg. That’s it.

If you have ever delved into the deep caves of video encoding and transcoding you’ve probably come along FFmpeg, the ‘swiss army knife’ of video encoding tools. Basically, FFmpeg is a command-line tool that allows you to convert virtually any video and audio format to another format. That’s very handy if you want to convert your DVD’s to XVID, a movie to a format you can play on your iPod or PSP or a Flash movie you can use on your website without needing to buy the whole Flash software package.

However, if you’re like me and you are more interested in making movies than converting them you might get a little scared by the fact that FFmpeg is command-line only, doesn’t come with good documentation and can only be ‘built from source’, which means that you can’t actually download the thing and run it, you have to compile it first. Phew.

macports.pngFortunately there is a solution and it’s called MacPorts. MacPorts is a software package that makes the whole process of running free and open source applications under Mac OS X a whole lot simpler by providing a simple command that you can run from the terminal. At the moment i’m writing this, 4376 applications can be installed using MacPorts.

To start you first have to download the appropriate package and install it. Make sure you have installed Xcode first. This is Apple’s developer toolkit that comes bundled with every Mac but isn’t installed automatically with Mac OS X. To install it, get your original Mac OS X install discs and install it from there.

So, when you finished installing MacPorts open a terminal (you can find this in your Applications/Utilities folder as Terminal.app) and try to see if it worked by executing:

$ port help

This will output all possible help options. If you’re getting nervous already by seeing all those letters on the screen you might download a graphical frontend to the port command. A free frontend is Porticus, which is pretty decent but still in beta stage, so you might have some trouble with it. PortAuthority is another option, but it will set you back $20. If you’re not getting nervous now, read on.

The most important options for port are called search and install which will let port, well.. search for packages and install them! Let’s try searching for ffmpeg

$ port search ffmpeg
ffmpeg multimedia/ffmpeg 0.4.9-pre1 Digital VCR and streaming server

You could now run port install ffmpeg to install the whole thing, but then you might not install all the things you want. Port packages can also contain variants which install additional options. To see all possible variants for ffmpeg run:

$ port variants ffmpeg
ffmpeg has the variants: universal, darwin_9, gpl, postproc, lame, libogg, vorbis, theora, faac, faad, xvid, x264, a52

Aha! If you wouldn’t install these variants too you couldn’t encode your movies to the popular XVID format, with MP3 audio (because you’re lacking lame) or to the free H264-compatible x264 format. You can add these variants to the install package by simply adding them to the command preceded by a plus:

$ port install ffmpeg +gpl +lame +x264 +xvid

You also need to add the gpl variant because xvid is licensed under the terms of the GNU General Public License (GPL) instead of FFmpeg which is licensed under the GNU Lesser General Public License (LGPL). When you have tried to use the command above to install FFmpeg you probably got an error back along the lines of:

Error: Unable to execute port: can't create directory "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_multimedia_ffmpeg": permission denied

This is because you’re installing into some of the directories of the system which a normal user doesn’t have write access to. To do this you have to precede sudo to your install command. If you haven’t enabled sudo access for your Mac, read this article. Let’s repeat the procedure above using sudo:

$ sudo port install ffmpeg +gpl +lame +x264 +xvid

You will now be prompted for a password. After that, port will start downloading and compiling many packages (many which are needed for FFmpeg to run). This might take a while (maybe even up to an hour if you have an old system), so leave your Mac on and do something else, but don’t close the Terminal window.

When everything is installed and you got no errors, try running ffmpeg:

$ ffmpeg

If all worked well you will now get a huge amount of information. A more minimal way of checking if ffmpeg is installed correctly is by running it with the -version argument:

$ ffmpeg -version

So, let’s encode a movie! For these instructions, i’m supposing you have a movie named mymovie.avi, which is a movie i encoded with XVID and MP3 audio, but it could of course be any movie. You can view a lot of information about a movie by using the -i (input) parameter:

$ ffmpeg -i mymovie.avi
Input #0, avi, from 'mymovie.avi':
Duration: 00:03:43.6, start: 0.000000, bitrate: 1405 kb/s
Stream #0.0: Video: msmpeg4, yuv420p, 640x480, 25.00 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s

Let’s say we want to convert this file to a movie encoded using the x264 codec, with a bitrate of 256kb/s , and AAC audio. To view all possible encoding formats you can run FFmpeg with the -formats parameter:

$ ffmpeg -formats

This will output all possible formats (it’s quite a long list). You can use the grep command to search through the list for specific keywords:
$ ffmpeg -formats | grep mp3
DE mp3 MPEG audio layer 3
DEA mp3
D A mp3adu
D A mp3on4

The ‘D” stands for decoding (reading the file), the ‘E’ for encoding (writing the file) and the ‘A’ for audio (that this codec is used for audio). It will be a ‘V’ if the codec is used for video.

So here is the command i used to transcode my XVID/MP3 movie to a X264/AAC movie with a bitrate of 256k:

$ ffmpeg -i mymovie.avi -b 256k -vcodec h264 -acodec aac mymovie.mov

You can’t view the results of your work with FFmpeg, for that you need a movie player (FFmpeg only transcodes movies). I recommend VLC. If you want to stay on the command line you could try mplayer (which you can install using port). There’s also Quicktime, but it might not be able to run every codec.

If for some reason you can’t compile ffmpeg you might have luck with this trick. It essentially involves using a precompiled ffmpeg executable from a shareware package (ffmpegX).

So, i hope this article has given you some advice on how to run FFmpeg under Mac OS X. If you have any comments, please feel free to drop them in below this post.

You may also digg this article.

Add a comment

72 comments