Setting Up FFMPEG and FFMPEG-PHP on CentOS 5 & 6
This guide provides two straightforward methods to install FFMPEG and its PHP extension, FFMPEG-PHP, on CentOS 5 and 6 servers. FFMPEG is a powerful tool for handling multimedia files, and FFMPEG-PHP allows your PHP applications to interact with FFMPEG.
METHOD 1: USING THE INSTALLER SCRIPT
This method uses a pre-made script to automate most of the installation process.
DOWNLOAD AND RUN THE SCRIPT
First, download the installer script:
wget http://9xhost.net/scripts/ffmpeg.sh
Then, run the script:
sh ffmpeg.sh
CONFIGURE PHP
After the script finishes, you'll need to enable the FFMPEG-PHP extension in your PHP configuration. The script's output will show you the path where the PHP extension was installed, typically something like /usr/local/lib/php/extensions/no-debug-non-zts-20060613/.
Open your php.ini file for editing:
nano /usr/local/lib/php.ini
Add the following line at the end of the file to enable the extension:
extension="ffmpeg.so"
RESTART APACHE
For the changes to take effect, restart your Apache web server:
/scripts/restartsrv_httpd
VERIFY INSTALLATION
You can confirm that FFMPEG-PHP is working by checking your PHP information.
From the command line:
php -i | grep ffmpeg
This should display details about the FFMPEG and FFMPEG-PHP versions.
INSTALLATION PATHS
FFMPEG itself is typically installed at:
/usr/bin/ffmpeg
EXCLUDE FROM YUM UPDATES
To prevent potential conflicts with future system updates, it's recommended to exclude FFMPEG packages from Yum updates.
Open the yum.conf file:
nano /etc/yum.conf
Add ffmpeg*
to the exclude
line. If an exclude
line doesn't exist, create it.
METHOD 2: MANUAL INSTALLATION VIA YUM AND COMPILATION
This method involves adding a repository, installing FFMPEG via Yum, and then compiling FFMPEG-PHP.
ADD DAG REPOSITORY
Create and open a new repository file:
nano /etc/yum.repos.d/dag.repo
Add the following content to the file:
[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
Import the GPG key for the repository:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
INSTALL FFMPEG
Update your Yum packages:
yum update
Now, install FFMPEG and its development libraries:
yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc
PREPARING FFMPEG-PHP
Download the FFMPEG-PHP package:
wget http://downloads.sourceforge.net/ffmpeg-php/ffmpeg-php-0.6.0.tbz2
Untar the downloaded package:
tar xjf ffmpeg-php-0.6.0.tbz2
Navigate into the extracted directory:
cd ffmpeg-php-0.6.0
Apply a necessary patch for compatibility:
sed -i 's/PIX_FMT_RGBA32/PIX_FMT_RGB32/g' ffmpeg_frame.c
Prepare for compilation:
phpize
Configure the build:
./configure
Compile the extension:
make
Install the extension:
make install
The output of make install will show you the PHP extensions path, for example:
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
CONFIGURE PHP
Edit your php.ini file:
nano /usr/local/lib/php.ini
Ensure extension_dir is set to the path identified by make install:
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
Add the following line directly below extension_dir to enable the FFMPEG-PHP extension:
extension="ffmpeg.so"
RESTART APACHE
Restart your Apache web server for changes to take effect:
/scripts/restartsrv_httpd
VERIFY INSTALLATION
Confirm FFMPEG-PHP is working from the command line:
php -i | grep ffmpeg
This should display FFMPEG and FFMPEG-PHP version information.
INSTALLATION PATHS
FFMPEG itself is typically installed at:
/usr/bin/ffmpeg
EXCLUDE FROM YUM UPDATES
To prevent potential conflicts, exclude FFMPEG packages from Yum updates.
Open the yum.conf file:
nano /etc/yum.conf
Add ffmpeg*
to the exclude
line.
TROUBLESHOOTING: 'list_entry' UNDECLARED ERROR
If you encounter an error during compilation similar to:
error: 'list_entry' undeclared
This usually indicates a compatibility issue between the FFMPEG-PHP version and your PHP version. The provided sed
command (sed -i 's/PIX_FMT_RGBA32/PIX_FMT_RGB32/g' ffmpeg_frame.c
) addresses one common issue, but newer PHP versions might require more extensive patches or a newer FFMPEG-PHP version. Consider searching for specific patches for your PHP version (e.g., "ffmpeg-php PHP 5.3 patch") or looking for a more updated FFMPEG-PHP release.
No comments:
Post a Comment