How to compile and install ffmpeg in Ubuntu 11.04

Posted: May 9, 2011 in Ubuntu
Tags: , , ,

Hello folks. Today we will see a excellent software that permit us to manipulate audio and videos files.

FFmpeg is a free software that permit us to record, convert and stream audio and video. It provide support for most existing file formats like AVI, MPEG, OGG, etc. and encoding formats like MPEG, DivX, MPEG4, etc. When you installed it from repository, it does not come with some encodes enabled like x264, vorbis and between others. So, to enable them, we need to compile it

Open a terminal and run:

sudo apt-get remove libmp3lame-dev ffmpeg

sudo apt-get install quilt libsdl1.2-dev libogg-dev libvorbis-dev liba52-dev libdts-dev libimlib2-dev texi2html libraw1394-dev libdc1394-22-dev libtheora-dev libgsm1-dev libxvidcore-dev libfaac-dev libfaad-dev build-essential git-core checkinstall yasm texi2html libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libx11-dev libxfixes-dev zlib1g-dev nasm

The command above will remove the libmp3lame-dev to avoid conflict and install the dependencies to compile ffmpeg and to enable the encoding. In this post we will compile the latest ffmpeg and x264 version, so let’s donwload x264 from git and compile it. Still in the terminal, type:

cd
mkdir ffmpeg-source
cd ffmpeg-source
git clone git://git.videolan.org/x264
cd x264
./configure
make -j3
sudo checkinstall --pkgname=x264 --default --pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes

Remember that, the option -j3 depends the numbers of cores or processors from your computer. X264 enables for encoding video streams into the H.264/MPEG-4 AVC.

Now, let’s do the same thing with lame.

cd ~/ffmpeg-source
sudo mkdir -p /usr/local/share/doc/lame
wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
tar xzvf lame-3.98.4.tar.gz
cd lame-3.98.4
./configure --enable-nasm --disable-shared
make -j3
sudo checkinstall --pkgname=lame-ffmpeg --pkgversion="3.98.4" --backup=no --default --deldoc=yes

Lame enables for encoding mp3 audio.

Another interesting encoding to be installed is the VP8 video. In the terminal run:

cd ~/ffmpeg-source
git clone git://review.webmproject.org/libvpx
cd libvpx
./configure
make -j3
sudo checkinstall --pkgname=libvpx --pkgversion="$(date +%Y%m%d%H%M)-git" --backup=no --default --deldoc=yes

Finally, it’s time to download, compile and install ffmpeg. Still in the terminal, run:

cd ~/ffmpeg-source
git clone git://git.videolan.org/ffmpeg
cd ffmpeg

./configure --enable-gpl --enable-postproc --enable-swscale --enable-pthreads --enable-x11grab --enable-libdc1394 --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx

make -j3

sudo checkinstall --pkgname=ffmpeg --pkgversion="0.6.3-git" --backup=no --deldoc=yes --default
hash x264 ffmpeg ffplay ffprobe

After that, you have the ffmpeg installed with a great numbers of encoding enabled. To verify if everything is ok, type in the terminal:

ffmpeg -version

You will see something like that:

ffmpeg version git-N-29730-g6841c8c, Copyright (c) 2000-2011 the FFmpeg developers
built on May 9 2011 00:00:10 with gcc 4.6.1 20110429 (prerelease)
configuration: --enable-gpl --enable-postproc --enable-swscale --enable-pthreads --enable-x11grab --enable-libdc1394 --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx
libavutil 51. 2. 1 / 51. 2. 1
libavcodec 53. 5. 0 / 53. 5. 0
libavformat 53. 0. 3 / 53. 0. 3
libavdevice 53. 0. 0 / 53. 0. 0
libavfilter 2. 5. 0 / 2. 5. 0
libswscale 0. 14. 0 / 0. 14. 0
libpostproc 51. 2. 0 / 51. 2. 0
ffmpeg git-N-29730-g6841c8c
libavutil 51. 2. 1 / 51. 2. 1
libavcodec 53. 5. 0 / 53. 5. 0
libavformat 53. 0. 3 / 53. 0. 3
libavdevice 53. 0. 0 / 53. 0. 0
libavfilter 2. 5. 0 / 2. 5. 0
libswscale 0. 14. 0 / 0. 14. 0
libpostproc 51. 2. 0 / 51. 2. 0

Note that, the item configuration displays the same line typed in the command “./configure” in ffmpeg compilation, in other words, everything was compiled with success.

If you want to get more information about ffmpeg, access the site www.ffmpeg.org.

That’s it. See you next time.

Advertisements
Comments
  1. panreyes says:

    Hello,
    Thanks for your guide, but in 11.04 I noticed this error when configuring ffmpeg: It won’t find x264, because the *.h where not copied to /usr/local/include/x264

    By just adding this line, it will be working fine
    mkdir /usr/local/include/x264 && cp ~/ffmpeg-source/x264/*.h /usr/local/include/x264

    • buildall says:

      Hi panreyes. Thanks for your comments.

      I have done new tests to identify what happend with you and that was the reason for the delay in responding. I’ve installed the Ubuntu in a new computer and I’ve done the tests. What I found out is that, this x264 version in the git was changed and x264 team have made some changes in Makefile too. To complete the x264 installation you need to do these steps:

    • – cp ~/ffmpeg-source/x264/*.h /usr/local/include (you don’t need to create a folder named x264, ffmpeg search the headers in /usr/local/include).
    • – cp ~/ffmpeg-source/x264/libx264.a /usr/local/lib/
    • However, if you don’t want to copy the files, just run this command in the end: make install-lib-dev. This will install the headers and libraries in the respective directories.

      Follow bellow, the differences between Makefile, I have compared that with the current one I published in this post.

      diff Makefile Makefile-old
      138c138
      .PHONY: all default fprofiled clean distclean install uninstall dox test testclean
      140,144c140
      < default: $(DEP)
      <
      < cli: x264$(EXE)
      < lib-static: $(LIBX264)
      default: $(DEP) x264$(EXE)
      153,154c149,150
      < x264$(EXE): .depend $(OBJCLI) $(CLI_LIBX264)
      x264$(EXE): $(OBJCLI) $(LIBX264)
      > $(LD)$@ $+ $(LDFLAGSCLI) $(LDFLAGS)
      214c210
      install: x264$(EXE) $(SONAME)
      216,218d211
      < install x264$(EXE) $(DESTDIR)$(bindir)
      <
      < install-lib-dev:
      224,227d216
      < install -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig
      < install -m 644 libx264.a $(DESTDIR)$(libdir)
      <
      install -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig
      > install x264$(EXE) $(DESTDIR)$(bindir)
      230,231d220
      <
      < install-lib-shared: lib-shared install-lib-dev

  • Davidxx4 says:

    hi .thank you for this tutorial, but i don’t understand . could you please update this
    sorry i am new in to linux world

  • Scott says:

    When I run;

    ./configure –enable-gpl –enable-postproc –enable-swscale –enable-pthreads –enable-x11grab –enable-libdc1394 –enable-libfaac –enable-libgsm –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-nonfree –enable-version3 –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libvpx

    I get this bounced back:

    ERROR: libx264 not found

    Not sure on how to fix this. I don’t really understand the dialogue between you and reyes, and whether or not it applies to my situation.

    • buildall says:

      Hi Scott.

      I’m sorry for that have stayed a little confused. I will explain again of another way.

      There were some changes in the x264’s Makefile. When I have written this post, the x264 installation was completed running:

      sudo checkinstall --pkgname=x264 --default --pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes

      Now, due these changes in Makefile, you must run after the command above:

      cd ~/ffmpeg-source/x264
      sudo make install-lib-dev
      sudo cp libx264.a /usr/local/lib/

      After that, go back to the ffmpeg source:

      cd ~/ffmpeg-source/ffmpeg

      and run the configure command again.

      I hope to have helped you. Any doubt, feel free to ask me.

      See you.

      • dopple says:

        Hi Buildall. It might be worth updating uour wiki article with this info so that people don’t have to check the comments for this info.

    • mrrgu says:

      When configuring x264 do this instead of just ./configure

      ./configure –enable-shared

  • bugbear says:

    I just worked all the way through that, then tried

    ffmpeg -i ep1.mp2 -ar 48000 -ab 128 -ac 2 -acodec mp3 ep1.mp3

    and got:

    Unknown encoder ‘mp3’

    frankly, I could weep!

    BugBear

    attached:

    ffmpeg -version
    ffmpeg version git-N-30694-g16c9e67, Copyright (c) 2000-2011 the FFmpeg developers
    built on Jun 10 2011 16:35:22 with gcc 4.5.2
    configuration: –enable-gpl –enable-postproc –enable-swscale –enable-pthreads –enable-x11grab –enable-libdc1394 –enable-libfaac –enable-libgsm –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-nonfree –enable-version3 –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libvpx
    libavutil 51. 8. 0 / 51. 8. 0
    libavcodec 53. 7. 0 / 53. 7. 0
    libavformat 53. 3. 0 / 53. 3. 0
    libavdevice 53. 1. 1 / 53. 1. 1
    libavfilter 2. 15. 0 / 2. 15. 0
    libswscale 0. 14. 1 / 0. 14. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    ffmpeg git-N-30694-g16c9e67
    libavutil 51. 8. 0 / 51. 8. 0
    libavcodec 53. 7. 0 / 53. 7. 0
    libavformat 53. 3. 0 / 53. 3. 0
    libavdevice 53. 1. 1 / 53. 1. 1
    libavfilter 2. 15. 0 / 2. 15. 0
    libswscale 0. 14. 1 / 0. 14. 1
    libpostproc 51. 2. 0 / 51. 2. 0

    • buildall says:

      Hi bugbear.

      Instead of use mp3 try to use libmp3lame.

      For example:

      ffmpeg -i ep1.mp2 -ar 48000 -ab 128 -ac 2 -acodec libmp3lame ep1.mp3.

      Any problem, feel free to ask me.

  • Hi,

    Is there a way to similary install ffmpeg2theora? I’m trying to install miro on natty which depends on ffmpeg and ffmpeg2theora. I was able to successfully install one using the above steps.

    when i do
    $>sudo apt-get install ffmpeg2theora

    i get the following errors in synaptic:
    —————————————————————-
    ffmpeg2theora:
    Depends: libavdevice52 but it is not going to be installed or
    libavdevice-extra-52 but it is not going to be installed
    Depends: libavformat52 but it is not going to be installed or
    libavformat-extra-52 but it is not going to be installed

  • nik0s says:

    Hi,

    I follow your tutorial and I wrote a script to automatically install deps, download from git and compile ffmpeg

    http://www.techno-blog.net/blog/2011/compiler-la-derniere-version-de-ffmpeg.html

    Regards Nikos

  • Dmitri says:

    works fine after these instructions:

    cd ~/ffmpeg-source/x264
    sudo make install-lib-dev
    sudo cp libx264.a /usr/local/lib/

  • Chris says:

    Hello,

    Could you please explain a little more on the -j3 make option? You briefly mention it has to do with your cpu count but I’ve not been able to find any information other than here on that specific flag.

    For instance, what would I change -j3 to in my system? 2x Intel Xeon E5260 quad core (8 total physical cores, 16 virtual).

  • Arianna says:

    Hi! I still have some problem when I do the “make”… I have this error with x264:

    libavcodec/libavcodec.a(libx264.o): In function `X264_init’:
    /home/arianna/ffmpeg-source/ffmpeg/libavcodec/libx264.c:478: undefined reference to `x264_encoder_open_125′
    collect2: ld returned 1 exit status
    make: *** [ffmpeg_g] Error 1

    any suggestion?

    • Vsevolod says:

      It`s cause of you`ve got 2 installed libs of libx264. run commands ls /usr/lib | grep 264 and /usr/local/lib | grep 264.

  • Dennis says:

    Seriously, Why can’t someone make an apt-source that installs ffmpeg with all known codecs and update it as more codecs are added?

  • Andrew Lee says:

    I’m a newbie to Ubuntu. Hope someone can help. After running one of the last steps in the above guide, namely:
    sudo checkinstall –pkgname=ffmpeg –pkgversion=”0.6.3-git” –backup=no –deldoc=yes –default

    I encountered this error message:

    ========================= Installation results =========================
    INSTALL doc/ffmpeg.1
    INSTALL doc/ffplay.1
    INSTALL doc/ffprobe.1
    INSTALL doc/ffserver.1
    INSTALL install-progs-yes
    INSTALL ffmpeg
    INSTALL ffplay
    INSTALL ffprobe
    INSTALL ffserver
    mkdir: cannot create directory `/usr/local/share/ffmpeg’: No such file or directory
    make: *** [install-data] Error 1

    **** Installation failed. Aborting package creation.

    What can I do to fix this problem? Thanks.

  • Cuckoo Anna says:

    When I try to run the last step cd ffmpeg and ./configure …, it says ERROR: libfaac not found.
    Anyone please help me to fix this.

  • Santo says:

    There’s certainly a great deal to know about this subject. I love all of the points you have made.

  • Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s