C++17 In Detail

09 June 2012

Building LibAV

See my new website at cppstories.com

LibAV (http://libav.org/about.html) is a great video library that handles almost all video codecs. It is independent library, but comes from ffmpeg. The most important thing is that the library can be used not only in open-source projects, but in commercial as well. Unfortunately if you want to use it in the second way you have to build this lib from scratch.  To make the situation worse it is complicated to build it on windows, so a lot of people advice to use Linux and do cross-compilation. There are some pages, where one can find precompiled binaries:
But those builds use only GPL version. To use it commercially, we need to build it on our own.

Configuring the toolchain

  • Install linux (for instance on a Virtual Machine - Oracle VirtualBox is free and amazing software to help). I've installed latest Ubuntu (11.10) but other releases would be fine.
  • from this site: http://ffmpeg.zeranoe.com/blog/ download latest MinGW-w64 toolchain build script. This script will build complete toolchain for cross-compilation. It is a good and very friendly piece of code and everyone (even me!) can handle it.
  • The script takes some time to finish: up to half an hour I think. It should end with the message: "MinGW-w64 has been built without errors. "

To build libAV (or ffmpeg) you need to do

  • Download source code for the libav: http://libav.org/download.html. Place the unpacked files for instance in home/src/libav
  • create output directory for the build for instance: home/build/libav32 and home/build/libav64
  • configure the build (see below in "build configuration")
  • type "make" (and "make install"). After the build you will have several files (dlls) in libav32 and libav64 output directories
  • and that's all... Now you can copy dlls to the windows machine and use them in your software...

Build configuration:

  • decide what you want to build: 32 or 64 bit version and then go to the output directory for that version: for instance cd home/build/libav32
  • add directory for binaries... from the end message of the toolchain: "export PATH="$PATH:/home/fen/mingw/mingw-w64-i686/bin"" or "export PATH="$PATH:/home/fen/mingw/mingw-w64-x86_64/bin""
  • for win32 type ../../src/libav/configure --enable-cross-compile --enable-w32threads --cross-prefix=i686-w64-mingw32- --arch=i686 --target-os=mingw32 --enable-memalign-hack --enable-shared --disable-static --disable-debug --enable-runtime-cpudetect

Important params:

  • "--cross-prefix=" simply go to the home/mingw/mingw-w64-i686/bin and find what is the prefix before binaries, for instance "i686-w64-mingw32-gcc"
  • description of options for the build can be find in the libav/configure script file
hope this helps :)

If you want to get additional C++ resources, exlusive articles, early access content, private Discord server and weekly curated news, check out my Patreon website: (see all benefits):

© 2017, Bartlomiej Filipek, Blogger platform
Disclaimer: Any opinions expressed herein are in no way representative of those of my employers. All data and information provided on this site is for informational purposes only. I try to write complete and accurate articles, but the web-site will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.