FFmpeg is a cross-platform solution for streaming audio and video as well as recording and conversion. There’s also a great PHP package called ffmpeg-php that allows for easy use of FFmpeg from inside PHP scripts. In this tutorial we will learn Install FFmpeg and FFmpeg-PHP Extension on CentOS server.
Install FFmpeg on CentOS
Step 1. To install, first you must add the DAG yum repository information corresponding to your CentOS/RHEL version to yum:
#nano /etc/yum.repos.d/dag.repo
Add the following text to the file and save:
[dag] name=DAG RPM Repository baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag gpgcheck=1 enabled=1
Step 2. After add Dag repository, Use yum to install ffmpeg using following command.
#<code>rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt #yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc
FFmpeg Basic Commands
#ffmpeg -version: show version #ffmpeg -formats: show available formats #ffmpeg -codecs: show available codecs #ffmpeg -decoders: show available decoders #ffmpeg -encoders: show available encoders #ffmpeg -bsfs: show available bit stream filters #ffmpeg -protocols: show available protocols #ffmpeg -pix_fmts: show available pixel formats #ffmpeg -layouts: show standard channel layouts #ffmpeg -sample_fmts: show available audio sample formats #ffmpeg -filters: show available filters
Install FFmpeg-PHP Extension on CentOS
Step 1.
#yum install php-gd php-devel
Step 2.Download the latest ffmpeg-php release
#wget http://nchc.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 #tar -xjf ffmpeg-php-0.6.0.tbz2 #cd ffmpeg-php-0.6.0 #phpize #./configure #make #make install
If you get [ffmpeg_movie.lo] Error 1 when compiling ffmpeg-php, then you will need to do:
#nano ffmpeg_movie.c Changes in ffmpeg_movie.c: #row 311: list_entry *le; to zend_rsrc_list_entry *le; #row 346: list_entry new_le; to zend_rsrc_list_entry new_le; #row 360: hashkey_length+1, (void *)&new_le, sizeof(list_entry), to hashkey_length+1, (void *)&new_le,sizeof(zend_rsrc_list_entry),
Step 3. Copy the ffmpeg.so module in php default module location. Now you have to edit php.ini file to enable ffmpeg-php support in it by using ffmpeg.so module.
#nano /etc/php.ini
Put the below two lines at the end of the php.ini file
[ffmpeg] extension=ffmpeg.so
FFmpeg-PHP extension should now be installed. You can check by creating a file called info.php in /var/www/html/ with the following content:
<?php phpinfo(); ?>