HOWTO: Compiling the latest FFmpeg & x264 on CentOS 4

Intoduction

FFmpeg is a superb video processing tool used to encode and transcode video files. In this particular project I needed to build “youtube” style video upload which would transcode into FLV, specifically catering for video files from the Nokia N95.

I spent quite a long time messing about with the stock version of ffmpeg on CentOS 4/Ubuntu trying to make it work, but it turned out not to be new enough/have all the right support compiled in.

This howto was written because I couldn’t find anything that fitted the bill for CentOS/RHEL (And being a Ubuntu man, found it a pain to get it compiled and working under CentOS). It’s based on the excellent tutorial by FakeOutdoorsman over on the Ubuntu forums. So big thanks to them.

These instructions have been tested on a fresh minimal install of CentOS 4.6 running in a VirtualBox VM.

Preparation

  1. Ensure that you have the rpmforge repo’s added to yum. See here for instructions.
  2. Update the install
    yum update
  3. (If you are not installing onto a fresh minimal install) Remove ffmpeg, x264 and faad2 to avoid confusion.
    yum remove ffmpeg x264 faad2 faad2-devel
  4. Install the necessary build tools
    yum install gcc gcc-c++ automake autoconf libtool yasm git subversion
  5. Install the necessary libraries
    yum install zlib-devel libmad-devel libvorbis-devel libtheora-devel lame-devel faac-devel a52dec-devel xvidcore-devel freetype-devel

Compile supporting libraries

  1. Compile & Install faad2 (for some reason I couldn’t get it to compile against the standard rpm version)
    cd ~
    wget http://downloads.sourceforge.net/faac/faad2-2.6.1.tar.gz
    tar xzvf faad2-2.6.1.tar.gz
    cd faad2
    autoreconf -vif
    ./configure
    make
    make install
  2. Compile & Install GPAC
    cd ~
    wget http://downloads.sourceforge.net/gpac/gpac-0.4.4.tar.gz
    tar -xzvf gpac-0.4.4.tar.gz
    cd gpac
    ./configure
    make
    make install
    make install-lib

    Note: if the compile fails with a osmozilla related error, please see here. I had to remove mozilla support to get it to compile.

  3. Update the links to the shared libs
    echo '/usr/local/lib/' > /etc/ld.so.conf.d/gapc-1386.conf
    ldconfig
  4. Compile & Install x264
    cd ~
    git clone git://git.videolan.org/x264.git
    cd x264
    ./configure  --enable-pthread --enable-mp4-output --enable-shared
    make
    make install
  5. Update the links to the shared libs…again
    ldconfig

Install ffmpeg

  1. cd ~
    svn export svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
    cd ffmpeg
    ./configure --prefix=/usr/local --disable-debug --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-pthreads --enable-x11grab --enable-liba52 --enable-libx264 --enable-libxvid --enable-libvorbis --enable-libfaac --enable-libfaad --enable-libmp3lame
    make
    make install
  2. If ffmpeg has problems finding shared libraries, set the LD_LIBRARY_PATH
    echo 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib; export LD_LIBRARY_PATH' >> /etc/ld.so.conf
    ldconfig

    I’m not convinced that this is the correct thing to do, or the correct way to do it…but it seems to work…

  3. All done.

Additional resources:

http://www.nazly.net/index.php?page=showevents&selTopic=230

http://www.tuxmachines.org/node/17063

Tags: , , , ,

4 Responses to “HOWTO: Compiling the latest FFmpeg & x264 on CentOS 4”

  1. Instalasi FFMPEG dan Library Pelengkap di CentOS 5 64 bit | Artikel Magnet Says:

    [...] http://mafiascripts.net/index.php?showtopic=8761 http://www.austenconstable.com/2008/08/06/howto-compiling-the-latest-ffmpeg-x264-on-centos-4 http://sourceforge.net/forum/forum.php?thread_id=1950227&forum_id=287546 « Apache 2 dan [...]

  2. Websites tagged "pthread" on Postsaver Says:

    [...] – Neil Williams: State of play in Emdebian {ARM} saved by carlaarena2008-09-27 – HOWTO: Compiling the latest FFmpeg & x264 on CentOS 4 saved by maiweezy2008-09-18 – Cross-compiling GTK+ over DirectFB v0.2 saved by [...]

  3. Mario Says:

    Great tutorial!

    Will this work with any format input container, for example, is this prepped for conversion from avi, flv, mkv, -> h.264 (mp4 container)?

  4. nerkn Says:

    Complying gpac required me to yum “zlib-devel” I got comply error.

Leave a Reply