HOWTO install and use FFmpeg on Mac OS X Leopard

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:
$ 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.
58 comments on “HOWTO install and use FFmpeg on Mac OS X Leopard”
-
Rytis wrote:
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.
Monday 26-11-2007
-
Wout wrote:
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).
Cheers for the help !
Thursday 29-11-2007
-
Hay wrote:
Hi Wout,
AFAIK codecs are installed automatically when compiling the program. Maybe you forgot to compile with the added ‘faac’ and ‘faad’ libraries? You can always view all possible formats by using$ ffmpeg -formats
A ‘D’ before a codec means decode, an ‘E’ means encode. You might have forgotten to include bitrate and/or other options that are needed for a certain codec.
The FFMPEG mailing lists might also be of help: http://ffmpeg.mplayerhq.hu/mailinglists.html
Thursday 29-11-2007
-
Justin wrote:
Thank you so much for this tutorial! I had been banging my head against the wall for two months trying to get h264 / faac / faad support into ffmpeg!
Thanks again!
Monday 03-12-2007
-
Marc wrote:
Thanks! Greate guide… Now I can revert back to commandline when doing video encoding for my iPhone :)
Tuesday 08-01-2008
-
Morphis wrote:
I need a tutorial for install ffmpeg-php in Leopard if any know one post plese.
Thursday 20-03-2008
-
marko wrote:
THANK YOU!
Sunday 13-04-2008
-
nubi wrote:
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?
Friday 25-04-2008
-
Derek wrote:
@Wout
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.
Saturday 10-05-2008
-
athony amos wrote:
thanks so much! made my first osx box complete!
newbs! don’t forget where you are/ln: try the leading ./ if it doesn’t work
sudo ./port install ffmpeg +gpl +lame +x264 +xvid
*crickets*
./ffmpeg
AND
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.
Friday 13-06-2008
-
Nemo wrote:
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.
Tuesday 01-07-2008
-
Nemo wrote:
OK, now it’s installing perl. This is not right.
Tuesday 01-07-2008
-
Hay wrote:
@Nemo: No, i think it needs that, when i first installed ffmpeg it took about an hour before it was finished downloading all dependencies.
Tuesday 01-07-2008
-
albert wrote:
please can u help me y trying to install this program but y have a error that say Unable to open port: invalid command name “use_parallel_build” please can u help me
Saturday 23-08-2008
-
j0ris wrote:
@albert:
You probably need version 1.6 of Macports. The link in the post takes you to 1.5.
http://svn.macosforge.org/repository/macports/downloads/MacPorts-1.6.0/
Monday 08-09-2008
-
Hay wrote:
@j0ris: thanks for the link, i’ve updated the post with it.
Friday 12-09-2008
-
Egor wrote:
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 happendsSo I never even got to installing ffmpleg itself. Any ideas what’s wrong ?
Thursday 02-10-2008
-
Hay wrote:
@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.
Saturday 04-10-2008
-
j0ris wrote:
Hay, you may also want to mention that Xcode tools must be installed prior to installing Macports.
Monday 13-10-2008
-
j0ris wrote:
And you can also install FFmpeg by using the binary included with FFmpegX:
http://www.macosxhints.com/article.php?story=20061220082125312
Monday 13-10-2008
-
brian wrote:
I’ve just successfully installed v 1.6.0 for Tiger and have the same problem as Egor. ‘port’ by itself as suggested similarly yields:
tcsh: port: Command not found
Same thing if I try the update process.
Maybe it’s a path problem — where should the port command actually end up after instillation?
Tuesday 21-10-2008
-
Hay wrote:
@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?
Wednesday 22-10-2008
-
perry wrote:
Installing macports is easy, but it places the command line file in a different folder than the standard terminal (or X-terminal) is looking in…
A few ways of fixing this, the easiest one is just locating the file port itself and copy paste it to one of the folders that terminal is looking in…
to see which folder terminal uses: $ which port
it will tell you what folders it looked in!
good luck.. installing ffmpeg hasnt worked for me yet though :(
Monday 03-11-2008
-
Scott Motte » Blog Archive » How to install ffmpeg on ubuntu hardy on slicehost wrote:
[...] a side not, here’s how to install ffmpeg on mac os x leopard for testing of your app on localhost with [...]
Wednesday 12-11-2008
-
robert wrote:
Will these instructions work on Tiger 10.4.11? I am doing it now and its building a ton of things that I am not sure I need.
After I ran:
“sudo port install +gpl +lame +x264 +xvid”
and typed:
“ffmpeg” and “ffmpeg -version”
I got this:
“-bash: ffmpeg: command not found”
Is there something that I could have missed any help would be much appreciated.
Thanks
Monday 17-11-2008
-
Hay wrote:
@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.
Tuesday 18-11-2008
-
David wrote:
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.
Wednesday 19-11-2008
-
robert wrote:
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
but i did use –enable-shared
any thoughts?
Thursday 20-11-2008
-
Hay wrote:
@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.
Thursday 20-11-2008
-
Navigator Technology » Blog Archive » Using ffmpeg - a free command-line video transcoder- on a mac wrote:
[...] HOWTO install and use FFmpeg on Mac OS X Leopard » Hay Kranen . [...]
Thursday 20-11-2008
-
Robert wrote:
Will do, I come back once I find something solid.
Thanks.
Thursday 20-11-2008
-
Brian wrote:
The version of ffmpeg is a little old (SVN-r14381), when for my needs I think I need at least r14480. How often does the MacPorts source update?
Saturday 22-11-2008
-
Aral Balkan - Links for 2008-11-28 wrote:
[...] 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) [...]
Saturday 29-11-2008
-
greg wrote:
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.
Sunday 07-12-2008
-
Hay wrote:
@greg Try opening a terminal and simply type ‘sudo’ (without the quotes), you should get this output:
usage: sudo -K | -L | -V | -h | -k | -l | -v
usage: sudo [-HPSb] [-p prompt] [-u username|#uid]
{ -e file [...] | -i | -s | }As far as i know, ‘sudo’ is available on all Mac OS X installations.
Monday 08-12-2008
-
greg wrote:
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.
thanks
Tuesday 09-12-2008
-
vigo/bronx wrote:
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!
Thursday 18-12-2008
-
Andrew wrote:
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.
Monday 29-12-2008
-
Dave wrote:
Dependencies have been installing for about 30 minutes.
Now it is hung on:
—> Fetching ffmpeg
Thursday 29-01-2009
-
for the good time » Wordpress - oh my how things have changed! wrote:
[...] to install the source code and compile it myself. For ffmpeg, I followed the instructions on this post. Basically, I followed these [...]
Sunday 01-02-2009
-
AR wrote:
I have tried the instructions here. ffmpeg is installed successfully. But I am still not able to do the encoding. This is what I run and the error I get.
udo ffmpeg -i SA-movie.avi -b 256k -r 25 -s 400×300 -vcodec flv -acodec libmp3lame -y mymovie.mov
FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: –prefix=/opt/local –disable-vhook –mandir=/opt/local/share/man –enable-shared –enable-pthreads –disable-mmx –cc=gcc-4.0 –enable-gpl –enable-postproc –enable-libmp3lame –enable-liba52
libavutil 49.10. 0 / 49.10. 0
libavcodec 51.71. 0 / 51.71. 0
libavformat 52.22. 1 / 52.22. 1
libavdevice 52. 1. 0 / 52. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
built on Feb 3 2009 00:54:50, gcc: 4.0.1 (Apple Inc. build 5490)
Input #0, avi, from ‘SA-movie.avi’:
Duration: 00:01:09.63, start: 0.000000, bitrate: 11029 kb/s
Stream #0.0: Video: mjpeg, yuvj422p, 640×480, 30.00 tb(r)
Stream #0.1: Audio: pcm_u8, 11024 Hz, mono, s16, 88 kb/s
[imgconvert @ 0xd00d90]PIX_FMT_YUV420P will be used as an intermediate format for rescaling
Output #0, mov, to ‘mymovie.mov’:
Stream #0.0: Video: flv, yuv420p, 400×300, q=2-31, 256 kb/s, 25.00 tb(c)
Stream #0.1: Audio: libmp3lame, 11024 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Error while opening codec for output stream #0.1 – maybe incorrect parameters such as bit_rate, rate, width or heightAny help is really appreciated.
Tuesday 03-02-2009
-
Hay wrote:
It looks like you didn’t specify the correct parameters for ffmpeg. ffmpeg can read your file, but maybe you set a setting wrong somewhere?
Tuesday 03-02-2009
-
AR wrote:
What is a correct setting? can you tell me what it is.
Tuesday 03-02-2009
-
geza wrote:
hi, help please!
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!
Wednesday 04-02-2009
-
Dan wrote:
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.
Wednesday 11-02-2009
-
Sri wrote:
Thank you very much. Was pulling my hair out trying to do manual install.
This way its a breeze !
Wednesday 11-02-2009
-
Sri wrote:
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 checksumsThank you for any help.
Wednesday 11-02-2009
-
Sri wrote:
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
}}}
Monday 16-02-2009
-
Gijs wrote:
Thanks for this excellent write-up..
Wednesday 04-03-2009
-
Dan wrote:
Thanks!
Wednesday 04-03-2009
-
MacPorts - la puissance de l’open-source sur votre Mac Os X | Réseau social des créateurs de site web wrote:
[...] Source : http://www.haykranen.nl/2007/11/21/howto-install-and-use-ffmpeg-on-mac-os-x-leopard/ [...]
Monday 06-07-2009
-
The War Room: a paratrooper's personal thinktank wrote:
[...] 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 [...]
Monday 03-08-2009
-
mito wrote:
For precompiled binaries see:
Thursday 20-08-2009
-
Scott Haines wrote:
I just installed ffmpeg locally and there are some new updates to the ./configure protocol. based on changes to the libfaad and libfaac
when you go to configure the file, use this command.
./configure –enable-libmp3lame –enable-libfaac –enable-libfaad –enable-gpl –enable-nonfree –enable-shared –disable-mmx
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)
Monday 12-10-2009
-
Problems with FFMpeg on a DVD? Try Handbrake « The Wheat Field wrote:
[...] video from a Panasonic EH65 burned onto a DVD into an audio MP3 file using FFmpeg (Windows | Mac [Alternative: ffmpeg from ffmpegX, but did not work well for me]). The typical ffmpeg -i [...]
Wednesday 14-10-2009
-
Esthon Wood wrote:
Hi, how do you uninstall ffmpeg using port? Thanks :)
Tuesday 15-12-2009
-
Hay wrote:
sudo port uninstall ffmpeg
Not that weird right? ;)
Tuesday 15-12-2009
-
Bertil wrote:
Audacity installs a version of ffmpeg. If it works only in Audacity I do not know. (Also on Mac.)
Wednesday 03-03-2010