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