brokencode

Oliver James' website


Building libav/ffmpeg with MSVC

This post is mostly for my future self, I will inevitably forget this process in about 2 years from now and need to do this all over again.

Building libav requires a Unix shell which isn't really difficult to get on Windows but if you want to target the MSVC toolchain you need to jump through some hoops to make that resulting binaries compatible with said toolchain.

I will be using cygwin to handle the shell and VS2019 to handle the toolchain, this will probably work with older and newer versions of MSVC/VS though.

Install x64 Cygwin with some extra packages: wget, bzip2, tar, make, nano, yasm, pkg-config and download and extract a stable snapshot of libav.

Open a 'x64 Native Tools Command Prompt for vs2019', navigate to where you installed cygwin earlier (probably cygwin64), launch cygwin.bat and cd to the source code you extracted earlier.

This will create a unix shell with all the required environment variables to compile code using the MSVC toolchain.

This step is going to massively change depending on what you want to build, libav is a monster of a library with hundreds of different options and abilities. I highly recommend looking at configure in a text editor and determining what you want to build. I just want h264 encoding/decoding ability in a shared library so my configure command looks like:

./configure --toolchain=msvc --enable-shared --disable-programs  --disable-everything --enable-encoder=h264 --enable-decoder=h264 --enable-demuxer=h264  --enable-parser=h264 --prefix=$(pwd)/build --extra-ldflags=User32.lib

I disable everything to start with the a clean slate (by default almost everything is built), I enable a h264 encoder, parser and demuxer and set some Windows specific libraries. I'm not sure why the build process doesn't link them in automatically but hey ho. You won't know if you need extra libraries until it fails to link them later, be prepared to come back to this stage and add the required libs.

Finally, `make -j16` to build and `make install`. Everything will be copied into a 'build' directory.