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?
I’ve been looking for an easy to follow tutorial. Thanks so much!
I’m glad that I was able to help Charles.
Nice tutorial! I used nano in the first step, since I couldn’t figure out how to save the file 😛 So, you might add a comment on that 🙂
I think I’ll do a vim tutorial in the future and link to that in case people need help.
As a quick tutorial, you start editing in vim by pressing the ‘i’ key. When you are done editing, press ESC and type ‘:wq’ followed by Enter. The ‘:wq’ command tells vim to write to the file and then quit.
A tutorial on vi may not be the best idea — as those who can learn vi will have by now. It was old and clunky 20 years ago, and is really non-intuitive unless one is forced, clockwork-orange-style, to use it until colon-bang actually makes sense. VI, as the creator says, “was made for a world that doesn’t exist any more”.
You may want to leave that one product-neutral or consider nano as the editor in your demo — something simple. It’s quite a lot easier to use, at least in the opinion of a guy who’s cursed at vi’s ridiculous UI for yeah, 20 years now.
Great tutorial, i wish all linux tutorials on the web were just like this one.
Thanks for your great job which helps a lot of people like me. Save us a bunch of time to struggling around.
I’m glad to be of help Andy.
Awesome tutorial. Thanks for the walkthrough!!
Glad to be of help Alex.
Its working .. haha. Thanks chris.. i dint find a better tutorial for installing ffmpeg than yours. sure i will donate you.. wait..
I’m glad it worked well for you prathap.
I’d be honored if you donated. You’d be the third. 🙂
please wait for september 30. at that day you will get payment..thanks.. thanks.. 🙂
great tutorial thanks!
when I do this
rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
it hangs and just sits there.. any ideas??
I fixed this by setting
then did yum install ffmpeg
no GPG check so it works….
I also take lack of errors on command line ‘ffmpeg’ to be a good sign that it worked.
I’m glad that you got it fixed. Thanks for sharing the solution Mike.
When I run:
./configure && make
I get the fololowing errors:
./configure: line 4062: syntax error near unexpected token `ffmpeg,’
./configure: line 4062: ` PHP_ADD_EXTENSION_DEP(ffmpeg, gd)’
It looks like GD isn’t installed on your system. Did you confirm that the php-gd package installed as instructed in the “Preparing for ffmpeg-php” section?
Hi i tried to install ffmpeg-php
when am configuring by this
it throws this message
checking for egrep… grep -E
checking for a sed that does not truncate output… //bin/sed
checking for gcc… no
checking for cc… no
checking for cc… no
checking for cl… no
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details.
And config.log i cant understand whats the problem. Please solve me this
It means just what the output is saying: your system does not have a c compiler. Notice the gcc, cc, and cl listings with “no” next to them. That means that the code is looking for a program with one of those names, and it can’t find one.
If you are on shared hosting, you probably won’t be able to use an existing compiler or add a compiler. Most shared hosting doesn’t want you to compile code on their server as the CPU load is very high.
If you are not on shared hosting and have access to root, installing can be done quickly by using a package manager. On CentOS as root, run “yum install gcc”.
thanks a lot. i found that and installed
i solved by installing make and gss commands using yum
yum install make
yum install gcc
Thanks for the tutorial – got it up and running on a centos box lickity split 🙂
[…] this article, you need to compile and install ffmpeg-php manually having installed some of the packages you just […]
Hi Chris, the GPG call you list in this article did not work for me. I went to Dag Wieer’s site a found the current URL.
It should read…
rpm –import http://apt.sw.be/RPM-GPG-KEY.dag.txt
Thank you for your help. It allowed me to install FFmpeg and I am very grateful.
It looks like a redirect is there now, but I went ahead and updated the link. Thanks for the info.
I get the following errors when trying to install ffmpeg-php
It’s been a couple of years since I’ve written this guide, so things may have changed since I last did this.
Digging around a bit on your messages, it looks like either the ffmpeg or ffmpeg-devel package haven’t been installed or weren’t installed properly. Go back and make sure that those two packages are installed and are functional.
If everything looks good with those packages, I’m sorry to say that I really don’t know what the problem would be.
[…] If you fancy, you can try the RPM version of this Chris Jean has an article. […]
Running Centos 6.2 – X86_64
Did all of the instructions that you mentioned and get the following error:-
[root@vps ffmpeg-php-0.6.0]# make
/bin/sh /root/downloads/ffmpeg-php-0.6.0/libtool –mode=compile cc -I. -I/root/downloads/ffmpeg-php-0.6.0 -DPHP_ATOM_INC -I/root/downloads/ffmpeg-php-0.6.0/include -I/root/downloads/ffmpeg-php-0.6.0/main -I/root/downloads/ffmpeg-php-0.6.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/libavcodec/ -I/usr/include/libavformat/ -I/usr/include/libavutil/ -I/usr/include/libswscale/ -I/usr/include/libavfilter/ -I/usr/include/libavdevice/ -DHAVE_CONFIG_H -g -O2 -Wall -fno-strict-aliasing -c /root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c -o ffmpeg_frame.lo
libtool: compile: cc -I. -I/root/downloads/ffmpeg-php-0.6.0 -DPHP_ATOM_INC -I/root/downloads/ffmpeg-php-0.6.0/include -I/root/downloads/ffmpeg-php-0.6.0/main -I/root/downloads/ffmpeg-php-0.6.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/libavcodec/ -I/usr/include/libavformat/ -I/usr/include/libavutil/ -I/usr/include/libswscale/ -I/usr/include/libavfilter/ -I/usr/include/libavdevice/ -DHAVE_CONFIG_H -g -O2 -Wall -fno-strict-aliasing -c /root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c -fPIC -DPIC -o .libs/ffmpeg_frame.o
/root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function ‘zim_ffmpeg_frame_toGDImage’:
/root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function)
/root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: (Each undeclared identifier is reported only once
/root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: for each function it appears in.)
/root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function ‘zim_ffmpeg_frame_ffmpeg_frame’:
/root/downloads/ffmpeg-php-0.6.0/ffmpeg_frame.c:421: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function)
make: *** [ffmpeg_frame.lo] Error 1
I have found the solution on another site:-
If you get the following error when running the command make to compile FFmpeg:
make: *** [ffmpeg_frame.lo] Error 1
In the version 0.6.0 of ffmpeg-php you will need to modify the file: ffmpeg_frame.c and replace every instance of PIX_FMT_RGBA32 with PIX_FMT_RGB32
Using Linux text editor, vi run the following commands:
# vi ffmpeg_frame.c
[…] ffmpeg-php extension. As it doesn't exist in rpm package, you should compile it from sources. Read this howto to see what you have to do […]
[…] production should use dedicated. Isn't rocket science to install. You can do it yourself even: http://chrisjean.com/2009/01/13/inst…centos-easily/ __________________ Experienced and efficient LAMP development. PHP – MySQL – XML – XHTML – CSS – […]
Thank you , you are a life saver
I just uploaded fixed version of php-ffmpeg on github.
all bugs fixed and it’s compatible with latest ffmpeg version.
Thank you do much Kotso!!!
Only your version did the trick. I search tones of articles many many hours.. Just nothing for latest Centos 7 on Plesk 12.5.
I didn’t got to ./configure && make && install because of error “no permissions for ./configure” but just copied the file “ffmpeg.so” from modules folder to “/usr/lib64/php/modules” and after just included extesion via command echo -e “extension=ffmpeg.so\n” > /etc/php.d/ffmpeg.ini and finally restarted the server (restarting only the apache didn’t included it in php info, I don’t know why).
show this error
[york]$ sudo make install
[sudo] password for preet94173:
preet94173 is not in the sudoers file. This incident will be reported.
You’ll need to give your user sudo privileges or login in as root and use the same commands without the
sudoportion of the command. For instance, “
sudo make install” would become “
make install“. Just make sure when you switch users that you are in the correct directory.
You can find instructions on both setting up sudo and switching to root on CentOS here.
I finally found a solution which allows to install ffmpeg in Centos 7:
1. wget ftp://rpmfind.net/linux/centos/6.5/os/x86_64/Packages/libdc1394-2.1.2-3.4.el6.x86_64.rpm
2. yum -y localinstall libdc1394-2.1.2-3.4.el6.x86_64.rpm
3. rpm -ivh http://dl.atrpms.net/el7-x86_64/atrpms/stable/atrpms-repo-7-7.el7.x86_64.rpm
4. yum -y install ffmpeg
I hope it will help somebody.
Thank you so much, you saved my day! 🙂
thanks for this great tutorial however I’ve run into a problem…
This install of ffmpeg does work for converting a file to rtmp stream but if I try an rtmp stream as the input it doesn’t work, I get:’Closing connection: NetStream.Play.StreamNotFound’. Maybe I’m doing something wrong but I’ve tried many command variations, so I’m thinking maybe the version of ffmpeg you get from this tutorial doesn’t support rtmp as the input stream. Can anyone shed light?
I don’t have any experience with working with RTMP streams or transcoding them. Hopefully someone reading the comments can help.
Great tutorial. Just be careful about the select right version of ffmpeg-php. The ffmpeg-php link is wrong, use this link
Thanks. I’ve updated the post.
Thank you for the post.
thank you so much brother. I install by doing as you mention. Superb.
Even after adding rpmforge, and dag repositories i still get the following error:
dag/7/x86_64/primary_db | 125 kB 00:02
Warning: No matches found for: ffmpeg
No matches found
can you please suggest what should i do in this case?
i followed the following tutorial that helped me installing ffmpeg on ceontos 7
hope it helps you guys too
I am not very vell in english language but i thank from you. your article is very helpful for me.
I think the dag repo is now out of date (september 2015) and is breaking systems. I followed these steps, 1) install dag repo, 2) yum update 3) reboot I get a kernel panic on the reboot and my system is completely hosed. This is with centos 6.7.
Oh, that’s brutal. When you’re running CentOS it’s important to keep all your repositories except the CentOS base set to ‘enable=0’ all the time, except when using yum for a specific package. And if you do leave multiple repositories enabled, then it’s important to install the priorities-plugin package for yum that lets you sent the CentOS to priority 1 and other repositories to lower priorities.
Sei que isso aqui não e´fórum, sou brasileiro, queria saber como faço isso! Porque já vi muitos tutorial, mas até o momento ainda não compreende muito. Eu não entendi isso [ Para utilizar com êxito o repositório DAG com ferramentas como o yum, você precisa adicionar chave GPG da DAG.]. Poderia me ajudar por favor! Ficaria grato se pude-se me ajudar.
The command to add the key follows shortly after that note. It the following:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt