ScaleScaleScaleScale

Tips / Nginx


How to Install ffmpeg + php-ffmpeg on CentOS 6 / 7

FFMPEG is a fantastic tool if you’re developing a video content-based website like YouTube, Vimeo, or any other website that relies on uploaded videos. FFMPEG allows developers to decode, encode, transcode, mux, demux, stream, filter and play almost any kind of video ever created. It’s very compatible with old videos and also with the latest edge formats.

Main libraries included are: libavcodec, libavformat, libavutil, libavdevice, libavfilter, libswscale and libswresample. And of course, one of the most important tools you may need: the ffmpeg command line binaryused for multimedia files transcoding.

Today when covering the installation of ffmpeg and the php-ffmpeg module on CentOS 6 and 7, we will use the ATRPMS & REMI repositories. These are stable repositories that allow you to have the latest versions of the ffmpeg & php-ffmpeg packages. With that said, let’s begin.

Requirements

  • CentOS 6 or 7, with full root access.

Import the GPG key from the repo:

rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms

Install the ATRPMS Repo:

rpm -ivh http://dl.atrpms.net/all/atrpms-repo-6-7.el6.x86_64.rpm

The output should be something like:

[root@nginxtips.com:~]rpm -ivh http://dl.atrpms.net/all/atrpms-repo-6-7.el6.x86_64.rpm
Retrieving http://dl.atrpms.net/all/atrpms-repo-6-7.el6.x86_64.rpm
Preparing...                ##################################### [100%]
   1:atrpms-repo            ##################################### [100%]

Install FFMpeg from ATRPMS Repository:

yum -y --enablerepo=atrpms install ffmpeg ffmpeg-devel

Output:

[root@nginxtips.com:~]yum --enablerepo=atrpms install ffmpeg ffmpeg-devel
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
.....
.....
.....
===============================================
 Package         Arch               Version        Repository  Size
===============================================
Installing:

 ffmpeg          x86_64             2.2.1-65.el6    atrpms      2.6 M
 ffmpeg-devel    x86_64             2.2.1-65.el6    atrpms      5.7 M
.....
.....
.....

How to check if FFMPEG is working?

Verify the ffmpeg version:

ffmpeg -version
[root@nginxtips.com:~]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

Check the supported formats:

ffmpeg -formats

Test converting videos. Here’s an example from mp4 to h264:

cd /usr/local/src
wget https://archive.org/download/WoodstockFestivalTrailer/Woodstock_Festival_Trailer.avi
ffmpeg -i Woodstock_Festival_Trailer.avi -vcodec libx264 Woodstock_Festival_Trailer-H264.avi

After done, you should see the new H264 file:

-rw-r--r-- 1 root root 20M May 4 2006 Woodstock_Festival_Trailer.avi
-rw-r--r-- 1 root root 15M Jan 30 10:01 Woodstock_Festival_Trailer-H264.avi

How can I work with ffmpeg using PHP?

Simple.  Just install php-ffmpeg extension. First, install REMI repo in order to get your php-ffmpeg package, then type:

yum install php-ffmpeg

Verify ffmpeg is loading from PHP:

php -i | grep ffmpeg -i

If you see this, it’s working:

[root@nginxtips.com:~]php -i | grep ffmpeg -i
/etc/php.d/ffmpeg.ini,
ffmpeg
ffmpeg-php version => 0.7.0
ffmpeg-php built on => Jan  1 2013 09:50:55
ffmpeg-php gd support  => enabled
ffmpeg libavcodec version => Lavc53.61.100
ffmpeg libavcodec license => GPL version 3 or later
ffmpeg libavformat version => Lavf53.32.100
ffmpeg libavformat license => GPL version 3 or later
ffmpeg swscaler version => SwS2.1.100
ffmpeg swscaler license => GPL version 3 or later

If you want to learn more, check out the ffmpeg official website.

Popular search terms:

  • ffmpeg centos 7
  • centos7 ffmpeg
  • https://www scalescale com/tips/nginx/ffmpeg-php-ffmpeg-centos-6-7/#
  • Centos 7 libav
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Ertem Yazıcı

    great article for linux noobs like :=).

    Installation and running both ffmpeg and ffmpeg-php ha no problem.

    a small note that you can download latest(i hope) ATRPMS repo from here for centOs 7:
    http://dl.atrpms.net/all/atrpms-repo-7-7.el7.x86_64.rpm

  • Wasif Tanveer

    Hello,

    thank you very much for this tutorial really helped me installing the ffmpeg on centos 7

    Thanks alot 🙂

  • thank you so much for this tut.i use nano 😛 i dont understand vi :-s

  • Narendran Gopalakrishnan
  • Nirjonadda

    [root@na ~]# yum install php-ffmpeg
    Loaded plugins: fastestmirror, tsflags, universal-hooks
    Loading mirror speeds from cached hostfile
    * EA4: 185.69.232.245
    * base: mirrors.coreix.net
    * epel: mirror.math.princeton.edu
    * extras: mirrors.coreix.net
    * updates: mirrors.coreix.net
    No package php-ffmpeg available.
    Error: Nothing to do
    [root@na ~]#

    Cannot install php-ffmpeg extension, Please let me know that how to install php-ffmpeg extension?

  • Sérgio Soares

    Got it working! Thanks how can I update to the latest version of ffmpeg?

  • Nirjonadda

    How To Install FFmpeg and FFmpeg-PHP Extension on CentOS 7?