In this tutorial, we will show you how to install FFmpeg and FFmpeg-PHP extension on CentOS. For those of you who didn’t know, 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, I will show you the easy way to install FFmpeg and FFmpeg-PHP (PHP extension).
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges.
- A server running one of the following operating systems: CentOS or any other RHEL-based distribution.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Table of Contents
Install FFmpeg on CentOS
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo yum clean all sudo yum update sudo yum install php-gd php-devel
Step 2. To install, first you must add the DAG yum repository information corresponding to your CentOS/RHEL version to yum:
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
After adding the Dag repository, Use
yum to install FFmpeg using the following command.
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. 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),
Copy the FFmpeg.so module in PHP default module location. Now you have to edit
php.ini the file to enable FFmpeg-PHP support in it by using FFmpeg.so module.
Put the below two lines at the end of the php.ini file
The 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(); ?>