Skip to content

Instantly share code, notes, and snippets.

@aslushnikov
Last active September 16, 2022 07:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslushnikov/422f1e1a57796a476bf73ebe04f2e5ac to your computer and use it in GitHub Desktop.
Save aslushnikov/422f1e1a57796a476bf73ebe04f2e5ac to your computer and use it in GitHub Desktop.
Windows: Compiling FFMPEG 4.3.1 with only LIBVPX and a few filters

Windows: Compiling FFMPEG 4.3.1 with only LIBVPX and a few filters

My goal was to compile minimal FFMPEG binary on Windows with the following properties:

  • is statically-linked
  • has jpeg decoder
  • has vp8 encoder
  • has a few enabled filters
  • both win32 and win64

Here's my log as of September 3, 2020.

Some context:

As a result, I succeeded using MSYS2 that I downloaded from https://www.msys2.org/ and installed to c:\msys64.

Part 1: Win64 build

  1. Launch c:\msys64\mingw64 to launch a shell with a proper environment.

  2. MSYS2 uses pacman to install dependencies. Run the following commands to update & install packages:

$ pacman -Syu
$ pacman -Su
$ pacman -S make pkgconf diffutils yasm
$ pacman -S mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2

notes:

  • yasm is needed for libvpx
  • the rest is a general compilation toolchain
  1. Compile libvpx manually and install library to a well-known location (prefix):
$ cd /c/
$ git clone https://chromium.googlesource.com/webm/libvpx
$ cd libvpx
$ ./configure --prefix=/eee64 --target=x86_64-win64-gcc --enable-static --disable-shared --disable-docs --disable-tools --disable-unit-tests --disable-examples
$ make && make install

Note: libvpx has a useful readme: https://chromium.googlesource.com/webm/libvpx/+/master/README

  1. Once libvpx is compiled, compile ffmpeg using the just-compiled libvpx:
$ cd /c/
$ git clone git://source.ffmpeg.org/ffmpeg.git
$ cd ffmpeg
$ git checkout n4.3.1
$ ./configure --extra-cflags="-I/eee64/include" \
              --extra-ldflags="-L/eee64/lib -static" \
              --prefix=/eee64 \
              --pkg-config-flags="--static" \
              --bindir=$PWD/output/bin \
              --disable-everything \
              --enable-ffmpeg \
              --enable-protocol=pipe \
              --enable-protocol=file \
              --enable-parser=mjpeg \
              --enable-decoder=mjpeg \
              --enable-demuxer=image2pipe \
              --enable-filter=pad \
              --enable-filter=crop \
              --enable-filter=scale \
              --enable-muxer=webm \
              --enable-libvpx \
              --enable-static \
              --enable-encoder=libvpx_vp8 \
              --disable-pthreads \
              --disable-zlib \
              --disable-iconv \
              --disable-bzlib \
              --disable-w32threads
$ make && make install

note: the following resources helped me to deal with some dynamic dependencies in the resulting ffmpeg.exe:

Part 2: Win32 build

  1. Launch c:\msys64\mingw32 to launch a shell with a proper environment. i'm not sure if this is required or everything could be done from mingw64 - but it worked.

  2. Update libraries for mingw32

$ pacman -Syu
$ pacman -Su
  1. Uninstall the x86_64 compilers that we installed to build win64 version:
$ pacman -R mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2
  1. Install the i686 compilers instead of their x86_64 counterparts:
$ pacman -S mingw-w64-i686-nasm mingw-w64-i686-gcc mingw-w64-i686-SDL2
  1. Remove all old source folders - we'll re-clone everything later for simplicity
$ rm -rf /c/ffmpeg && rm -rf /c/libvpx
  1. Clone & compile libvpx. Notice a change: --target=x86-win32-gcc
$ cd /c/
$ git clone https://chromium.googlesource.com/webm/libvpx
$ cd libvpx
$ ./configure --prefix=/eee32 --target=x86-win32-gcc --enable-static --disable-shared --disable-docs --disable-tools --disable-unit-tests --disable-examples
$ make && make install
  1. Clone & compile ffmpeg
$ cd /c/
$ git clone git://source.ffmpeg.org/ffmpeg.git
$ cd ffmpeg
$ git checkout n4.3.1
$ ./configure --extra-cflags="-I/eee32/include" \
              --extra-ldflags="-L/eee32/lib -static" \
              --prefix=/eee32 \
              --pkg-config-flags="--static" \
              --bindir=$PWD/output/bin \
              --disable-everything \
              --enable-ffmpeg \
              --enable-protocol=pipe \
              --enable-protocol=file \
              --enable-parser=mjpeg \
              --enable-decoder=mjpeg \
              --enable-demuxer=image2pipe \
              --enable-filter=pad \
              --enable-filter=crop \
              --enable-filter=scale \
              --enable-muxer=webm \
              --enable-libvpx \
              --enable-static \
              --enable-encoder=libvpx_vp8 \
              --disable-pthreads \
              --disable-zlib \
              --disable-iconv \
              --disable-bzlib \
              --disable-w32threads
$ make && make install

note: using -j for make somehow breaks compilation - so I'd suggest compiling everything in one thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment