Build FFMpeg on windows - bryanch/random GitHub Wiki

References

Prerequisites

  • Setup MSYS2 environment (refer to this wiki)

Clone the source

git clone git://source.ffmpeg.org/ffmpeg

Alternative options

Install packages

normal msys2 packages

pacman -S make pkg-config diffutils

mingw-w64 packages and toolchains

pacman -S mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2

Build using MINGW-W64

configure, this step may take quite some minutes

./configure

build, as said in the official instructions, use make -r to speed up the time for re-building

make -r 

Build using MSVC

Refer to the the official instructions, the configure step needs an extra parameter

./configure --toolchain=msvc

Build with GPU acceleration support

Reference the official instructions

  1. Download and install the CUDA toolkit
  2. Install Microsoft Visual Studio VC tools
  3. Open a VC Command Prompt (e.g. "x64 Native Tools Command Prompt for VS 2019"), add two paths
    set INCLUDE=%INCLUDE%;%CUDA_PATH%\include
    set LIB=%LIB%;%CUDA_PATH%\lib\x64
    
  4. Open MSYS shell by executing the msys_shell.bat
  5. Clone and enable ffnvcodec header
    git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
    cd nv-codec-headers
    make
    make install PREFIX=/usr
    
  6. configure including CUDA headers
    cd ~/ffmpeg
    ./configure --toolchain=msvc --arch=x86_64 --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp 
    
  7. make
    make -j 10