Skip to content

Commit 1536d68

Browse files
build system
1 parent 5d18b85 commit 1536d68

3 files changed

Lines changed: 338 additions & 0 deletions

File tree

.github/workflows/build.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Build FFmpeg
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
schedule:
12+
- cron: "0 0 * * *"
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
16+
17+
jobs:
18+
build:
19+
strategy:
20+
matrix:
21+
os:
22+
- ubuntu-22.04
23+
- ubuntu-22.04-arm
24+
- windows-2022
25+
- macos-13 # x86_64
26+
- macos-15 # ARM64
27+
runs-on: ${{ matrix.os }}
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Install dependencies (Ubuntu)
33+
if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm'
34+
# Using meson from pip because the version in the Ubuntu 22.04 repository is too old
35+
run: |
36+
sudo apt-get update && sudo apt-get install -y git build-essential nasm yasm cmake ninja-build pkg-config
37+
pip3 install --user meson
38+
39+
- name: Install dependencies (macOS)
40+
if: matrix.os == 'macos-15' || matrix.os == 'macos-13'
41+
run: brew install git nasm yasm cmake make meson ninja pkg-config autoconf automake libtool autogen
42+
43+
- name: Install dependencies (Windows)
44+
if: matrix.os == 'windows-2022'
45+
uses: msys2/setup-msys2@v2
46+
with:
47+
msystem: 'MINGW64'
48+
update: true
49+
install: git mingw-w64-x86_64-gcc nasm yasm mingw-w64-x86_64-cmake mingw-w64-x86_64-meson ninja pkg-config perl make mingw-w64-x86_64-autotools autoconf-archive libtool
50+
51+
- name: Build FFmpeg Windows
52+
if: matrix.os == 'windows-2022'
53+
shell: msys2 {0}
54+
run: sh build.sh
55+
56+
- name: Build FFmpeg Linux/macOS
57+
if: matrix.os != 'windows-2022'
58+
run: sh build.sh
59+
60+
- name: Upload artifact
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: "ffmpeg-build-${{ matrix.os }}"
64+
path: "*.tar.gz"
65+
if-no-files-found: ignore
66+
67+
release:
68+
name: Release
69+
needs: [ build ]
70+
runs-on: ubuntu-24.04
71+
if: ${{ github.event_name != 'pull_request' }}
72+
permissions:
73+
contents: write
74+
steps:
75+
- uses: actions/checkout@v4
76+
77+
- name: Download Artifacts
78+
uses: actions/download-artifact@v4
79+
with:
80+
path: artifacts/
81+
82+
- name: Move Artifacts
83+
run: |
84+
set -eo pipefail
85+
mkdir -p upload
86+
find artifacts/ -type f -exec mv {} $(pwd)/upload/ \;
87+
rm -rf artifacts/
88+
89+
- uses: ncipollo/release-action@v1
90+
with:
91+
artifacts: upload/*
92+
makeLatest: true
93+
allowUpdates: true
94+
name: Auto-Release ${{ github.run_id }}
95+
body: |
96+
This is an auto-release of ffmpeg.
97+
Triggered by ${{ github.event_name }}
98+
[View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
99+
tag: latest
100+
replacesArtifacts: true
101+
102+
- uses: ncipollo/release-action@v1
103+
with:
104+
artifacts: upload/*
105+
makeLatest: false
106+
allowUpdates: true
107+
name: Auto-Release ${{ github.run_id }}
108+
body: |
109+
This is an auto-release of ffmpeg.
110+
Triggered by ${{ github.event_name }}
111+
[View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
112+
tag: auto-release-${{ github.run_id }}
113+
replacesArtifacts: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

build.sh

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Define directories
5+
HOME_DIR=~
6+
BUILD_DIR="$HOME_DIR/ffmpeg_build"
7+
DEPS_DIR="$HOME_DIR/deps"
8+
SRC_DIR=$(pwd)
9+
10+
# Clean up existing directories
11+
rm -rf "$BUILD_DIR" "$DEPS_DIR"
12+
mkdir -p "$BUILD_DIR" "$DEPS_DIR"
13+
14+
# Detect ARTIFACT_OS
15+
OS=$(uname -s)
16+
case "$OS" in
17+
Linux*) ARTIFACT_OS="Linux" ;;
18+
Darwin*) ARTIFACT_OS="macOS" ;;
19+
CYGWIN*|MINGW*|MSYS*) ARTIFACT_OS="Windows" ;;
20+
*) echo "Unsupported OS: $OS"; exit 1 ;;
21+
esac
22+
23+
# Detect ARCH
24+
ARCH=$(uname -m)
25+
case "$ARCH" in
26+
x86_64|amd64) ARCH="x86_64" ;;
27+
aarch64|arm64) ARCH="arm64" ;;
28+
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
29+
esac
30+
31+
# Set environment variable for pkg-config
32+
export PKG_CONFIG_PATH="$DEPS_DIR/lib/aarch64-linux-gnu/pkgconfig:$DEPS_DIR/lib/x86_64-linux-gnu/pkgconfig:$DEPS_DIR/lib/pkgconfig"
33+
34+
# Get CPU count
35+
if [ "$ARTIFACT_OS" = "macOS" ]; then
36+
CPU_COUNT=$(sysctl -n hw.ncpu)
37+
else
38+
CPU_COUNT=$(nproc)
39+
fi
40+
[ -z "$CPU_COUNT" ] && CPU_COUNT=4
41+
echo "CPU count: $CPU_COUNT"
42+
echo "Detected ARTIFACT_OS: $ARTIFACT_OS, ARCH: $ARCH"
43+
44+
# Helper function to run commands
45+
run_cmd() {
46+
echo "Running: $1"
47+
bash -c "$1"
48+
}
49+
50+
# Function to build Autotools-based dependencies
51+
build_autotools_dep() {
52+
repo=$1
53+
dir_name=$2
54+
configure_cmd=$3
55+
run_before_conf_cmd=$4
56+
57+
echo "Building $dir_name with Autotools"
58+
run_cmd "git clone --depth 1 $repo $dir_name"
59+
cd "$SRC_DIR/$dir_name"
60+
if [ -n "$run_before_conf_cmd" ]; then
61+
echo "Running pre-configure command for $dir_name"
62+
run_cmd "$run_before_conf_cmd"
63+
fi
64+
if [ -f "autogen.sh" ]; then
65+
run_cmd "sh autogen.sh"
66+
fi
67+
run_cmd "$configure_cmd"
68+
run_cmd "make -j$CPU_COUNT"
69+
run_cmd "make install"
70+
cd "$SRC_DIR"
71+
}
72+
73+
# Function to build Meson-based dependencies
74+
build_meson_dep() {
75+
repo=$1
76+
dir_name=$2
77+
meson_cmd=$3
78+
79+
echo "Building $dir_name with Meson"
80+
run_cmd "git clone --depth 1 $repo $dir_name"
81+
cd "$SRC_DIR/$dir_name"
82+
run_cmd "$meson_cmd"
83+
run_cmd "ninja -Cbuild"
84+
run_cmd "ninja -Cbuild install"
85+
cd "$SRC_DIR"
86+
}
87+
88+
echo "Building for $ARTIFACT_OS ($ARCH)"
89+
90+
# Build dependencies in order
91+
92+
### 1. zlib
93+
build_autotools_dep "https://github.com/madler/zlib.git" "zlib" "sh ./configure --prefix=$DEPS_DIR --static CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
94+
95+
### 2. OpenSSL
96+
if [ "$ARTIFACT_OS" = "Windows" ]; then
97+
config="mingw64"
98+
elif [ "$ARTIFACT_OS" = "macOS" ]; then
99+
if [ "$ARCH" = "arm64" ]; then
100+
config="darwin64-arm64-cc"
101+
else
102+
config="darwin64-x86_64-cc"
103+
fi
104+
elif [ "$ARTIFACT_OS" = "Linux" ]; then
105+
if [ "$ARCH" = "arm64" ]; then
106+
config="linux-aarch64"
107+
else
108+
config="linux-x86_64"
109+
fi
110+
else
111+
echo "Unsupported OS: $ARTIFACT_OS"
112+
exit 1
113+
fi
114+
openssl_configure="perl ./Configure $config --prefix=$DEPS_DIR --openssldir=$DEPS_DIR/ssl no-shared no-docs no-tests"
115+
build_autotools_dep "https://github.com/openssl/openssl.git" "openssl" "$openssl_configure"
116+
117+
### 3. freetype2
118+
build_meson_dep "https://gitlab.freedesktop.org/freetype/freetype.git" "freetype" "meson setup build --prefix=$DEPS_DIR --default-library=static"
119+
120+
### 4. harfbuzz
121+
build_meson_dep "https://github.com/harfbuzz/harfbuzz.git" "harfbuzz" "meson setup build --prefix=$DEPS_DIR --default-library=static"
122+
123+
### 5. fribidi
124+
build_meson_dep "https://github.com/fribidi/fribidi.git" "fribidi" "meson setup build --prefix=$DEPS_DIR --default-library=static -Ddocs=false"
125+
126+
### 6. libass
127+
build_meson_dep "https://github.com/libass/libass.git" "libass" "meson setup build --prefix=$DEPS_DIR --default-library=static"
128+
129+
### 7. libfdk-aac
130+
build_autotools_dep "https://github.com/mstorsjo/fdk-aac.git" "fdk-aac" "sh autogen.sh && ./configure --prefix=$DEPS_DIR --enable-static --disable-shared CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
131+
132+
### 8. libmp3lame
133+
build_autotools_dep "https://github.com/lameproject/lame.git" "lame" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-shared --enable-nasm --disable-gtktest --disable-frontend CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
134+
135+
### 9. libopus
136+
build_autotools_dep "https://github.com/xiph/opus.git" "opus" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-shared CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
137+
138+
### 10. libogg
139+
build_autotools_dep "https://github.com/xiph/ogg.git" "ogg" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-shared CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
140+
141+
### 11. libvorbis
142+
if [ "$ARTIFACT_OS" = "macOS" ]; then
143+
patch_configure="sed -i '' 's/ -force_cpusubtype_ALL//g' configure.ac"
144+
else
145+
patch_configure=""
146+
fi
147+
build_autotools_dep "https://gitlab.xiph.org/xiph/vorbis.git" "vorbis" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-shared --with-ogg=$DEPS_DIR CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\"" "$patch_configure"
148+
149+
### 12. libvpx
150+
build_autotools_dep "https://github.com/webmproject/libvpx.git" "libvpx" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-shared"
151+
152+
### 13. libx264
153+
build_autotools_dep "https://code.videolan.org/videolan/x264.git" "x264" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-opencl --disable-bashcompletion --extra-cflags=\"-fPIC\" CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
154+
155+
### 14. libx265
156+
echo "Building x265"
157+
run_cmd "git clone https://bitbucket.org/multicoreware/x265_git.git x265"
158+
if [ "$ARTIFACT_OS" = "Windows" ]; then
159+
build_dir="build/linux"
160+
cmake_cmd="cmake -G \"MSYS Makefiles\" ../../source && cmake ../../source -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=$DEPS_DIR CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
161+
elif [ "$ARTIFACT_OS" = "Linux" ] && [ "$ARCH" = "arm64" ]; then
162+
build_dir="build/aarch64-linux"
163+
cmake_cmd="cmake ../../source -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DENABLE_SVE2=OFF -DCMAKE_INSTALL_PREFIX=$DEPS_DIR CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
164+
elif [ "$ARTIFACT_OS" = "macOS" ] && [ "$ARCH" = "arm64" ]; then
165+
build_dir="build/aarch64-darwin"
166+
cmake_cmd="cmake ../../source -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=$DEPS_DIR CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
167+
elif [ "$ARTIFACT_OS" = "macOS" ]; then
168+
build_dir="build/linux"
169+
cmake_cmd="cmake ../../source -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DENABLE_ASSEMBLY=OFF -DCMAKE_INSTALL_PREFIX=$DEPS_DIR CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
170+
else
171+
build_dir="build/linux"
172+
cmake_cmd="cmake ../../source -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=$DEPS_DIR CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
173+
fi
174+
x265_dir="$SRC_DIR/x265/$build_dir"
175+
mkdir -p "$x265_dir"
176+
cd "$x265_dir"
177+
run_cmd "$cmake_cmd"
178+
run_cmd "make -j$CPU_COUNT"
179+
run_cmd "make install"
180+
cd "$SRC_DIR"
181+
182+
### 15. libaom
183+
echo "Building libaom"
184+
run_cmd "git clone https://aomedia.googlesource.com/aom aom"
185+
aom_build_dir="$SRC_DIR/aom_build"
186+
mkdir -p "$aom_build_dir"
187+
cd "$aom_build_dir"
188+
run_cmd "cmake ../aom -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DENABLE_TESTS=0 -DENABLE_DOCS=0 CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\" -DCMAKE_INSTALL_PREFIX=$DEPS_DIR"
189+
run_cmd "cmake --build . -j$CPU_COUNT"
190+
run_cmd "cmake --install ."
191+
cd "$SRC_DIR"
192+
193+
### 16. libwebp
194+
build_autotools_dep "https://github.com/webmproject/libwebp.git" "libwebp" "sh ./configure --prefix=$DEPS_DIR --enable-static --disable-shared CFLAGS=\"-fPIC\" CXXFLAGS=\"-fPIC\""
195+
196+
### 17. libdav1d
197+
build_meson_dep "https://code.videolan.org/videolan/dav1d.git" "dav1d" "meson setup build --prefix=$DEPS_DIR --default-library=static"
198+
199+
# Function to build FFmpeg
200+
build_ffmpeg() {
201+
version=$1
202+
branch=$2
203+
echo "Building FFmpeg $version"
204+
ffmpeg_dir="$SRC_DIR/ffmpeg-$version"
205+
build_dir_version="$BUILD_DIR/ffmpeg-$version"
206+
mkdir -p "$build_dir_version"
207+
run_cmd "git clone --depth 1 --branch $branch https://github.com/FFmpeg/FFmpeg.git ffmpeg-$version"
208+
cd "$ffmpeg_dir"
209+
configure_cmd="./configure --prefix=$build_dir_version --disable-static --enable-shared --pkg-config-flags=\"--static\" --extra-cflags=\"-I$DEPS_DIR/include\" --extra-ldflags=\"-L$DEPS_DIR/lib\" --enable-gpl --enable-nonfree --enable-version3 --enable-openssl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libaom --enable-libwebp --enable-zlib --disable-autodetect"
210+
run_cmd "$configure_cmd"
211+
run_cmd "make -j$CPU_COUNT"
212+
run_cmd "make install"
213+
artifact_name="ffmpeg-$version-$ARTIFACT_OS-$ARCH.tar.gz"
214+
echo "Creating artifact: $artifact_name"
215+
run_cmd "tar -czf $SRC_DIR/$artifact_name -C $build_dir_version ."
216+
cd "$SRC_DIR"
217+
}
218+
219+
# Build FFmpeg versions
220+
build_ffmpeg "7.1" "release/7.1"
221+
build_ffmpeg "6.1" "release/6.1"
222+
build_ffmpeg "master" "master"
223+
224+
echo "Build completed successfully"

0 commit comments

Comments
 (0)