(dv):Installing FFmpeg and FFmpeg-php

  • This page was last modified on April 11, 2011, at 14:49.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Contents

About FFmpeg and 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.

FFmpeg-PHP is an extension for PHP that adds an easy to use, object-oriented API for accessing and retrieving information from video and audio files. It has methods for returning frames from movie files as images that can be manipulated using PHP's image functions. This works well for automatically creating thumbnail images from movies. ffmpeg-php is also useful for reporting the duration and bitrate of audio files (mp3, wma...). ffmpeg-php can access many of the video formats supported by ffmpeg (mov, avi, mpg, wmv...)

Requirements

This article assumes the user is comfortable with:

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

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.repo and 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 Tools installed.
  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
  4. 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 of PIX_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

  5. Once you have fixed up the ffmpeg_frame.c file, run the following commands to compile and install the extension:
    phpize
    ./configure && make
    make install
  6. Edit the /etc/php.ini file in your favorite text editor, and add the following line to any blank area underneath the "[PHP]" line:
    /etc/php.ini
    extension=ffmpeg.so
  7. Now, just restart Apache:
    /etc/init.d/httpd restart
  8. 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.
  9. You are done!

External Links

FFmpeg.org website
FFmpeg-php site at Sourceforge
LinuxHostingSupport.net - a fix for "error: PIX_FMT_RGBA32 undeclared"