Compiling custom ffmpeg with all bells and whistles on Ubuntu 8.10
Sunday, March 1st, 2009This is first of two blog posts explaining how to compile and install ffmpeg with all supporting libraries. This tutorial is based on one of the tutorials I have found online. It would be way harder to write it without it. You can find it here: http://juliensimon.blogspot.com/2008/12/howto-compiling-ffmpeg-x264-mp3-xvid.html.
I’m assuming that you are using Ubuntu 8.10 Intrepid Ibex with all the ffmpeg libraries, gstreamer libraries, ubuntu-restricted-extras and ffmpeg already installed. I have tested the steps on fresh Ubuntu install so there should be no problem following them. You should probably install ubuntu-restricted-extras package before proceeding with the tutorial.
Prerequisites
Before we start we have to install subversion and git repository tools.
$ sudo apt-get install subversion git git-core
We also have to remove Ubuntu version of ffmpeg so there are no conflicts with the new one we will be installing.
$ sudo apt-get remove ffmpeg
All software sources will go to the ~/video folder. So lets create it:
$ mkdir ~/video
Now we have to install some additional libraries that are required by ffmpeg during compilation.
2. Installing libamr
This library is needed for 3GPP speech codecs. You can read more about it here: http://en.wikipedia.org/wiki/Adaptive_multi-rate_compression
Unfortunately libamr is not in Ubuntu repository so we have to pool it from Madiabuntu repositories. To do that we have to add Mediabuntu repositories to our sources list:
$ sudo wget http://www.medibuntu.org/sources.list.d/hardy.list --output-document=/etc/apt/sources.list.d/medibuntu.list
$ sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update
Now we can just apt-get it with the command:
$ sudo apt-get install libamrnb-dev libamrwb-dev
3. Installing libnut
NUT is a container format under construction by MPlayer and ffmpeg developers. Libnut needs to be built from source:
$ cd ~/video
$ svn co svn://svn.mplayerhq.hu/nut/src/trunk/ nut
$ cd nut
$ make
$ sudo make install
$ sudo ldconfig
4. Installing libx264
$ cd ~/video
$ sudo apt-get install libgpac-dev yasm
$ git clone git://git.videolan.org/x264.git
$ cd x264
$ ./configure --prefix=/usr/local --enable-shared --enable-pic
$ make
$ make install
$ sudo ldconfig
5. Installing libxvid
$ cd ~/video
$ sudo apt-get install nasm
$ wget http://downloads.xvid.org/downloads/xvidcore-1.2.1.tar.gz
$ tar xvfz xvidcore-1.2.1.tar.gz
$ cd xvidcore/build/generic
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ sudo ldconfig
6. Installing additional libraries
$ sudo apt-get install libfaac-dev libfaad-dev libschroedinger-dev libtheora-dev libvorbis-dev libxv-dev libxvmc-dev libmp3lame-dev libgsm1-dev libavc1394-dev libdc1394-22-dev libimlib2-dev libdirac-dev libbz2-dev libspeex-dev libopenjpeg-dev libsdl-gfx1.2-dev
7. Configure and build ffmpeg
$ cd ~/video
$ svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
$ cd ffmpeg
Now if you have Nvidia video card you may want to install the latest drivers to take advantage of hardware encoding and decoding in ffmpeg. You can read more about this technology here: http://en.wikipedia.org/wiki/VDPAU. To do that install following packages from Ubuntu repository:
$ sudo apt-get install nvidia-180-kernel-source nvidia-glx-180 nvidia-glx-180-dev
and restart your computer when drivers are installed. After restart (assuming everything works) you are ready to configure the ffmpeg:
$ ./configure --prefix=/usr/local --enable-gpl --enable-nonfree --enable-shared --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-x11grab --enable-bzlib --enable-libamr-nb --enable-libamr-wb --enable-libdc1394 --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libschroedinger --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --enable-libspeex --enable-libopenjpeg --enable-libdirac --enable-vdpau --enable-x11grab
If you use other video card or your Nvidia chipset is not supported (http://www.mythtv.org/wiki/VDPAU) by the new driver use this configuration option:
$ ./configure --prefix=/usr/local --enable-gpl --enable-nonfree --enable-shared --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-x11grab --enable-bzlib --enable-libamr-nb --enable-libamr-wb --enable-libdc1394 --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libschroedinger --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --enable-libspeex --enable-libopenjpeg --enable-libdirac --enable-x11grab
$ make
$ sudo make install
I know below command should not be used (read more here: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html section 3.3.1.) but without it our new ffmpeg will not work. I have tried to solve this problem with switches –extra-ldflags=”-R/usr/local/lib” and –extra-cflags=”-Wl,-rpath,/usr/local/lib” but it did not work. Either I don’t understand the problem or there is something wrong with ffmpeg Makefiles. If someone has an idea how to solve it please post a comment.
$ echo "export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
$ source ~/.bashrc
$ sudo ldconfig
Now lets test our new ffmpeg:
$ ffmpeg -version
FFmpeg version SVN-r17621, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-shared --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-x11grab --enable-bzlib --enable-libamr-nb --enable-libamr-wb --enable-libdc1394 --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libschroedinger --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --enable-libspeex --enable-libopenjpeg --enable-libdirac --enable-vdpau
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.19. 0 / 52.19. 0
libavformat 52.30. 0 / 52.30. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Feb 26 2009 15:39:39, gcc: 4.3.2
FFmpeg SVN-r17621
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.19. 0 / 52.19. 0
libavformat 52.30. 0 / 52.30. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
Seems like everything is OK. Have fun!
