FFmpeg is a set of free and open-source libraries that allow you to record, convert and stream digital audio and video in various formats. It includes libavcodec, a library for encoding and decoding audio and video, and libavformat, a library for multiplexing and demultiplexing into a media container. The name comes from the name of the MPEG Expert Group and FF, meaning Fast Forward.

Debian

# apt-get install ffmpeg

Install ffmpeg module for PHP:

# apt-get install php5-ffmpeg

After installation you need to restart Apache and check if the ffmpeg module is plugged in:

# /etc/init.d/apache2 restart
# php -i | grep ffmpeg
/etc/php5/cli/conf.d/20-ffmpeg.ini,
ffmpeg  
ffmpeg-php version => 0.6.0-svn  
ffmpeg-php built on => Apr 6 2012 16:24:10  
ffmpeg-php gd support => enabled  
ffmpeg libavcodec version => Lavc53.35.0  
ffmpeg libavformat version => Lavf53.21.0  
ffmpeg swscaler version => SwS2.1.0  
ffmpeg.allow_persistent => 0 => 0  
ffmpeg.show_warnings => 0 => 0  

Centos

Import and install repositories:

# rpm -ivh https://www.mirrorservice.org/sites/dl.atrpms.net/el7-x86_64/atrpms/stable/atrpms-repo-7-7.el7.x86_64.rpm

Let's edit them:

# vi /etc/yum.repos.d/atrpms.repo

We make it look like this:

#baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
baseurl=https://www.mirrorservice.org/sites/dl.atrpms.net/el$releasever-$basearch/atrpms/stable  

Installing FFmpeg:

# yum install ffmpeg ffmpeg-compat ffmpeg-compat-devel ffmpeg-devel ffmpeg-libs

Installing php-ffmpeg

Install git and download the sources for the ffmpeg-php extension:

# yum install git
# git clone https://github.com/tony2001/ffmpeg-php.git

(or you can just go to https://github.com/tony2001/ffmpeg-php and download the zip file archive of this repository on the right, then unzip and assemble it).

Install the php extension builder package

# yum install php-devel gcc

Copy and install the extension:

# cd ffmpeg-php
# phpize
# ./configure
# make && make install

Edit the php.ini file:

# vim /etc/php.d/ffmpeg.ini

Add the line:

extension=ffmpeg.so  

Save the file:

:wq!

Check if the ffmpeg module is plugged in and restart apache

# php -i | grep ffmpeg
ffmpeg  

Centos 7

# systemctl restart httpd
Updated Oct. 23, 2018