CentOSLinuxTutorials

How To Install FFmpeg and FFmpeg-PHP Extension on CentOS

Install FFmpeg and FFmpeg-PHP Extension on CentOS

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.

Prerequisites

  • 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).
  • A non-root sudo user or 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.

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:

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

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 Install FFmpeg and FFmpeg-PHP Extension on CentOS

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),

Install FFmpeg on CentOS and FFmpeg-PHP Extension 

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.

#nano /etc/php.ini

Put the below two lines at the end of the php.ini file

[ffmpeg]
extension=ffmpeg.so

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();
?>

FFmpeg Install Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “FFmpeg” installation, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button