How to install FFmpeg + PHP-FFmpeg on cPanel

FFmpeg is a popular video and audio converter/processing library, along with the PHP-FFmpeg extension can help you to build powerful video web apps within minutes. FFmpeg can also convert multimedia on the fly and apply powerful filters to your audio and video files.

Important: this method should work for plain CentOS 6.x and 7.x without cPanel, you just have to edit the correct php.ini file (usually located at /etc/php.ini) while loading the php-ffmpeg extension

Install FFmpeg and the PHP-FFmpeg extension

Sometimes this installation process may be difficult or you may find lot of errors while compiling if you are using source code, however we will use rpm files for the ffmpeg installation and will compile only the php-ffmpeg extension. Let’s begin.

Install the Dag repo

Create a new file called dag.repo inside yum repositories:

nano -w /etc/yum.repos/dag.repo

Paste this inside exactly as you see it:

[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

Import Dag’s GPG key

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

Install package libdc1394:

yum install libdc1394-devel

Install ffmpeg and ffmpeg-devel packages:

yum -y install ffmpeg ffmpeg-devel

Test FFMPEG

You should see this kind of output:

[root@server:~]ffmpeg -version
ffmpeg version 2.2.1
built on Apr 13 2014 13:00:18 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-pthreads --enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --disable-stripping
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100

Now let’s begin with php-ffmpeg extension, which will allow you to manipulate video and audio via PHP programming laguage:

Backup your current php.ini file

cp /usr/local/lib/php.ini /usr/local/lib/php.ini.backup

Install Git

yum -y install git

Download and compile

cd /root/
git clone https://github.com/tony2001/ffmpeg-php.git
cd ffmpeg-php
phpize
./configure
make
make install

Edit your php.ini

nano -w /usr/local/lib/php.ini

At the end of the file, add the extension so PHP can load it:

extension="ffmpeg.so"

Save your file and restart httpd to apply changes:

service httpd restart

Test it:

php -i | grep ffmpeg

That should give you a big output like this:

[root@server:~]php -i | grep ffmpeg
ffmpeg
ffmpeg-php version => 0.7.0
ffmpeg-php built on => Aug 4 2015 23:38:38
ffmpeg-php gd support => disabled
ffmpeg libavcodec version => Lavc55.52.102
ffmpeg libavcodec license => GPL version 3 or later
ffmpeg libavformat version => Lavf55.33.100
ffmpeg libavformat license => GPL version 3 or later
ffmpeg swscaler version => SwS2.5.102
ffmpeg swscaler license => GPL version 3 or later

How can I convert a video file?

It’s pretty easy in fact, just like this:

$ ffmpeg -i input.mp4 output.avi

 

Further reading:

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

15 Comments

  1. This looks pretty good, however, cpanel best practices dictate that you should never edit the php.ini file directly because it will get overwritten on the next easyapache run, so ideally adding the extension should be done via the whm option under advanced php configuration as that will stick on further builds.

    Pretty nice share otherwise.

  2. right from the 1st instruction i get unable to conect to host
    ive been having a nightmare of a time trying to get ffmpeg working again, it used to work before cpanel updated

  3. after installing then i try to verify and there is showing that error ” ffmpeg not found “

  4. Please can you let me know that How To Install FFmpeg and FFmpeg-PHP Extension on CentOS 7 with cPanel EA4?

Leave a Reply

Your email address will not be published. Required fields are marked *