Compiling FFMPEG with x264 support on Windows requires additionnal steps. This article follows the previous article: How to compile FFMPEG for Windows 11, so make sure to follow the previous steps before continuing.
NASM vs YASM
I’m not totally sure why, but I haven’t been able to compile x264 with yasm, so I had to install nasm. However, when I tried to compile FFMPEG with nasm installed, the compilation hanged. So I had to uninstall nasm to get back to yasm.
The trick is: install nasm, compile x264, uninstall nasm.
Prerequisites
First, follow the steps in this article to make sure you can compile a basic version of FFMPEG: How to compile FFMPEG for Windows 11
All the following steps are executed In the MSYS2 console.
Compile x264
Install nasm
pacman -S nasm
Download and compile x264:
cd ~
git clone http://git.videolan.org/git/x264.git
cd x264
CC=cl ./configure --enable-static --prefix=./installed
make
make install
Uninstall nasm
pacman -R nasm
Compile FFMPEG
Next, you must download and compile FFMPEG. You must enable x264 and specify the path:
cd ~
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg_x64
cd ffmpeg_x64
make clean
PKG_CONFIG_PATH="/home/<user>/x264/installed/lib/pkgconfig"
CC=cl ./configure --target-os=win64 --arch=x86_64 --toolchain=msvc --enable-shared --enable-gpl --enable-libx264 --extra-ldflags="-LIBPATH:../x264/installed/lib/" --extra-cflags="-I../x264/installed/include/"
make
make install
The FFmpeg output will be located in C:\msys64\home\<user>\ffmpeg_x64
Notes:
If the compilation hangs on the following line:
Creating library libavcodec/avcodec.lib and object libavcodec/avcodec.exp
This means you faced the compilation problem with nasm. Make sure to uninstall nasm before compiling FFMPEG.
Getting this linker hang even without nasm installed 🙁