Project Highlight: ffmpeg-windows-build-helpers

Posted in software by Christopher R. Wirz on Fri May 04 2018



FFmpeg is a free and open-source software project consisting of a large suite of libraries and programs for handling video, audio, and other multimedia files and streams. For a project at work, we have a "compile from source" requirement for third party libraries. We are also maintaining a cross-platform AnyCpu nuget package that wraps FFmpeg. Fortunately, building 32bit and 64bit versions is easy using ffmpeg-windows-build-helpers and I'm a fan of the good work they've done. FFmpeg has somewhat of a complicated build chain, but this project has made it easier - given you have a linux environment (Ubuntu would be my choice). This is where Docker can be of some assistance. If you haven't installed Docker already, give it a try.


sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Note: I will try to update this post on occasion.

Here is the basic Dockerfile to get up and running. I recommend downloading the archive of the repository. This way changes to the dependencies won't change performance of the container.


# Dockerfile
FROM ubuntu:latest
# uses many of the concepts found at
# https://github.com/rdp/ffmpeg-windows-build-helpers/

# This mode enables zero interaction while using apt 
ARG DEBIAN_FRONTEND=noninteractive

# define xterm (xterm is in most cases built with support for 16 colors)
# and needs to be defined for ffmpeg's build scripts
ENV TERM xterm

# install necessary container dependencies
RUN apt-get update && apt-get install -y lsb-release && apt-get clean all

# install the build environment
RUN apt-get update && \
    apt-get install -y \
    subversion \
    ragel \
    curl \
    texinfo \
    g++ \
    bison \
    flex \
    cvs \
    yasm \
    automake \
    autogen \
    libtool \
    autoconf \
    gcc \
    cmake \
    git \
    make \
    pkg-config \
    zlib1g-dev \
    mercurial \
    zip \
    unzip \
    pax \
    nasm \
    gperf \
    bzip2 \
    autoconf-archive \
    p7zip-full \
    meson \
    clang \
    python \
    python3-setuptools \
    wget \
    ed

# get the current archive
RUN wget https://codeload.github.com/rdp/ffmpeg-windows-build-helpers/zip/master -O ffmpeg-windows-build-helpers-master.zip

# or copy the helpers from the base directory 
# COPY ffmpeg-windows-build-helpers-master.zip /

# extract the build helper, remove the .zip, 
# run the cross-compile script, then list the artifacts
RUN unzip ffmpeg-windows-build-helpers-master.zip && \
    rm ffmpeg-windows-build-helpers-master.zip && \
    mv ffmpeg-windows-build-helpers-master ffmpeg-windows-build-helpers && \
    cd ffmpeg-windows-build-helpers && \
    ./cross_compile_ffmpeg.sh --compiler-flavors=win32 \
        --build-ffmpeg-shared=y \
        --build-ffmpeg-static=y \
        --disable-nonfree=n \
        --build-intel-qsv=y \
        --enable-gpl=y  && \
    chmod -R 0777 /ffmpeg-windows-build-helpers/sandbox/redist/  

We have a container, but now we must run it. I personally use a run.sh script.


#!/bin/bash

# make a directory for output files and make it writable to all
mkdir -p `pwd`/output && chmod -R 0777 `pwd`/output

# build the Dockerfile into an image
sudo docker build . -f Dockerfile -t ffmpeg-windows-build-helpers-image

# create a new container of an image, and execute the container OR start it if it were stopped
sudo docker run -d --name ffmpegbuilder -it ffmpeg-windows-build-helpers-image || docker start ffmpegbuilder -i

# after it has completed, copy the output back to the host
sudo docker cp ffmpegbuilder:/ffmpeg-windows-build-helpers/sandbox/redist/. `pwd`/output

# stop the container and remove it
sudo docker stop ffmpegbuilder && docker rm ffmpegbuilder && docker image rm -f ffmpeg-windows-build-helpers-image

# remove all unused docker resources (confirming Y)
echo "y" | sudo docker system prune -a

You can run this script using


chmod +x run.sh && ./run.sh

In the output folder, you will see a file named something like ffmpeg-N-100064-g3c922681c3-win32-static.7z and frei0r-plugins-x86-v1.7.0-12-ga312322.7z. Repeat the process for other architectures or better yet, make more containers.