Last active
May 15, 2025 07:19
-
-
Save CypherpunkSamurai/ea41ba810ece339656e011d48a964daf to your computer and use it in GitHub Desktop.
Msys2 FFmpeg 7.1 Build Script Using Shell Script Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# FFmpeg build script based on MSYS2/MinGW-w64 PKGBUILD | |
# Variables | |
FFMPEG_VERSION="7.1.1" | |
BUILD_DIR="$(pwd)/ffmpeg-build" | |
INSTALL_DIR="/opt/ffmpeg" # Change this to your preferred installation directory | |
CORES=$(nproc) | |
# Create build directory | |
mkdir -p "${BUILD_DIR}" | |
cd "${BUILD_DIR}" | |
# Install required headers | |
# IGNORE THIS (was found with BUILD testing): | |
# pacman -S --noconfirm mingw-w64-x86_64-frei0r-plugins mingw-w64-x86_64-gnutls mingw-w64-x86_64-aom mingw-w64-x86_64-libass mingw-w64-x86_64-libbluray mingw-w64-x86_64-libcaca mingw-w64-x86_64-dav1d mingw-w64-x86_64-libgme mingw-w64-x86_64-gsm mingw-w64-x86_64-libjxl mingw-w64-x86_64-liblc3 mingw-w64-x86_64-libvpl mingw-w64-x86_64-libmodplug mingw-w64-x86_64-opencore-amr mingw-w64-x86_64-openjpeg2 mingw-w64-x86_64-opus mingw-w64-x86_64-libplacebo mingw-w64-x86_64-vulkan-headers | |
# THIS IS REAL LIST: | |
pacman -S --noconfirm mingw-w64-x86_64-amf-headers mingw-w64-x86_64-autotools mingw-w64-x86_64-cc mingw-w64-x86_64-dlfcn mingw-w64-x86_64-ffnvcodec-headers mingw-w64-x86_64-nasm mingw-w64-x86_64-pkgconf mingw-w64-x86_64-vulkan-headers | |
pacman -S --noconfirm mingw-w64-x86_64-aom mingw-w64-x86_64-bzip2 mingw-w64-x86_64-dav1d mingw-w64-x86_64-fontconfig mingw-w64-x86_64-freetype mingw-w64-x86_64-frei0r-plugins mingw-w64-x86_64-fribidi mingw-w64-x86_64-gmp mingw-w64-x86_64-gnutls mingw-w64-x86_64-gsm mingw-w64-x86_64-harfbuzz mingw-w64-x86_64-lame mingw-w64-x86_64-libass mingw-w64-x86_64-libbluray mingw-w64-x86_64-libcaca mingw-w64-x86_64-libexif mingw-w64-x86_64-libgme mingw-w64-x86_64-libiconv mingw-w64-x86_64-libjxl mingw-w64-x86_64-liblc3 mingw-w64-x86_64-libmodplug mingw-w64-x86_64-libplacebo mingw-w64-x86_64-librsvg mingw-w64-x86_64-libsoxr mingw-w64-x86_64-libssh mingw-w64-x86_64-libtheora mingw-w64-x86_64-libva mingw-w64-x86_64-libvorbis mingw-w64-x86_64-libvpl mingw-w64-x86_64-libvpx mingw-w64-x86_64-libwebp mingw-w64-x86_64-libx264 mingw-w64-x86_64-libxml2 mingw-w64-x86_64-openal mingw-w64-x86_64-opencore-amr mingw-w64-x86_64-openjpeg2 mingw-w64-x86_64-opus mingw-w64-x86_64-rav1e mingw-w64-x86_64-rtmpdump mingw-w64-x86_64-SDL2 mingw-w64-x86_64-speex mingw-w64-x86_64-srt mingw-w64-x86_64-svt-av1 mingw-w64-x86_64-vid.stab mingw-w64-x86_64-vulkan mingw-w64-x86_64-x265 mingw-w64-x86_64-xvidcore mingw-w64-x86_64-zimg mingw-w64-x86_64-zlib mingw-w64-x86_64-zvbi | |
# Download source | |
echo "Downloading FFmpeg ${FFMPEG_VERSION}..." | |
wget "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" | |
tar xf "ffmpeg-${FFMPEG_VERSION}.tar.xz" | |
# Download patches | |
wget "https://raw.githubusercontent.com/msys2/MINGW-packages/master/mingw-w64-ffmpeg/pathtools.c" | |
wget "https://raw.githubusercontent.com/msys2/MINGW-packages/master/mingw-w64-ffmpeg/pathtools.h" | |
wget "https://raw.githubusercontent.com/msys2/MINGW-packages/master/mingw-w64-ffmpeg/0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch" | |
wget "https://github.com/FFmpeg/FFmpeg/commit/d1ed5c06e3edc5f2b5f3664c80121fa55b0baa95.patch" | |
# Prepare sources | |
cd "ffmpeg-${FFMPEG_VERSION}" | |
cp -f "../pathtools.c" "../pathtools.h" libavfilter/ | |
# Apply patches | |
echo "Applying patches..." | |
patch -Nbp1 -i "../0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch" | |
patch -Nbp1 -i "../d1ed5c06e3edc5f2b5f3664c80121fa55b0baa95.patch" | |
# Define common configuration options | |
COMMON_CONFIG=( | |
--disable-debug | |
--disable-stripping | |
--disable-doc | |
--enable-dxva2 | |
--enable-d3d11va | |
--enable-d3d12va | |
--enable-frei0r | |
--enable-gmp | |
--enable-gnutls | |
--enable-gpl | |
--enable-iconv | |
--enable-libaom | |
--enable-libass | |
--enable-libbluray | |
--enable-libcaca | |
--enable-libdav1d | |
--enable-libfontconfig | |
--enable-libfreetype | |
--enable-libfribidi | |
--enable-libgme | |
--enable-libgsm | |
--enable-libharfbuzz | |
--enable-libjxl | |
--enable-libmodplug | |
--enable-libmp3lame | |
--enable-libopencore_amrnb | |
--enable-libopencore_amrwb | |
--enable-libopenjpeg | |
--enable-libopus | |
--enable-librtmp | |
--enable-libssh | |
--enable-libsoxr | |
--enable-libspeex | |
--enable-libsrt | |
--enable-libtheora | |
--enable-libvidstab | |
--enable-libvorbis | |
--enable-libx264 | |
--enable-libx265 | |
--enable-libxvid | |
--enable-libvpx | |
--enable-libwebp | |
--enable-libxml2 | |
--enable-libzimg | |
--enable-libzvbi | |
--enable-openal | |
--enable-pic | |
--enable-postproc | |
--enable-runtime-cpudetect | |
--enable-swresample | |
--enable-version3 | |
--enable-vulkan | |
--enable-zlib | |
--enable-libvpl | |
) | |
# Architecture-specific options | |
ARCH=$(uname -m) | |
if [[ "${ARCH}" != "i686" ]]; then | |
COMMON_CONFIG+=( | |
--enable-liblc3 | |
--enable-libplacebo | |
--enable-librav1e | |
--enable-librsvg | |
--enable-libsvtav1 | |
) | |
fi | |
# Check if we're not on ARM64 | |
if [[ "${ARCH}" != "aarch64" ]]; then | |
COMMON_CONFIG+=( | |
--enable-amf | |
--enable-nvenc | |
) | |
fi | |
# Build both static and shared versions | |
for VARIANT in static shared; do | |
echo "Building ${VARIANT} variant..." | |
mkdir -p "../build-${VARIANT}" | |
cd "../build-${VARIANT}" | |
if [[ ${VARIANT} == "static" ]]; then | |
ENABLE_VARIANT="--enable-static --pkg-config-flags=--static" | |
else | |
ENABLE_VARIANT="--enable-shared" | |
fi | |
"../ffmpeg-${FFMPEG_VERSION}/configure" \ | |
--prefix="${INSTALL_DIR}" \ | |
--target-os=mingw32 \ | |
--arch="${ARCH%%-*}" \ | |
"${COMMON_CONFIG[@]}" \ | |
--logfile=config.log \ | |
${ENABLE_VARIANT} | |
make -j${CORES} | |
# Run tests (optional, may fail) | |
echo "Running tests for ${VARIANT} variant..." | |
make check || true | |
cd "../ffmpeg-${FFMPEG_VERSION}" | |
done | |
# Install | |
echo "Installing FFmpeg..." | |
cd "../build-shared" | |
make DESTDIR="${INSTALL_DIR}" install | |
cd "../build-static" | |
make DESTDIR="${INSTALL_DIR}" install | |
echo "FFmpeg ${FFMPEG_VERSION} has been built and installed to ${INSTALL_DIR}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Installation | |
# iwr -useb https://raw.githubusercontent.com/CypherpunkSamurai/portable-windows-installers/refs/heads/master/msys2_portable.ps1 | iex | |
pacman -S --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-clang make yasm pkg-config autotools mingw-w64-x86_64-autotools | |
pacman -S --noconfirm --needed mingw-w64-x86_64-fdk-aac mingw-w64-x86_64-lame mingw-w64-x86_64-libvpx mingw-w64-x86_64-libx264 mingw-w64-x86_64-x265 mingw-w64-x86_64-ffnvcodec-headers | |
pacman -S --noconfirm --needed base-devel texinfo | |
# or use the dependencies (and build dependencies) list from when configuring build: https://packages.msys2.org/packages/mingw-w64-x86_64-ffmpeg | |
wget "https://ffmpeg.org/releases/ffmpeg-7.0.tar.gz" | |
tar --force-local -xf ffmpeg-7.0.tar.gz | |
wget https://gist.githubusercontent.com/CypherpunkSamurai/1e0120dae3aaadeb4121031f2c075250/raw/ffmpeg_windows_build_patch.patch -O w.patch | |
# Patch | |
cd ffmpeg-7.0 | |
# go-astiav | |
# https://gist.github.com/CypherpunkSamurai/1e0120dae3aaadeb4121031f2c075250 | |
# not working command: | |
# sed -i 's/$(AR) $(ARFLAGS) $(AR_O) \(.*\)/$(file > objs.txt, \1)\n\t$(AR) $(ARFLAGS) $(AR_O) @objs.txt/' ffbuild/library.mak | |
# use patch | |
patch -p1 --verbose < ../w.patch | |
# Build | |
# https://doc.qt.io/qt-6/qtmultimedia-building-ffmpeg-windows.html | |
echo 'Current Folder : ' $(pwd) | |
mkdir -p build && cd build | |
mkdir install | |
# install manually as we set --prefix=./install we could have set --prefix=/usr/local for mingw64 installation that is pkg-config compatible | |
# https://trac.ffmpeg.org/wiki/CompilationGuide/MSVC#libx264 --enable-shared is required for h264 encoder | |
# ../configure --prefix=./install --disable-doc --enable-network --enable-shared | |
../configure \ | |
--prefix=./install \ | |
--disable-doc \ | |
--enable-gpl \ | |
--enable-nonfree \ | |
--enable-libx264 \ | |
--enable-libx265 \ | |
--enable-libvpx \ | |
--enable-libmp3lame \ | |
--enable-libfdk-aac \ | |
--enable-openssl \ | |
--enable-sdl2 \ | |
--enable-cuda \ | |
--enable-nvenc \ | |
--enable-avdevice \ | |
--enable-avfilter \ | |
--enable-swscale \ | |
--enable-swresample \ | |
--enable-shared \ | |
--disable-static | |
# make V=1 check VERBOSE=t | |
# build and install later | |
# make -j | |
# make install | |
# or (-j is number of paralell workers) | |
make -j$(nproc) install | |
# copy the built | |
cp -r ./install/* /mingw64 | |
# check using pkg-config --cflags --libs libavformat libavutil | |
# pkg-config --cflags --libs libavformat libavutil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacman -S --noconfirm --needed git zsh make diffutils patchutils grep which wget curl mingw-w64-x86_64-toolchain base-devel | |
pacman -S --noconfirm --needed make yasm pkg-config autotools mingw-w64-x86_64-autotools | |
pacman -S --noconfirm --needed mingw-w64-x86_64-clang | |
pacman -S --noconfirm --needed mingw-w64-x86_64-bat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://gist.github.com/CypherpunkSamurai/b91cce81e7763255da5ec6d59351b036 | |
# https://gist.github.com/CypherpunkSamurai/1e0120dae3aaadeb4121031f2c075250 | |
# code was created from workflow file (https://github.com/asticode/go-astiav/blob/bc148523bc707cb628df76f2811c579d8b69ce9b/.github/workflows/test.yml) | |
# and patch (https://github.com/asticode/go-astiav/blob/bc148523bc707cb628df76f2811c579d8b69ce9b/.github/workflows/windows.patch) | |
# and makefile (https://github.com/asticode/go-astiav/blob/bc148523bc707cb628df76f2811c579d8b69ce9b/Makefile) | |
# Or install PRE BUILD FFMPEG: | |
# https://packages.msys2.org/packages/mingw-w64-x86_64-ffmpeg | |
# pacman -S mingw-w64-x86_64-ffmpeg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment