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.
Fortunately 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:
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
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.
Just as a side note, I tried installing MacPorts on 10.5, all went ok, but took suspiciously long time to instal. I looked at the console output and it said ports had issues with rsync.
I then ran port -d selfsync and it all worked fine.
Great job on this clear tutorial ! Exactly the thing I needed.
Encoding works fine, but I can’t seem to convert certain types such as MP4 files. Even the AAC Audio codec seems to be a mystery to my FFMPEG installation. (By the way I installed it with the options you suggested).
How would I go about installing extra codecs ? In the FFMEG site I can see tons of codecs, but I wouldn’t know how to install them locally. Can you help me out with this one ?
(running the sudo port install command again with extra options, just gave me a couple of errors, so I guess I’m doing things wrong here).
Thank you so much!
Unfortunately the current version of ffmpeg doesn’t install. Somebody here http://trac.macosforge.org/projects/macports/ticket/14960 seems to have found a way to make this work but I can’t seem to do it myself. I’ve had ffmpeg working before this update and wound up with nothing trying to install it again with FAAC…
Anyone know what to do?
It doesn’t recognize AAC because you didn’t install it with +faac and/or +faad. Just reinstall using ports and you should be off to the races.
newbs! don’t forget where you are/ln: try the leading ./ if it doesn’t work
sudo ./port install ffmpeg +gpl +lame +x264 +xvid
it took me a bit of time to get ffmpeg to work, months to get bash scripts exactly right; it’s the most powerful program you’ll find; everything’s built on it; don’t get discouraged. ‘man ffmpeg’ is your friend.
So, I’m trying MacPorts for the first time right now, and as part of the ffmpeg install, it’s first installing… ncurses? WTF? A. ncurses already comes with Mac OS X, and B. since when does ffmpeg use ncurses? Granted, I selected “+gpl +postproc +lame +theora +faac +faad +x264 +a52”, but where do any of those use ncurses either? Oh well.
Anyway, thanks for the post. I’ve known about MacPorts for a while, but this (and the lack of any precompiled ffmpeg binaries that I could find!) gave me the kick I needed to finally try it.
Tried to install MacPorts and I don’t think it actually installs it. When I type ” $ port help” into the Terminal I get this: -bash: port: command not found
I reinstall it and still same result. I use this package: MacPorts-1.6.0-10.5-Leopard.dmg since I run Leopard. Tried to do $ sudo ports selfupdate and it asks me for a poassword (???) and nothing happends
So I never even got to installing ffmpleg itself. Any ideas what’s wrong ?
@Egor: Remember that you do not have to type the dollar sign ($), that’s just a common way of showing that you’re in a terminal. Try typing ‘port’ (without the quotes), pressing enter and see what happens.
Also, it is perfectly normal that you’re being asked for a password. The ‘sudo’ command is used when you want to do something that affects the whole system, not just your user account. You might have seen this earlier when installing some programs on your Mac (‘Mac OS X needs your password to continue..’). So just enter your normal password.
Hay, you may also want to mention that Xcode tools must be installed prior to installing Macports.
And you can also install FFmpeg by using the binary included with FFmpegX:
@j0ris: thanks for the tips. I’ve added them to the article.
@brain: Try typing in ‘which port’ in your terminal. In a default installation it will end up in /opt/local/bin/. If you get no results it is not installed on your system. Maybe you didn’t install XCode first or used an older package?
@robert: i think you have the wrong command here, you should include ‘ffmpeg’ in your install command
sudo port install ffmpeg +gpl +lame +x264 +xvid
It’s normal that port needs to install lots of stuff, ffmpeg has lots of dependencies.
Thanks for this guide! I did have one problem though after installing MacPorts, which wasn’t immediately obvious. Using the MacPorts installer package, the default path is /opt/local/bin. When I search for the executable using “which port”, I got nothing. Turns out that this path is not a part of the default search paths in bash. To add the port path to your default paths, drop into Terminal and type “sudo pico /etc/paths”. Type in your password then add “/opt/local/bin” at the end of the list. Type Control-O to save the file then Control-X to exit pico. Close then re-launch Terminal for the changes to take affect.
Thanks yes that did the trick. And I can convert a video woohoo. I am using MAMP on my mac and whein i test with phpinfo() i do not see the ffmpeg support also when i try to install the ffmpeg-php :
./configure in the ffmpeg-php dir it says:
configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the –enable-shared option
@robert: i suppose you used port to install ffmpeg-php? That doesn’t work because MAMP has a PHP installation on its own. Mac OS X comes with PHP built in, but i’m not even sure if port uses that installation or that you have to install PHP from port too. Maybe you should Google around a bit on installing PHP extensions on Mac OS X.
[…] HOWTO install and use FFmpeg on Mac OS X Leopard Â» Hay Kranen 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. (tags: ffmpeg os x install) […]
i’m pretty new at this, i’ve got xcodes and macports installed, i found i had to either open ‘port’ which was burried in the folder that appeared after installing macports or type in that path to a blank terminal window before i could get terminal to find me anything. after doing that i can get all the info i need, but it won’t recognize the ‘sudo’ command when i try to actually install the files. any thoughts? am i doing this wrong? i’m going to keep playing with it.
As far as i know, ‘sudo’ is available on all Mac OS X installations.
that worked, but i still can’t get any further. i retried a few variations of the install command with no new results. i get the feeling this was only the first part of your response, let me know what else i might try.
nice doc but you realy don’t need “ports” to instal ffmpeg… also, ports is not good if you use “mobileme”… ( if you install apache2 from ports and disable internal apache, it screws all mobileMe stuff )… yes i know, its not easy as in ports but try to compile and build your own ffmpeg. i compiled x264 with assembler support ( nasm ), fps increased like 50fps to 200fps… again, don’t use ports!
On Leopard with MacPort 1.700, ffmpeg will NOT build with x264 or xvid encoding enabled. You get decode, no encode. No errors, it just builds without it.
Dependencies have been installing for about 30 minutes.
Now it is hung on:
—> Fetching ffmpeg
I’m stuck up with port install on a G5 PPC Leopard(10.5.6).. Does anyone have a full featured precompiled binary??(faac,faad,lame,x264,xvid,a52,postproc,gpl)
I have a binary only for Intel, but ffmpeg dies with it..
Thanks a lot!
Macports is great way of installing ffmpeg and the various components (I have it running now) however Mac Ports does nor support the instillation ffmpeg-php extension. Does anyone know how to install this manually alongside the install of ffmpeg via Mac Ports? I have been looking around an people just run into problems. I need a good tutorial.
Thank you very much. Was pulling my hair out trying to do manual install.
This way its a breeze !
Everything was running right – till I got stumbled with this error.
Error: Checksum (md5) mismatch for cdparanoia-0.9.8.tar.gz
Error: Target org.macports.checksum returned: Unable to verify file checksums
Thank you for any help.
Here is the lastest update from MacPorts – incase someone encounters the same issue.
concerning ffmpeg, the current version of ffmpeg does not require the
variants +gpl +lame +x264 +xvid as these are now
included by default. Please make sure that your ports tree is up to date
and just install ffmpeg without any variants
sudo port selfupdate
sudo port clean ffmpeg
sudo port install ffmpeg
[…] and use FFmpeg on Mac OS X Leopard » Hay Kranen Filed in video technology, web server technology. HOWTO install and use FFmpeg on Mac OS X Leopard » Hay Kranen . READ THIS FIRST – USES MacPorts. No […]
This will enable the gpl license for the ffmpeg install as well as the nonfree license for the faac install, I hope this helps, I now have a great upto date install of ffmpeg running on my Mac. (10-12-09)
What is the best way to bulk convert movie files on a Mac?…
There is Adobe Media Encoder which lets you batch files with drag and drop. The downside is that I think it only comes with a purchase of Flash CS5. Depending on your confidence with coding and Terminal usage, you could look into ffmpeg combined with A…
It’s been a long time since this incredible article was written but it still comes up first when you google “Mac Ports ffmpeg” It’s worth noting that it appears as if now the default is to give you the most functional configuration by default, and you only need to use variants if you want to exclude certain functionality.
Also, if video is your only concern, Handbrake now takes video file input, is simpler to use, free, and actually uses ffmpeg anyway. Heck, there’s even a command line version that has a much simpler syntax than ffmpeg. Pretty much the only reason not to use it is that it only outputs video files, and not audio-only file types.
Thanks again for writing this up in the first place.
Dude, please tell me that youre heading to write a great deal more. I notice you havent written an additional weblog for a whilst (Im just catching up myself). Your weblog is just too essential to turn out to be missed. Youve received so extremely a lot to say, this kind of understanding about this subject it would be a shame to see this weblog disappear. The internet needs you, man!