There are many tutorials on how to install ffmpeg for cPanel. I will be combining one with my own modifications. Please submit modifications or corrections when necessary and I will update this post. The last update to this post was February 7th, 2012.
Some Prerequisites
There are a few things you’ll need to prepare if you’re on a fresh installation.
- Subversion
Subversion is required to download and install ffmpeg and mplayer. First, you need to allow yum to install Perl packages.
nano -w /etc/yum.conf
In the exclude= line, remove “perl*” – save (CTRL+O) and exit (CTRL+X).
yum install subversion
Be sure to add the perl* line back to /etc/yum.conf after you install subversion! This is to prevent yum from accidentally overwriting cPanel’s Perl modules.
- Git
Git is required because for some reason, when you install mplayer, it forces you to download a Git repository of ffmpeg. Don’t use this repository for installing ffmpeg – it breaks with a strange error message. How you install Git will vary across OSes. On CentOS 5.5 x64, there are several dependencies as well.
yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel
cd /usr/local/src
wget http://git-core.googlecode.com/files/git-1.7.7.tar.gz
tar -zxf git-1.7.7.tar.gz
cd git-1.7.7
make prefix=/usr/local all
make prefix=/usr/local install
- Ruby
Ruby is required for flvtool. You can install this using the cPanel script:
/scripts/installruby
If you’re not using cPanel, you can probably install this using your package manager.
- libXext
libXext is required for MP4Box. It’s in the yum repositories.
yum install libXext libXext-devel
- Remove any other installations
You might already have ffmpeg installed. If it was compiled in, that’s fine, this will overwrite it. But if you have RPM binaries installed, this will cause issues. Run the following:
rpm -qa | grep ffmpeg
rpm -qa | grep mplayer
rpm -qa | grep mencoder
rpm -qa | grep 264
Remove with rpm -e any libraries, common files, or binary installations of these packages to prevent conflicts.
Download All The Things
One note; the official distribution release of ffmpeg-php no longer compiles. The SVN version available here works, but the SVN tarball link here can’t easily be downloaded in a terminal session, so I’ve rehosted the file here on this server. This is not my file, I haven’t modified it, and I take no responsibility for it – it’s merely a copy of the file available from the above link.
- Let’s get started! This step can and probably should be copy/pasted into your terminal all in one block.
cd /usr/local/src
wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
tar zxf flvtool2-1.0.6.tgz
wget http://switch.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz
tar zxf lame-398-2.tar.gz
wget http://hasaninter.net/ffmpeg-php.tar.gz
tar xzf ffmpeg-php.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.3.tar.bz2
tar xjf libvorbis-1.2.3.tar.bz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.4.tar.gz
tar xzf libogg-1.1.4.tar.gz
wget http://sourceforge.net/projects/opencore-amr/files/opencore-amr/0.1.2/opencore-amr-0.1.2.tar.gz/download
tar xzf opencore-amr-0.1.2.tar.gz
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
tar xjf libtheora-1.1.1.tar.bz2
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar zxf xvidcore-1.3.2.tar.gz
wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
tar zxf faad2-2.7.tar.gz
wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
tar zxf faac-1.28.tar.gz
mkdir /usr/local/lib/codecs
wget ftp://ftp.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
tar xjf essential-20071007.tar.bz2
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar zxf yasm-1.2.0.tar.gz
cp /usr/local/src/essential-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
mkdir /usr/local/src/tmp
chmod 777 /usr/local/src/tmp
export TMPDIR=/usr/local/src/tmp
svn co https://gpac.svn.sourceforge.net/svnroot/gpac/trunk/gpac gpac
git clone git://git.videolan.org/x264.git
- Now it’s time to grab mplayer and ffmpeg, the latest versions possible.
git clone git://git.videolan.org/ffmpeg.git ffmpeg
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
Let’s Compile This Shit!
Alright, now we’re down to the good stuff – compilation! Hopefully if the above steps went correctly this will just fly by. However I do not recommend that you copy and paste the entire command tree into the terminal at this point. Run everything one step at a time to catch any errors if they do occur. Google is your friend, but feel free to leave a comment here if you run in to any problems.
- Lame
cd /usr/local/src/lame-398-2/
./configure
make
make install
- Libogg
cd /usr/local/src/libogg-1.1.4
./configure
make
make install
- Libvorbis
cd /usr/local/src/libvorbis-1.2.3
./configure
make
make install
- yasm
cd /usr/local/src/yasm-1.2.0
./configure
make
make install
- Libxvid
cd /usr/local/src/xvidcore/build/generic
./configure
make
make install
- Libx264
cd /usr/local/src/x264
./configure --enable-shared
make
make install
- Flvtool
cd /usr/local/src/flvtool2-1.0.6
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
- Opencore-amr
cd /usr/local/src/opencore-amr-0.1.2
./configure
make
make install
- Libtheora
cd /usr/local/src/libtheora-1.1.1
./configure
make
make install
- faad2
cd /usr/local/src/faad2-2.7
./configure
make
make install
- faac
cd /usr/local/src/faac-1.28
./configure
make
make install
- MP4Box
cd /usr/local/src/gpac
./configure
make
make install
- ldconfig
To make sure mplayer and ffmpeg install using the correct libs, we need to make sure ld knows where to find our libraries. First, check:
nano /etc/ld.so.conf
Make sure that this file contains the line:
/usr/local/lib
If you’re on a 64-bit system you should also add:
/usr/local/lib64
Save (CTRL+O), exit (CTRL+W), and then update:
ldconfig
If you run in to any “file not found” errors, it’s probably ldconfig.
- Mplayer – remember, this will download a new version of ffmpeg for some crazy reason. When it asks, just hit enter and allow it to download. It’s only used for compiling mplayer. We must use –yasm=” because we’ve switched from yasm to nasm and mplayer can’t deal with that.
cd /usr/local/src/mplayer/
./configure --enable-jpeg
make
make install
- FFMpeg
cd /usr/local/src/ffmpeg
./configure --enable-libmp3lame --enable-libvorbis --enable-shared --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-nonfree --enable-libtheora --enable-version3 --enable-gpl --enable-libxvid
make
make install
- FFMpeg-PHP – at this point you may receive an error message. To fix this error refer to the second code block.
cd /usr/local/src/ffmpeg-php
phpize
./configure
make
make install
nano -w ffmpeg_frame.c
CTRL+W CTRL+R PIX_FMT_RGBA32 [enter] PIX_FMT_RGB32
A
CTRL+O CTRL+X
What this does is replaces all instances of PIX_FMT_RGBA32 with PIX_FMT_RGB32, saves, and exits. This will happen after the “make” step – you will need to run “make” again, then “make install.”
- php.ini – All that’s left is to modify your php.ini file! Add the following near the top of the file /usr/local/lib/php.ini (to avoid conflicts)
extension=ffmpeg.so
- Restart Apache
/etc/init.d/httpd restart
That’s It!
At this point you should have a fully functional ffmpeg installation compiled in to PHP. You can test this with the following:
php -m | grep ffmpeg
You should get the output:
ffmpeg
Thank you very much to serverhostingsecrets.com for providing a very stable base for me to build this tutorial on!