Apr 282012
 

It’s been a long time coming, but here’s my guide to install the latest ffmpeg and associated packages for a video upload site on base CentOS, no cPanel required (if Google got you here and you have cPanel, try the cPanel ffmpeg guide). This article assumes you’ve already set up your HTTP daemon (Apache, nginx, lighttpd, litespeed, etc), scripting agent (PHP), and database provider (mySQL, PostgreSQL, etc). The commands in this guide assume you are running the latest CentOS 5.8 64-bit. Some modifications may be necessary for other architectures and versions of CentOS.

  1. Make sure you’re up to date
  2. Make sure you’re on the latest CentOS branch. We’re installing the latest version of ffmpeg, and if you’re not running the latest version of your CentOS branch, you may run into unexpected issues.

    yum update

    Install whatever is required, and compatible with your other software. If you update your kernel, reboot before continuing.

  3. Extra Repositories
  4. RPMForge is a useful, fully-compatible extra repository. We will use it for a number of packages that don’t need to be bleeding-edge. For more information, see the CentOS wiki.

    wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
    rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
    rpm -K rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
    rpm -i rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

  5. Development Tools
  6. You must have the required packages to download and compile the source code.

    yum groupinstall "Development Tools"
    yum install subversion git

  7. Install RPM libraries
  8. Some libraries don’t need to be bleeding-edge. We’ll install those now.

    yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel libXext libXext-devel flvtool2

  9. ldconfig
  10. We need to make sure ldconfig is checking the correct directories for libraries.

    echo /usr/local/lib >> /etc/ld.so.conf; ldconfig

  11. Download libraries
  12. Okay, here’s the big one. It’s probably a good idea to go ahead and copy+paste this whole code block into your terminal at once to save time. One note; the official distribution release of ffmpeg-php no longer compiles. The SVN version available here works, but the SVN tarball link here can’t easily be downloaded in a terminal session, so I’ve rehosted the file here on this server. This is not my file, I haven’t modified it, and I take no responsibility for it – it’s merely a copy of the file available from the above link.

    cd /usr/local/src
    wget http://iweb.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
    tar zxf lame-3.99.5.tar.gz
    wget http://hasaninter.net/ffmpeg-php.tar.gz
    tar xzf ffmpeg-php.tar.gz
    wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
    tar xzf libvorbis-1.3.3.tar.gz
    wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
    tar xzf libogg-1.3.0.tar.gz
    wget http://iweb.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz
    tar xzf opencore-amr-0.1.3.tar.gz
    wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
    tar xjf libtheora-1.1.1.tar.bz2
    wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
    tar zxf xvidcore-1.3.2.tar.gz
    wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
    tar zxf faad2-2.7.tar.gz
    wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
    tar zxf faac-1.28.tar.gz
    mkdir /usr/local/lib/codecs
    wget ftp://ftp.mplayerhq.hu/MPlayer/releases/codecs/all-20110131.tar.bz2
    tar -jxf all-20110131.tar.bz2
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
    tar zxf yasm-1.2.0.tar.gz
    cp all-20110131/* /usr/local/lib/codecs/
    chmod -R 755 /usr/local/lib/codecs/
    mkdir /usr/local/src/tmp
    chmod 777 /usr/local/src/tmp
    export TMPDIR=/usr/local/src/tmp
    svn co https://gpac.svn.sourceforge.net/svnroot/gpac/trunk/gpac gpac
    git clone git://git.videolan.org/x264.git
    git clone git://git.videolan.org/ffmpeg.git ffmpeg
    svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

  13. Compile everything
  14. Here we go! This is the hard part, where we compile bleeding-edge libraries. At the time this was posted, this all worked. If you run into any errors, try Googling them. If you still can’t figure it out (or more importantly, if you do!) please comment here and I’ll edit this post with the latest fixes.

    1. Lame

    2. cd /usr/local/src/lame-3.99.5/
      ./configure
      make
      make install

    3. Libogg

    4. cd /usr/local/src/libogg-1.3.0
      ./configure
      make
      make install

    5. Libvorbis

    6. cd /usr/local/src/libvorbis-1.3.3
      ./configure
      make
      make install

    7. yasm

    8. cd /usr/local/src/yasm-1.2.0
      ./configure
      make
      make install

    9. Libxvid

    10. cd /usr/local/src/xvidcore/build/generic
      ./configure
      make
      make install

    11. Libx264

    12. cd /usr/local/src/x264
      ./configure --enable-shared
      make
      make install

    13. Opencore-amr

    14. cd /usr/local/src/opencore-amr-0.1.3
      ./configure
      make
      make install

    15. Libtheora

    16. cd /usr/local/src/libtheora-1.1.1
      ./configure
      make
      make install

    17. Fadd2

    18. cd /usr/local/src/faad2-2.7
      ./configure
      make
      make install

    19. Faac

    20. cd /usr/local/src/faac-1.28
      ./configure
      make
      make install

    21. MP4Box

    22. cd /usr/local/src/gpac
      ./configure
      make
      make install

    23. mplayer

    24. cd /usr/local/src/mplayer/
      ./configure --enable-jpeg
      make
      make install

    25. ffmpeg

    26. cd /usr/local/src/ffmpeg
      ./configure --enable-libmp3lame --enable-libvorbis --enable-shared --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-nonfree --enable-libtheora --enable-version3 --enable-gpl --enable-libxvid
      make
      make install

    27. ffpmeg-php

    28. cd /usr/local/src/ffmpeg-php
      phpize
      ./configure
      make
      make install

    29. php.ini
    30. If you’re adding in the ffmpeg module to PHP (which this guide assumes you are), you need to add the extension to PHP. Again, this guide assumes you’re using PHP on Apache with CentOS 5.

      echo "extension=ffmpeg.so" > /etc/php.d/ffmpeg.ini
      /etc/init.d/httpd restart

  15. ldconfig
  16. To ensure that all of the libraries are loaded and linkable by ffmpeg, etc, run:

    ldconfig

That’s it! There are a few tests you can run to ensure that this is actually installed properly. Here are the two most important.


php -m | grep ffmpeg
ffmpeg