Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

build(ffmpeg): build FFmpeg here, with only the codecs the game opens

Olcay Seyganb9a5c800494c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc5179a3e..b09c54e46 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1126,7 +1126,9 @@ found and fixed — EA's own, not port damage.**
- Sound and movies come from the game itself now. The 2003 sound and video libraries are 32-bit and
cannot be loaded by a 64-bit program at all, so the build carries its own: Windows' own mixer for
sound, and a decoder for the movies that reads the same files the game has always shipped. Nothing
- about what you hear or watch changes, and the two old libraries are no longer in the download.
+ about what you hear or watch changes, and the two old libraries are no longer in the download. The
+ decoder was built for this game and holds only the formats it opens, so it adds 3MB rather than
+ the 123MB a general-purpose one would.
- Your replays still play and your matches still join. The old 32-bit build and this one work out
the same game, to the digit: the same match played by both, 3000 frames of computer against
computer, ends on the same world with the same checksum. That is what the change was measured
diff --git a/GeneralsMD/Code/Tools/ffmpeg-build.bat b/GeneralsMD/Code/Tools/ffmpeg-build.bat
new file mode 100644
index 000000000..79eb3b366
--- /dev/null
+++ b/GeneralsMD/Code/Tools/ffmpeg-build.bat
@@ -0,0 +1,33 @@
+@echo off
+rem Builds FFmpeg for the game: see ffmpeg-build.sh for what goes in it and why.
+rem
+rem Needs MSYS2 with make and nasm:
+rem winget install MSYS2.MSYS2
+rem C:\msys64\usr\bin\bash -lc "pacman -S --noconfirm --needed make nasm diffutils"
+rem
+rem MSVC comes from vcvars64 below and is inherited into the MSYS2 shell, which is what
+rem --toolchain=msvc needs; edit the edition here if this machine has a different one.
+
+setlocal
+set "VCVARS=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
+set "MSYS_BASH=C:\msys64\usr\bin\bash.exe"
+
+if not exist "%VCVARS%" (
+ echo [ffmpeg] ERROR: %VCVARS% not found. Edit this file for your Visual Studio edition.
+ exit /b 1
+)
+if not exist "%MSYS_BASH%" (
+ echo [ffmpeg] ERROR: %MSYS_BASH% not found. Install MSYS2 - see the comment at the top.
+ exit /b 1
+)
+
+call "%VCVARS%" >nul 2>&1
+set "MSYS2_PATH_TYPE=inherit"
+set "CHERE_INVOKING=1"
+
+rem The script's own path, as MSYS2 spells it.
+set "SCRIPT=%~dp0ffmpeg-build.sh"
+set "SCRIPT=%SCRIPT:\=/%"
+set "SCRIPT=/%SCRIPT::=%"
+
+"%MSYS_BASH%" -lc "'%SCRIPT%'"
diff --git a/GeneralsMD/Code/Tools/ffmpeg-build.sh b/GeneralsMD/Code/Tools/ffmpeg-build.sh
new file mode 100644
index 000000000..d4fd220b3
--- /dev/null
+++ b/GeneralsMD/Code/Tools/ffmpeg-build.sh
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+#
+# Builds the FFmpeg the game links against, with the codecs it opens and nothing else.
+#
+# Run it through ffmpeg-build.bat, which supplies the MSVC environment. The result lands in
+# Libraries/Source/FFmpeg/dist, laid out the way CMakeLists.txt expects: include/, lib/*.lib,
+# bin/*.dll. Those DLLs are post-build copied next to generals.exe and are what the payload ships.
+#
+# What the game opens, and therefore all that is built:
+# .bik movies -> bink demuxer, the bink video decoder and both binkaudio decoders
+# .mp3 music -> mp3 demuxer and decoder, mpegaudio parser
+# .wav speech -> wav demuxer, the PCM decoders and the two ADPCM flavours its files use
+# avfilter, avdevice, the programs, the network layer and every other codec are off. A stock
+# general-purpose build of the same version is 123MB of DLLs; this is 3.3MB.
+#
+# The version matters: the library majors decide the DLL names (avcodec-62 and friends), which
+# CMakeLists.txt and launcher/build-payload.js both name.
+set -e
+
+FFMPEG_VERSION=8.1.2
+SOURCE_ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
+DIST="$SOURCE_ROOT/GeneralsMD/Code/Libraries/Source/FFmpeg/dist"
+WORK="${TMPDIR:-/tmp}/zhr-ffmpeg-$FFMPEG_VERSION"
+TARBALL="ffmpeg-$FFMPEG_VERSION.tar.xz"
+
+mkdir -p "$WORK"
+cd "$WORK"
+
+if [ ! -d "ffmpeg-$FFMPEG_VERSION" ]; then
+ [ -f "$TARBALL" ] || curl -fsSL -o "$TARBALL" "https://ffmpeg.org/releases/$TARBALL"
+ tar xf "$TARBALL"
+fi
+cd "ffmpeg-$FFMPEG_VERSION"
+
+# MSYS2's coreutils ships a link.exe that shadows the MSVC linker, and configure cannot find cl's
+# one while it is first on PATH.
+if [ -f /usr/bin/link.exe ]; then
+ mv /usr/bin/link.exe /usr/bin/link-coreutils.exe
+fi
+restore_link() {
+ if [ -f /usr/bin/link-coreutils.exe ]; then
+ mv /usr/bin/link-coreutils.exe /usr/bin/link.exe
+ fi
+}
+trap restore_link EXIT
+
+./configure \
+ --prefix="$WORK/out" \
+ --toolchain=msvc \
+ --arch=x86_64 \
+ --target-os=win64 \
+ --enable-shared \
+ --disable-static \
+ --disable-everything \
+ --disable-autodetect \
+ --disable-programs \
+ --disable-doc \
+ --disable-avdevice \
+ --disable-avfilter \
+ --disable-network \
+ --disable-debug \
+ --enable-swscale \
+ --enable-swresample \
+ --enable-demuxer=bink,mp3,wav \
+ --enable-decoder=bink,binkaudio_dct,binkaudio_rdft,mp3,mp3float,pcm_s16le,pcm_s16be,pcm_u8,pcm_s24le,pcm_s32le,pcm_f32le,adpcm_ima_wav,adpcm_ms \
+ --enable-parser=mpegaudio \
+ --enable-protocol=file
+
+# configure takes an unknown component name without a word. The first build of this asked for a
+# decoder called "binkvideo", which is that decoder's display name rather than the name configure
+# knows it by ("bink"), and produced libraries that could not open a single movie.
+for component in BINK_DECODER BINKAUDIO_DCT_DECODER BINKAUDIO_RDFT_DECODER MP3_DECODER \
+ ADPCM_IMA_WAV_DECODER PCM_S16LE_DECODER BINK_DEMUXER MP3_DEMUXER WAV_DEMUXER \
+ MPEGAUDIO_PARSER FILE_PROTOCOL; do
+ if ! grep -q "^#define CONFIG_${component} 1$" config_components.h; then
+ echo "configure did not enable ${component}" >&2
+ exit 1
+ fi
+done
+
+make -j"$(nproc)"
+make install
+
+# The install puts the import libraries in bin/ next to the DLLs; the build expects them in lib/.
+rm -rf "$DIST"
+mkdir -p "$DIST/bin" "$DIST/lib"
+cp -r "$WORK/out/include" "$DIST/"
+cp "$WORK/out/bin"/*.dll "$DIST/bin/"
+cp "$WORK/out/bin"/*.lib "$DIST/lib/"
+cp COPYING.LGPLv2.1 "$DIST/LICENSE.txt"
+
+echo
+echo "FFmpeg $FFMPEG_VERSION installed into $DIST"
+du -ch "$DIST/bin"/*.dll | tail -1