ffmpeg installation on Mac OSX

ffmpeg installation on Mac OSX

Notice: I have posted a newer vesion of these installations on this site. For the latest info on installing FFmpeg on Mac OS X I suggest you read the new one.

This article explains how to install ffmpeg and ffmpeg-php on Mac OS X. ffmpeg is a command line tool used to convert video and audio formats. It allows you to convert audio and video between any of its supported formats.

ffmpeg-php is an extension for php that allows you to access information about the movies/videos from within php. The actual commands to convert the video must still be executed with functions such as exec() or system(), but by having ffmpeg-php you can test the video(say to verify an uploaded file is actually a video) and gain access to information that you would not have otherwise.

My primary interest in ffmpeg is for converting videos of various formats into a flash video format for display on websites. This setup works to allow me to develop scripts on my locally on my mac that I later use on my linux server.

My setup for this install is as follows:
Mac OS X 10.4.11
Marc Linyanages' (entropy) PHP version 5.2.4

I have not tested this on either different versions of php or Mac OS X. But this is a successful install with the latest libraries for this setup.

This installation process will be conducted from a terminal shell. If you are completely new to this I suggest that you read up on linux shell commands first as the entire process will take place in Terminal.

Prerequisites

Apple Developer Tools

To have access to the command line tools necessary to install ffmpeg and its required tools you need to have Apple's Developer Tools installed on your Mac. This will give you the C development tools you need to run commands such as 'configure", "make", and "make install".

The Apple Developer Tools package is located on the install disk for your Mac in a folder named Xcode Tools. Within the Xcode folder you will find a file named "XcodeTools.mpkg". Double click this package to begin the install and proceed as normal. Note: the Xcode Tools package is rather large, and will take up around 2 gigs of disk space. It’s a necessary price to pay if you want to develop with these tools.

Ensuring PHP Continuity

We need to make sure that your terminal and your server are using the same php binary. If you are using the php setup that came with your Mac this should not be a problem. If however you are using a version that you installed, either from entropy or MAMP for example, then your command line will be pointing to a different php than you are using with your server.

You can find this out by running a phpinfo() script and comparing the values against values  returned by running "php -i" from your terminal. If they are different versions you will need to modify the '/usr/bin/php-config' file to contain the appropriate values and move/remove /usr/bin/php and replace it with a symlinc to your active php binary, such as:

$ mv /usr/bin/php /usr/bin/php_bak
$ ln -s /path/to/your/phps/bin/php /usr/bin/php

While your at it you will need to do the same with phpize:
$ mv /usr/bin/phpize /usr/local/phpize_bak
$ ln -s /path/to/your/phps/bin/phpize /usr/bin/phpize

Doing this allows the terminal to point to the correct php when called for by the ffmpeg-php configure script.

make – version 3.81 or later

ffmpeg requires you to make and install it via the shell. Due to a broken backward compatibility issue you will need to upgrade your version of "make" to version 3.81 or newer if you want to install the latest version of ffmpeg. We will include this step in the tutorial.

Setting Up our Directories and Downloading Packages

We will be installing these packages in ‘/usr/local/’. First we will create a directory for our source files. The dollar sign($) begining a line in this tutorial represents the command line prompt.

$ cd /usr/local
$ sudo mkdir ./src
$ cd ./src

 

Install wget

I preffer working with wget over curl, it seems to work better for me in getting these packages. First we have to download and install it though, which we will use curl to do.

 

$ curl -O http://ftp.gnu.org/pub/gnu/wget/wget-1.9.1.tar.gz
$ tar -xzvf wget-1.9.1.tar.gz
$ cd wget-1.9.1
$ ./configure
$ make
$ sudo make install

$ ln -s /usr/local/bin/wget /usr/bin/wget


Download the necessary packages.

We will do this from the command line using wget, but you can download it however you want and then transfer the files to the src folder we created earlier.

 

$ wget  http://promotionalpromos.com/mirrors/gnu/gnu/make/make-3.81.tar.gz
$ wget  http://sourceforge.net/projects/lame/files/lame/3.97/lame-3.97.tar.gz/download
$ wget  http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
$ wget  http://ffmpeg.org/releases/ffmpeg-0.5.tar.bz2
$ wget  http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz

$ wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download

Now that we have all our necessary stuff we will extract the packages that we downloaded so we can start installing them.


$ tar -xzvf make-3.81.tar.gz
$ tar -xzvf lame-3.97.tar.gz
$ tar -xzvf faad2-2.7.tar.gz
$ bunzip2 ffmpeg-0.5.tar.bz2
$ tar -xf ffmpeg-0.5.tar
$ bunzip2 ffmpeg-php-0.6.0.tbz2
$ tar -xf ffmpeg-php-0.6.0.tar

Installing make

$ cd /usr/local/src/make-3.81
$ ./configure
$ make
$ sudo make install

Installing lame

lame is an mp3 encoder. Since Flash video usually uses mp3 as its audio format and ffmpeg doesn't include and mp3 encoder you will need to install lame and tell ffmpeg to use it.

$ cd /usr/local/src/lame-3.97
$ ./configure
$ make
$ sudo make install

Installing faad

Quicktime videos use AAC as its audio codec, so to encode and decode in this format you will need to install faad and tell ffmpeg to use it.

$ cd /usr/local/src/faad2-2.7
$ ./configure
$ make
$ sudo make install

Installing ffmpeg

When configuring ffmpeg we need to tell it to use it as a shared library and to enable lame and faad (faad requires the --enable-gpl as well). This configuration worked well for me.

$ cd /usr/local/src/ffmpeg-0.5
$ ./configure --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad
$ make
$ sudo make install
$ sudo ln -s /usr/local/bin/ffmpeg /usr/bin/ffmpeg

Now from your terminal enter:

$ ffmpeg -version

You should get something similar to this:

FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-shared --enable-libmp3lame --enable-libfaad --enable-gpl
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 0 / 52.20. 0
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  built on Jul 24 2009 21:22:05, gcc: 4.0.1 (Apple Computer, Inc. build 5250)
FFmpeg 0.5
libavutil     49.15. 0 / 49.15. 0
libavcodec    52.20. 0 / 52.20. 0
libavformat   52.31. 0 / 52.31. 0
libavdevice   52. 1. 0 / 52. 1. 0

Congratulations! you have successfully installed ffmpeg! Check below for an example of how to execute commands to convert video from the terminal. You will be able to execute these same commands from within your php scripts with the exec() function.

Installing ffmpeg-php

If you want to have access to the functionality provided by ffmpeg-php you can go ahead and install it now. Heres how:

$ cd /usr/local/src/ffmpeg-php-0.6.0
$ phpize
$ ./configure --with-ffmpeg
$ make
$ sudo make install

Restart your server

$ sudo apachectl restart

Installing flvtool2

flvtool2 adds necessary meta data to your Flash videos to make them a more proper file and provide to flash player with information about the video.

$ cd /usr/local/src/flvtool2_1.0.5_rc6
$ ruby setup.rb config
$ ruby setup.rb setup
$ sudo ruby setup.rb install

Possible Problems

ffmpeg headers not found.

If while configuring ffmpeg-php you encounter this error, which should hopefully not happen when working with these versions, the problem lies with ffmpeg-php looking in '/usr/local/include/ffmpeg/' instead of '/usr/local/include/'. To fix this try this:

$ cp /usr/local/include/libavcodec/* /usr/local/include/ffmpeg
$ cp /usr/local/include/libavdevice/* /usr/local/include/ffmpeg
$ cp /usr/local/include/libavformat/* /usr/local/include/ffmpeg
$ cp /usr/local/include/libavutil/* /usr/local/include/ffmpeg
$ cp /usr/local/include/libswscale/* /usr/local/include/ffmpeg


unkown token near ('ffmpeg,' )

If you get this error it lies with a compatibility issue with the ffmpeg-php compilers between new and old versions of php. The problem is with the configure script trying to load an extension which is no longer used in php. to fix it:

$ cd /usr/local/src/ffmpeg-0.6.0
$ vim config.m4 +/PHP_ADD_EXTENSION_DEP

add 'dnl' without the quotes (stands for 'do not load') before and save and try again. this should fix it.

Note: These problems only existed when my systems recognition of the php and phpize binaries and php-config weren't set correctly. When I removed all components to try the install again from scratch everything worked fine with no errors during configure, make or make install of any step of this entire procedure.

Also make sure that you get a copy of lame 3.97. When I tried it with 3.98 I would get an audio conversion error when converting my videos to flash. The only problem I saw with the files that where output was that they would not tell the browser to total length of the file and therefor the video progress bar wasn't functional.

ffmpeg conversion example

I will give you an example of a basic conversion command. Put a video on your desktop. We are going to tell ffmpeg to convert this video into a flash video format and then pipe it through flvtool2 to add the meta data. For an explanation of these commands run 'man ffmpeg' from terminal.

$ ffmpeg -i /Users/your~username/Desktop/moviename.ext -s 320x240 -sameq -ab 32000 -ar 22050 -f flv /Users/your~username/Desktop/moviename.flv | flvtool2 -U /Users/your~username/Desktop/moviename.flv

Have fun!

"ffmpeg installation on Mac OSX" Comments

From MacJoomla on Mar 25, 2010
Thank you very much for this cool step by step manual. Even me was able to get it to work with OS x 10.5 after reading or better in copying and pasting ;-) Just two little remarks to make it even better: In "Download the necessary packages" there is not listed how to download and extract "flvtool2" and "Installing ffmpeg-php" worked for me using "./configure --with-fmpeg " instead of just "configure --with-fmpeg". Maybe two steps after this it is a good idea to use "sudo make install" instead of just "make install"…? However, thanks again :-) MacJoomla
From ericopter on Mar 28, 2010
Thanks MacJoomla, I will fix that up. I have actually been reworking this article a bit and will add those updates
From FlashMan on May 4, 2010
I did the prerequisites and pointed it to my MAMP folder but I get this error when I phpize in the ffmpeg-php folder: grep: /Applications/MAMP/bin/php5/include/php/main/php.h: No such file or directory grep: /Applications/MAMP/bin/php5/include/php/Zend/zend_modules.h: No such file or directory grep: /Applications/MAMP/bin/php5/include/php/Zend/zend_extensions.h: No such file or directory Configuring for: PHP Api Version: Zend Module Api No: Zend Extension Api No: Please help somebody
From Paul on May 5, 2010
having problems with ffmpeg-php on snow leopard. getting the following error when running make: /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c -fno-common -DPIC -o .libs/ffmpeg_frame.o /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function ‘zim_ffmpeg_frame_toGDImage’: /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function) /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: (Each undeclared identifier is reported only once /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: for each function it appears in.) /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function ‘zim_ffmpeg_frame_ffmpeg_frame’: /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:421: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function) make: *** [ffmpeg_frame.lo] Error 1
From ericopter on May 7, 2010
Flashman: When using mamp, you have to make sure all your command line PHPs(php, phpize and php-config), which are usually located in /usr/bin are pointing to their respective counter parts in the mamp distro. I would assume they would be in /Applications/MAMP/bin, but I dont use mamp, I use a custom Apache PHP install. give me some more info and Maybe I can help you out. Paul: I need more info. What stage are you at, what command did you run, maybe I can help you figure it out. WHen I did this for the first time i spent ALOT of time on google searching errors and trying to figure stuff out. hopefully I can save you some time
From Xenus98 on Jun 16, 2010
With MacOSX 10.6.3 Snow leopard, you will not be able to compile FFMPEG correctly until you change "configure" flags. You have to configure with the flags "--arch=x86_64". So the full command line is : "./configure --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --arch=x86_64" Thanks a lot for the tutorial !!
From Xenus98 on Jun 16, 2010
FOR the ffmpeg-php to work on the Mac OS X, you need also to configure it that way : "sudo ./configure --with-ffmpeg --enable-skip-gd-check" It suppose that you have GD working with php.
From ericopter on Jun 17, 2010
Xenus98, thanks for your contributions. I appreciate added input from others who have made this work. I am going to be breaking this tutorial down into my article section, where I am going to post numerous articles on installing tons of stuff on your Mac. Hope you chime in there too!
From jazjai on Jul 8, 2010
Excellent tutorial . I downloaded each one to my downloads folder and clicked each one wher eit extracts itself. Then put each one on the desktop and moved to my src folder where I followed your steps. It took about 15 mins. Thank you so much.
From ericopter on Aug 13, 2010
Thanks, I'm, glad you enjoyed it. I have just gotten a new MacBook Pro with Snow Leopard and installed goodies on it, including the latest ffmpeg. I will be posting this in our article section in a couple of days.
From Internet Casino on Sep 27, 2010
I should digg your article so more people can see it, very helpful, I had a tough time finding the results searching on the web, thanks. - Norman
From Private Krankenversicherung Vergleich on Oct 1, 2010
You made a few excellent points there. I did a search on the topic and almost not got any specific details on other websites, but then happy to be here, seriously, appreciate that. - Lucas

Login/Register to leave a comment

Log In to Your Account
Don't have an account? Register