How to compile and install ffmpeg in Ubuntu 11.04

9 05 2011

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.


Actions

Information

19 responses

18 05 2011
panreyes

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

19 05 2011
buildall

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

    23 05 2011
    Davidxx4

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

    24 05 2011
    buildall

    Hi Davidxx4.

    What didn’t you understand?

    26 05 2011
    Scott

    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.

    26 05 2011
    buildall

    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.

    12 05 2012
    dopple

    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.

    21 08 2011
    mrrgu

    When configuring x264 do this instead of just ./configure

    ./configure –enable-shared

    10 06 2011
    bugbear

    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

    10 06 2011
    buildall

    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.

    14 06 2011
    Siddharth Mitra

    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

    21 06 2011
    pasteeater

    Your guide looks very similar to this:
    HOWTO: Install and use the latest FFmpeg and x264 on Ubuntu

    10 07 2011
    nik0s

    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

    28 07 2011
    Dmitri

    works fine after these instructions:

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

    1 08 2011
    Chris

    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).

    1 09 2011
    paulw

    -j just tells make to run compile jobs in parallel, so speeding up the build
    http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_47.html#SEC46

    in your case -j8 would be a good start

    8 05 2012
    Grant Jeffers
    12 05 2012
    dopple

    Thanks Grant. That sorted my issue out.

    24 05 2012
    Arianna

    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?

    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 )

    Connecting to %s




    Follow

    Get every new post delivered to your Inbox.

    Join 37 other followers