Here’s how to build and install FFmpeg from source with all the bells and whistles (i.e codec support). We’ll install it as a custom Debian package using checkinstall
. That way, any other package that depends on the ffmpeg
package will recognize that it is already installed, and won’t try to fetch it from the Debian or Ubuntu software repositories.
Install the dependencies
sudo apt-get -y install build-essential autoconf automake cmake libtool git checkinstall mkdir ffmpegtemp cd ffmpegtemp mkdir aom cd aom git clone https://aomedia.googlesource.com/aom cmake aom/ -DBUILD_SHARED_LIBS=1 make sudo checkinstall -y --deldoc=yes --pkgversion=1.0.0 cd .. git clone https://github.com/hoene/libmysofa cd mysopha cd build cmake .. cd build cpack sudo apt-get remove libmysopha0 libmysopha-dev sudo dpkg -i *.deb cd.. sudo apt-get -y install build-essential autoconf automake cmake libtool git \ checkinstall nasm yasm libass-dev libfreetype6-dev libsdl2-dev p11-kit \ libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \ libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev libchromaprint-dev \ frei0r-plugins-dev gnutls-dev ladspa-sdk libcaca-dev libcdio-paranoia-dev \ libcodec2-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgme-dev \ libgsm1-dev libjack-dev libmodplug-dev libmp3lame-dev libopencore-amrnb-dev \ libopencore-amrwb-dev libopenjp2-7-dev libopenmpt-dev libopus-dev \ libpulse-dev librsvg2-dev librubberband-dev librtmp-dev libshine-dev \ libsmbclient-dev libsnappy-dev libsoxr-dev libspeex-dev libssh-dev \ libtesseract-dev libtheora-dev libtwolame-dev libv4l-dev libvo-amrwbenc-dev \ libvorbis-dev libvpx-dev libwavpack-dev libwebp-dev libx264-dev libx265-dev \ libxvidcore-dev libxml2-dev libzmq3-dev libzvbi-dev liblilv-dev \ libopenal-dev opencl-dev libjack-dev
Install the non-free dependencies too, if you want to convert decrypted Blu-Ray content:
sudo apt-get -y install libbluray-dev libfdk-aac-dev
Download and extract the FFmpeg source code
wget https://ffmpeg.org/releases/ffmpeg-4.2.1.tar.bz2 tar -xf ffmpeg-4.2.1.tar.bz2 rm ffmpeg-4.2.1.tar.bz2 cd ffmpeg-4.2.1
Configure the build
With free dependencies only
./configure --enable-gpl --enable-version3 --disable-static --enable-shared --enable-small --enable-avisynth --enable-chromaprint --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine --enable-libsmbclient --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtesseract --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa --enable-openal --enable-opencl --enable-opengl --enable-libdrm
Or, including non-free
./configure --enable-gpl --enable-version3 --disable-static \ --enable-shared --enable-small --enable-avisynth --enable-chromaprint \ --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa \ --enable-libaom --enable-libass --enable-libcaca --enable-libcdio \ --enable-libcodec2 --enable-libfontconfig --enable-libfreetype \ --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack \ --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb \ --enable-libopencore-amrwb --enable-libopencore-amrwb \ --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse \ --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine \ --enable-libsnappy --enable-libsoxr --enable-libspeex \ --enable-libssh --enable-libtesseract --enable-libtheora \ --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc \ --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp \ --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 \ --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa \ --enable-openal --enable-opencl --enable-opengl --enable-libdrm \ --enable-nonfree --enable-libfdk-aac --enable-libbluray
Build
make
Purge any existing package installation
sudo apt-get -y purge ffmpeg "libav*" " libpostproc*" sudo apt-get -y autoremove
Install your custom FFmpeg build as a package
sudo checkinstall -y --deldoc=yes --pkgversion=10:4.2.1 cd .. rm -rf ffmpegtemp
This saved my life. Thanks
this doesn’t work for debian 8
ges/mysite/Build/aom# cmake aom/
CMake Error at CMakeLists.txt:11 (cmake_minimum_required):
CMake 3.5 or higher is required. You are running version 3.0.2
— Configuring incomplete, errors occurred!
I tried this on an Ubuntu 18.04 and during the Build stage, the make fails:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CC libavcodec/lclenc.o
CC libavcodec/libaomdec.o
CC libavcodec/libaomenc.o
libavcodec/libaomenc.c:703:109: error: ‘AOM_ERROR_RESILIENT_PARTITIONS’ undeclared here (not in a function); did you mean ‘AOM_ERROR_RESILIENT_DEFAULT’?
” is still done over the partition boundary.”, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, “er”},
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AOM_ERROR_RESILIENT_DEFAULT
ffbuild/common.mak:60: recipe for target ‘libavcodec/libaomenc.o’ failed
make: *** [libavcodec/libaomenc.o] Error 1
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Just thought I would pass it on.
I have the same issue as Mike Perkinson in Ubuntu 16.04
Did you solve the problem?
This commit solves the problem: http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=b69ea742ab23ad74b2ae2772764743642212a139
Even after apply the patch I cannot get to compile
/usr/bin/ld: /usr/local/lib/libaom.a(aom_config.c.o): relocation R_X86_64_32 against `.rodata.str1.8′ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libaom.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
ffbuild/library.mak:102: recipe for target ‘libavcodec/libavcodec.so.58’ failed
make: *** [libavcodec/libavcodec.so.58] Error 1
Tried using the latest snapshot, exactly the same issue.
try to update to latest aom. works on november builds
I got aom again, cloned git but still it is the same as before. I can compile the latest snapshot manually following https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu or using the scripts from https://github.com/rdp/ffmpeg-windows-build-helpers but not the relase branch.
For now I can stick with snapshot
I solved this compile error with adding the PIC compile flag to the aom library, try this patch in directory ffmpegtemp/aom/aom:
diff –git a/build/cmake/compiler_flags.cmake b/build/cmake/compiler_flags.cmake
index 79192c1fa..ec8d214a5 100644
— a/build/cmake/compiler_flags.cmake
+++ b/build/cmake/compiler_flags.cmake
@@ -17,6 +17,9 @@ include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(“${AOM_ROOT}/build/cmake/compiler_tests.cmake”)
+set(AOM_EXTRA_C_FLAGS “-fPIC”)
+
# Strings used to cache flags.
set(AOM_C_FLAGS)
set(AOM_CXX_FLAGS)
When I’m trying to compile ffmpeg, I have this error
nasm/yasm not found or too old. Use –disable-x86asm for a crippled build.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “ffbuild/config.log” produced by configure as this will help
solve the problem.
I ran into this problem as well. After I ran this I got farther:
sudo apt install nasm
compile aom with option:
cmake aom/ -DAOM_EXTRA_C_FLAGS=-fPIC
worked for me.
I solved the ffmpeg issue with aom by compiling aom as a shared library:
cmake aom/ -DBUILD_SHARED_LIBS=1
as per (aom/README.md)
Thank you for this very helpful comment!
..then after running ldconfig:
erflungued@minty:~/src/ffmpegtemp/ffmpeg-4.1.3$ make check
worked fine.
Thanks for this tute @Sean
After removing libavcodec I ended up in command line on boot.
Looks like libs from this custom ffmpeg package were not linked properly. Any suggestions how to fix?
I’m stuck there too… really wish someone answered with a solution. Google isn’t helping much… =/
LD libavcodec/libavcodec.so.58
/usr/bin/ld: /usr/local/lib/libaom.a(noise_model.c.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5′ can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
ffbuild/library.mak:102: recipe for target ‘libavcodec/libavcodec.so.58’ failed
make: *** [libavcodec/libavcodec.so.58] Error 1
1) Small typo in instructions;
–enable-small–enable-avisynth
should read:
–enable-small –enable-avisynth
2) git clone …
can be
git clone –depth=1 …
to avoid unecessary repo history
3) aom: for this error: “relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5′ can not be used when making a shared object; recompile with -fPIC” the following works:
delete ffmpegtemp directory, take all same steps for aom again, but change;
cmake aom/
to;
cmake aom/ -DAOM_EXTRA_C_FLAGS=-fPIC
then just go back to ffmpeg directory and type make again, build will complete
4) Latest: https://ffmpeg.org/releases/ffmpeg-4.1.3.tar.gz
Enjoy & God bless
HI,
I have this warning:
/usr/bin/ld: warning: libavcodec.so.57, needed by /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libchromaprint.so, may conflict with libavcodec.so.58
/usr/bin/ld: warning: libavutil.so.55, needed by /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libchromaprint.so, may conflict with libavutil.so.56
/usr/bin/ld: warning: libswresample.so.2, needed by //usr/lib/x86_64-linux-gnu/libavcodec.so.57, may conflict with libswresample.so.3
Then:
support@Bench-PC-01:~/ffmpegtemp/ffmpeg-4.0$ ffmpeg
ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
Hi,
I have the exact same problem mentioned above regarding not being able to open libavdevice.so.58
Any suggestions?
Thank you.
Nevermind, I think “make install” did the trick.
What a pain in the lower rear… Can anybody provide an Ubuntu build with all the non-free stuff and VAAPI/GPU-encoding included? (or even a Windows EXE to run in Wine, that would be super practical and straight forward…)
wow! thank you Sean – this went very well.
just one little fix on the page formatting: at installing the dependencies
“sudo apt-get -y install build-essential autoconf automake …\”
there is white space after each backslash so if we paste the whole block in at the prompt it wants to checkinstall nasm – not the intended consequence!
the ./configure block is clear of any trailing white space and works as intended.
I’ve been using linux for a couple years, but am still a novice, after a bunch of headaches, here are my notes from my install on MX linux 19
———————————————————————————————————————-
1. Before you start, you have to have to add MX Linux’s AHS repository:
Launch synaptic package manager > settings > Repositories > New, then enter
Binary: deb
URI: http://mxrepo.com/mx/repo/
Distribution: buster ahs
Click OK
Check the Enabled box next to the new http://mxrepo.com/mx/repo/ entry
or you run into a bunch of dependency errors when you try to install libsdl2-dev.
———————————————————————————————————————-
2. Before you get to the installing libmysofa you have to install yasm by running:
sudo apt get yasm
or you’ll get an error
———————————————————————————————————————-
3. Running “git clone https://github.com/hoene/libmysofa” creates a folder called “libmysofa” not “mysopha”, so after it finishes downloading run:
cd libmysofa
instead of “cd mysopha”
———————————————————————————————————————-
4. after running “sudo dpkg -i *.deb” in the mysofa run
cd ..
instead of “cd..” because it’s missing a space and so won’t move up the directory.
———————————————————————————————————————-
5. Before configuring the ffmpeg build you have to run:
sudo apt install libdrm-dev
otherwise you get an error saying that the pkg can’t find it. (added to the list below)
———————————————————————————————————————-
6. When installing the long list of dependencies and running the ffmegpeg configuration MX Linux will ignore all the commands after the first \, so remove all of them and enter them as one long list instead:
sudo apt-get -y install build-essential autoconf automake cmake libtool git checkinstall nasm yasm libass-dev libfreetype6-dev libsdl2-dev p11-kit libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev libchromaprint-dev frei0r-plugins-dev gnutls-dev ladspa-sdk libcaca-dev libcdio-paranoia-dev libcodec2-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgme-dev libgsm1-dev libjack-dev libmodplug-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libopenjp2-7-dev libopenmpt-dev libopus-dev libpulse-dev librsvg2-dev librubberband-dev librtmp-dev libshine-dev libsmbclient-dev libsnappy-dev libsoxr-dev libspeex-dev libssh-dev libtesseract-dev libtheora-dev libtwolame-dev libv4l-dev libvo-amrwbenc-dev libvorbis-dev libvpx-dev libwavpack-dev libwebp-dev libx264-dev libx265-dev libxvidcore-dev libxml2-dev libzmq3-dev libzvbi-dev liblilv-dev libopenal-dev opencl-dev libjack-dev libdrm-dev
./configure –enable-gpl –enable-version3 –disable-static –enable-shared –enable-small –enable-avisynth –enable-chromaprint –enable-frei0r –enable-gmp –enable-gnutls –enable-ladspa –enable-libaom –enable-libass –enable-libcaca –enable-libcdio –enable-libcodec2 –enable-libfontconfig –enable-libfreetype –enable-libfribidi –enable-libgme –enable-libgsm –enable-libjack –enable-libmodplug –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libopencore-amrwb –enable-libopenjpeg –enable-libopenmpt –enable-libopus –enable-libpulse –enable-librsvg –enable-librubberband –enable-librtmp –enable-libshine –enable-libsnappy –enable-libsoxr –enable-libspeex –enable-libssh –enable-libtesseract –enable-libtheora –enable-libtwolame –enable-libv4l2 –enable-libvo-amrwbenc –enable-libvorbis –enable-libvpx –enable-libwavpack –enable-libwebp –enable-libx264 –enable-libx265 –enable-libxvid –enable-libxml2 –enable-libzmq –enable-libzvbi –enable-lv2 –enable-libmysofa –enable-openal –enable-opencl –enable-opengl –enable-libdrm –enable-nonfree –enable-libfdk-aac –enable-libbluray
———————————————————————————————————————-
Thanks for the guide, hopefully this will help others if they run into the same issues.
how to configure ‘const char *filter_descr’ in https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/filtering_video.c to use atadenoise to do video processing in ffmepg
I was trying to compile ffmpeg for three days and I failed every time. this tutorial was a savior. thank you very much.
Very grateful for this guide. I would love to see it updated to include ‘all codecs’ and cuda support for GPU processing. Am attempting to combine your guide with https://www.cyberciti.biz/faq/how-to-install-ffmpeg-with-nvidia-gpu-acceleration-on-linux/