FFmpeg is an amazing collection of open-source tools that can record and stream video and audio. However, it can also transcode video and audio (convert the files to different formats), and that is what has me so excited. There’s also a great PHP package called ffmpeg-php that allows for easy use of FFmpeg from inside PHP scripts. Today, I’m going to see if I can’t help you get both of these set up on your system.
Admittedly, it’s been a while since I’ve tried to install FFmpeg, about two years. I recently thought up some ideas on how I’d like to use FFmpeg, so I thought it was time to give it a try yet again. Today, I’m proud to say that installing FFmpeg is so much easier to install compared to the past, that I dare say it’s simple.
Here is my experience with installing FFmpeg on my server and how to fix the pitfalls that I encountered.
Note that I did all the following steps on a CentOS server. The specific version is CentOS x64 5.2.
These instructions can work for other distros with little or no modifications, but some distros will be completely different. For example, the DAG RPM Repository that I’m using (more info below) has support for the following distros: Red Hat Enterprise Linux, Fedora Core, Yellow Dog Linux, Aurora Linux, CentOS, Scientific Linux (they really need to get a verified SSL cert), TaoLinux, WhiteBox Linux, Lineox, and BLAG. Other distros will need to use a different repository.
If you successfully get FFmpeg running on another distro, please comment your changes here and I’ll update the post (and make sure you get credit of course).
Also note that I experienced some bumps in the road while installing everything. While many of you may not experience these issues, I found it important to document these problems and how I fixed them in case you encounter them.
The first thing that you need to do is set up the DAG repository. This repository is an actively-maintained repository that provides a staggering number of packages with current or near current builds. Adding this repository is a great way to run the latest offerings of many packages.
Adding the DAG repository is simple. I’m using yum, so I did the following to add the repository:
- Create and open a new file called /etc/yum.repos.d/dag.repo. I ran “
- Add the following text to the file:
name=DAG RPM Repository
- Finally, save and close the file.
In order to successfully use the DAG repository with tools such as yum, you need to add DAG’s GPG key. Failure to do so will result in an error like the following:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Public key for faac.x86_64.1.26-1.el5.rf.rpm is not installed
In order to add the GPG key for DAG, run the following:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
The DAG: Frequently Asked Questions page has additional instructions on how to get the repository loaded and working on your distro.
Now that DAG is setup, it’s a good idea to update all your packages.
Depending on the packages you currently have installed, this could potentially upgrade, install, or replace numerous packages that may or may not be very important to you. Make sure you carefully look through that list and do any necessary preparations before telling yum that it can go ahead.
For example, yum told me that it was going to replace my current MySQL interface library for Perl with a new one. I added to my check list a note to verify that my Perl code functioned correctly after the install.
I ran into another hitch when I told yum to go ahead with the update. It informed me that my current version of Subversion conflicted with the new version it wanted to install. When this happens, you need to remove the old package before proceeding. This time, I made backups of all of my repositories and my /etc/sysconfig/svnserve file before proceeding just in case. I then removed Subversion “
yum remove subversion“, ran the update process “
yum update“, and installed Subversion again “
yum install subversion“.
Installing – FFmpeg
Now you are ready to install FFmpeg with yum. I wanted to install all the available FFmpeg packages, so I first asked yum what was available.
yum search ffmpeg
Searching through the results, I found that three packages need to be installed: ffmpeg, ffmpeg-devel, and ffmpeg-libpostproc.
yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc
Note: If you install ffmpeg-libpostproc, the entire FFmpeg software library changes from the LGPL license to the GPL license.
After a couple of minutes, the packages and the packages that they depend on were installed.
I simply ran “
ffmpeg” from the command line, and I took the lack of threatening error or warning messages as a good sign that things were working.
Preparing for ffmpeg-php
I often work with programs through command line calls in code, but I wanted something more robust this time, so I looked around and found ffmpeg-php. Based on the API, it looks to be a great tool to interface PHP and FFmpeg.
There are four things that are required to successfully install and run ffmpeg-php; they are:
- ffmpeg-0.4.9_pre1 or higher
- php-4.3.0 or higher
- gd-2.0 or higher
PHP and FFmpeg should be good to go since at the time of this writing, DAG has PHP version 5.1.6 and FFmpeg version 0.4.9. GD and php-devel can be easily installed by running the following yum command:
yum install php-gd php-devel
In case you are wondering what php-devel is for, it installs the phpize program which is used to install ffmpeg-php.
Now we are ready to install ffmpeg-php. This can be done in six easy steps:
- Download the latest ffmpeg-php release
- Extract the archive:
tar -xjf ffmpeg-php-X.x.x.tbz2
./configure && make
sudo make install
This may seem like a lot of work when I earlier described this process as “simple,” but trust me that this is a thousand times easier than when I first tried installing FFmpeg. I think I spent three hours working on installing FFmpeg just to find out that it didn’t work the first time I tried.
Time and time again, package management has proven to be an extremely powerful tool. While I know the value of manually configuring and compiling code, the ease of simply using a package manager can reduce the time needed to install and manage software from hours or days to minutes.
I’m glad to see that FFmpeg has benefited from the use of these package managers and great repositories like the DAG RPM Repository.
Did I help you?