Install ffmpeg, ffmpeg-php

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. See the documentation for a complete feature list and the Changelog for recent changes.

FFmpeg is free software licensed under the LGPL or GPL depending on your choice of configuration options. If you use FFmpeg or its constituent libraries, you must adhere to the terms of the license in question. You can find basic compliance information and get licensing help on our license and legal considerations page.

Looking for help? Contact us, but before you report any bugs, read the guidelines that we created for this purpose.

Want to participate in the active development of FFmpeg? Keep up with the latest developments by subscribing to both the ffmpeg-devel and ffmpeg-cvslog lists.

 

Centos


Installing FFmpeg

FFmpeg can be installed fairly easily on the (dv) 3.5 and 4.0 servers, through use of the third-party DAG RPM Repository.

  1. Connect to your server as root.
  2. Create and edit a new file in /etc/yum.repos.d/ called dag.repoand add the following lines:/etc/yum.repos.d/dag.repo
    [dag]
    name=DAG RPM Repository
    baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
    gpgcheck=1
    enabled=1
  3. Next, run the following commands to import the CentOS GPG key, then download and import the DAG Repository GPG key:
    rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
    wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
    rpm --import RPM-GPG-KEY.dag.txt

    If you want to verify the keys have been properly installed, enter

    rpm -q gpg-pubkey-*

    Look for the following two gpg-pubkey entries from the command’s output:

    gpg-pubkey-e8562897-459f07a4 — CentOS 5 key

    gpg-pubkey-6b8d79e6-3f49313d — DAG Repository key

  4. Now that yum has been properly configured with a new RPM repo, we can get FFmpeg installed. First, we want to update the yum package list with all the new packages the DAG Repository offers:
    yum update
  5. Once yum has been updated with the new package list, we need to install ffmpeg and ffmpeg-devel:
    yum install ffmpeg ffmpeg-devel
  6. Sit back and relax while yum downloads and installs the required packages for FFmpeg, you are done!

Installing FFmpeg-PHP

Since we have to compile FFmpeg-php from source, make sure your (dv) server has the Developer Toolsinstalled.

  1. Connect to your server as root.
  2. Download the latest FFmpeg-php source code:
    wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download
  3. Run the following commands to unpack the archive and move into the ffmpeg-php directory:
    tar -xjf ffmpeg-php-0.6.0.tbz2
    cd ffmpeg-php-0.6.0

    There appear to be some coding mistakes in 0.6.0, and so you will need to edit the file ffmpeg_frame.c. To fix this, edit the ffmpeg_frame.c file in your favorite text editor, and replace all instances ofPIX_FMT_RGBA32 to read PIX_FMT_RGB32. If you do not do this, the extension will not work, and your Apache error log will have wonderful messages like these:

    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/ffmpeg.so’ – /usr/lib64/php/modules/ffmpeg.so: undefined symbol: _php_create_ffmpeg_frame in Unknown on line 0

  4. Once you have fixed up the ffmpeg_frame.cfile, run the following commands to compile and install the extension:
    phpize
    ./configure && make
    make install
  5. Edit the /etc/php.inifile in your favorite text editor, and add the following line to any blank area underneath the “[PHP]” line:/etc/php.ini
    extension=ffmpeg.so
  6. Now, just restart Apache:
    /etc/init.d/httpd restart
  7. If you want to make sure the extension is loaded and working, set up a PHP Info page, or copy test_ffmpeg.php and the contents of the tests/test_media/ directory into the document root of your website (normally httpdocs), then load test_ffmpeg.php from your browser.
  8. You are done!

 

Debian/ ubuntu

 


#sudo apt-get install build-essential

#sudo apt-get install ffmpeg

#sudo apt-get install php5-ffmpeg

Windows


Update

  1. Download compiled dlls from here: http://sergey89.ru/files/ffmpeg-php-win32-all.zip
  2. Extract and put php_ffmpeg.dll to you php ext folder
  3. Put the rest of dlls to you windows/system32 folder
  4. Restart apache and run phpinfo() – you should see the ffmpeg extension (btw you have to check php not apache error log if you are looking for errors wamp->php->php error log)
Other Method

We recently had a request from a client to install FFMPEG and the associated PHP module on a Windows server that was running Plesk 8.2 with PHP 5.2. This posed a bit of a problem because the FFMPEG project only releases source code releases, relying on others to make binary distributions. For linux distributions, it’s usually in the package repository, but for windows, you have to dig around the internet until you can find someone that has compiled it for you, or you can compile it yourself. In addition, they refuse to go out of their way to make their code Windows friendly, which is fine, but it makes the process to compile it kind of complicated, since it doesn’t work in Microsoft’s C/C++ compiler by default, so you have to configure MinGW to compile it.

Finding a windows distribution of the main FFMPEG project was fairly easy. This site distributes binaries and also provides a very good guide on compiling it for yourself.

However, the PHP module is much harder. Especially since you have to find a module that is compatible with your version of PHP. Most of the available instructions point to PHP 4 modules, if you need a PHP 4 module, here is one good set of instructions. After much digging, I finally found a PHP 5 module here.

UPDATED: This link is now broken, we’re currently hosting the PHP 5 module on our website here.

A complete set of instructions for completing this installation is below. My environment was Windows 2003, IIS 6, Plesk 8.2 and PHP 5.2.6:

  • If you plan to use the FFMPEG command-line tool, download the binary package from arrozcru.org. Use a tool such as 7-zip to decompress it and expand the tar file where you want to place it.
  • Download the zip file that includes the ffmpeg-php extension here and uncompress it. It includes several other software packages, you can ignore them, the files that we are interested in are in the ffmpeg-php-win32-all directory. UPDATED: This link is now broken, we’re currently hosting the PHP 5 module on our website here.
  • Copy the avcodec-51.dll, avformat-51.dll, avutil-49.dll and pthreadGC2.dll files to the c:\windows\system32 directory.
  • Copy the php_ffmpeg.dll file to your PHP extensions directory. For me, this was “C:\Program Files\SWsoft\Plesk\Additional\PleskPHP5\ext”
  • Edit your php.ini file and add the following bit. For me this was located at “C:\Program Files\SWsoft\Plesk\Additional\PleskPHP5\php.ini”extension=php_ffmpeg.dll
  • If you are running PHP as an ISAPI filter, you’ll probably need to restart IIS. I was running it as a CGI and I didn’t need to restart.

Source

  • http://wiki.mediatemple.net/w/(dv):Installing_FFmpeg_and_FFmpeg-php
  • http://ubuntuforums.org/showthread.php?t=934995
  • http://ffmpeg-php.sourceforge.net/

Leave a comment