forked from System233/ffmpeg-msvc-prebuilt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·223 lines (184 loc) · 7.25 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·223 lines (184 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
# Copyright (c) 2024 System233
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
HELP_MSG="Usage: build.sh <x86,amd64,arm,arm64> [static,shared] [gpl,lgpl] ...FF_ARGS"
set -e
source ./env.sh
if [ -z $BUILD_ARCH ]; then
echo "$HELP_MSG" >&2
exit 1
fi
shift 3 || true
FF_ARGS=$@
for dep in libharfbuzz libfreetype sdl libjxl libvpx libwebp libass; do
# Use sed to detect the option as grep might fail in some envs or with CRLF
if [ -n "$(sed -n "/enable-${dep}/p" FFmpeg/configure | head -n 1)" ]; then
export ENABLE_${dep^^}=1
echo "Detected enabled dependency: $dep"
else
echo "Dependency $dep NOT found in configure"
fi
done
echo BUILD_ARCH=$BUILD_ARCH
echo BUILD_TYPE=$BUILD_TYPE
echo BUILD_LICENSE=$BUILD_LICENSE
echo FF_ARGS=$FF_ARGS
add_ffargs() {
FF_ARGS="$FF_ARGS $@"
}
apply-patch() {
GIT_CMD="git -C $1 apply $(pwd)/patches/$2 --ignore-whitespace"
if ! $GIT_CMD -R --check 2>/dev/null; then
echo Apply $2 for $1
$GIT_CMD
else
echo Skip $2 for $1
fi
}
apply-patch zlib zlib.patch
if [ -f "FFmpeg/libavfilter/textutils.c" ] && ! grep -q 'include "libavutil/time_internal.h"' "FFmpeg/libavfilter/textutils.c"; then
apply-patch FFmpeg ffmpeg.patch
fi
apply-patch harfbuzz harfbuzz.patch
./build-make-dep.sh nv-codec-headers
if [ "$BUILD_TYPE" == "static" ]; then
ZLIB_OPTS="-DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_STATIC=ON"
else
ZLIB_OPTS="-DZLIB_BUILD_SHARED=ON -DZLIB_BUILD_STATIC=OFF"
fi
./build-cmake-dep.sh zlib -DZLIB_BUILD_EXAMPLES=OFF $ZLIB_OPTS
if [ ! -f "$INSTALL_PREFIX/lib/zlib.lib" ]; then
# Fallback: find any zlib*.lib or zlib*.a or libz*.a and copy it
# We search recursively in case it is deeply nested.
ZLIB_CACHED_LIB=$(find "$INSTALL_PREFIX" -name "zlib*.lib" -o -name "zlib*.a" -o -name "libz*.a" -o -name "z.lib" | head -n 1)
if [ -n "$ZLIB_CACHED_LIB" ]; then
echo "[DEBUG] Found zlib lib candidate: $ZLIB_CACHED_LIB"
cp "$ZLIB_CACHED_LIB" "$INSTALL_PREFIX/lib/zlib.lib"
else
echo "Error: zlib library not found in $INSTALL_PREFIX"
fi
fi
add_ffargs "--enable-zlib"
if [ -n "$ENABLE_LIBFREETYPE" ]; then
./build-cmake-dep.sh freetype
add_ffargs "--enable-libfreetype"
fi
if [ -n "$ENABLE_LIBHARFBUZZ" ]; then
./build-cmake-dep.sh harfbuzz -DHB_HAVE_FREETYPE=ON
add_ffargs "--enable-libharfbuzz"
fi
if [ -n "$ENABLE_LIBASS" ]; then
./build-libass.sh
# Rename/copy static libs for MSVC
if [ -f "$INSTALL_PREFIX/lib/libfribidi.a" ]; then
cp "$INSTALL_PREFIX/lib/libfribidi.a" "$INSTALL_PREFIX/lib/fribidi.lib"
fi
if [ -f "$INSTALL_PREFIX/lib/libass.a" ]; then
cp "$INSTALL_PREFIX/lib/libass.a" "$INSTALL_PREFIX/lib/ass.lib"
cp "$INSTALL_PREFIX/lib/libass.a" "$INSTALL_PREFIX/lib/libass.lib"
fi
add_ffargs "--enable-libass"
fi
if [ -n "$ENABLE_SDL" ]; then
./build-cmake-dep.sh SDL -DSDL_LIBC=ON -DCMAKE_SHARED_LINKER_FLAGS="/defaultlib:libcmt.lib /defaultlib:libvcruntime.lib /defaultlib:libucrt.lib"
add_ffargs "--enable-sdl"
fi
if [ -n "$ENABLE_LIBJXL" ]; then
if [ "$BUILD_TYPE" == "shared" ]; then
JPEGXL_STATIC=OFF
else
JPEGXL_STATIC=ON
fi
apply-patch libjxl libjxl.patch
./build-cmake-dep.sh openexr -DOPENEXR_INSTALL_TOOLS=OFF -DOPENEXR_BUILD_TOOLS=OFF -DBUILD_TESTING=OFF -DOPENEXR_IS_SUBPROJECT=ON
./build-cmake-dep.sh libjxl -DBUILD_TESTING=OFF -DJPEGXL_ENABLE_BENCHMARK=OFF -DJPEGXL_ENABLE_JNI=OFF -DJPEGXL_BUNDLE_LIBPNG=OFF -DJPEGXL_ENABLE_TOOLS=OFF -DJPEGXL_ENABLE_EXAMPLES=OFF -DJPEGXL_STATIC=$JPEGXL_STATIC
add_ffargs "--enable-libjxl"
fi
if [ -n "$ENABLE_LIBVPX" ]; then
case $BUILD_ARCH in
amd64) libvpx_target=x86_64-win64-vs17 ;;
x86) libvpx_target=x86-win32-vs17 ;;
arm) libvpx_target=armv7-win32-vs17 ;;
arm64) libvpx_target=arm64-win64-vs17 ;;
esac
LIBVPX_ARGS="--enable-static-msvcrt"
apply-patch libvpx libvpx.patch
if [[ "$BUILD_ARCH" == "arm" || "$BUILD_ARCH" == "arm64" ]]; then
VPX_AS_FLAGS="--as=auto"
VPX_AS_VAL=""
else
VPX_AS_FLAGS="--as=yasm"
VPX_AS_VAL="yasm"
fi
env CFLAGS="" AS="$VPX_AS_VAL" AR=lib ARFLAGS= CC=cl CXX=cl LD=link STRIP=false target= ./build-make-dep.sh libvpx --target=$libvpx_target $VPX_AS_FLAGS --disable-optimizations --disable-dependency-tracking --disable-runtime-cpu-detect --disable-thumb --disable-neon --enable-external-build --disable-unit-tests --disable-decode-perf-tests --disable-encode-perf-tests --disable-tools --disable-examples $LIBVPX_ARGS
# Fix vpx.lib missing for shared/static builds
if [ -f "$INSTALL_PREFIX/lib/vpxmt.lib" ]; then
cp "$INSTALL_PREFIX/lib/vpxmt.lib" "$INSTALL_PREFIX/lib/vpx.lib"
elif [ -f "$INSTALL_PREFIX/lib/vpxmd.lib" ]; then
cp "$INSTALL_PREFIX/lib/vpxmd.lib" "$INSTALL_PREFIX/lib/vpx.lib"
elif [ -f "$INSTALL_PREFIX/lib/vpx.dll.lib" ]; then
cp "$INSTALL_PREFIX/lib/vpx.dll.lib" "$INSTALL_PREFIX/lib/vpx.lib"
fi
if [ ! -f "$INSTALL_PREFIX/lib/pkgconfig/vpx.pc" ]; then
echo "Generating vpx.pc..."
mkdir -p "$INSTALL_PREFIX/lib/pkgconfig"
cat > "$INSTALL_PREFIX/lib/pkgconfig/vpx.pc" <<EOF
prefix=$INSTALL_PREFIX
exec_prefix=\${prefix}
libdir=\${prefix}/lib
includedir=\${prefix}/include
Name: vpx
Description: WebM Project VPx codec implementation
Version: 1.14.1
Requires:
Conflicts:
Libs: -L\${libdir} -lvpx
Cflags: -I\${includedir}
EOF
fi
add_ffargs "--enable-libvpx"
fi
if [ -n "$ENABLE_LIBWEBP" ]; then
./build-cmake-dep.sh libwebp -DWEBP_BUILD_EXTRAS=OFF -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF -DWEBP_BUILD_GIF2WEBP=OFF -DWEBP_BUILD_IMG2WEBP=OFF -DWEBP_BUILD_VWEBP=OFF -DWEBP_BUILD_WEBPINFO=OFF -DWEBP_BUILD_WEBPMUX=OFF
add_ffargs "--enable-libwebp"
fi
if [ "$BUILD_LICENSE" == "gpl" ]; then
apply-patch x265_git x265_git-${BUILD_TYPE}.patch
if [ "$BUILD_TYPE" == "static" ]; then
X265_ARGS="-DSTATIC_LINK_CRT=ON"
ENABLE_SHARED=OFF
else
X265_ARGS="-DSTATIC_LINK_CRT=OFF"
ENABLE_SHARED=ON
fi
if [ "$BUILD_ARCH" == "arm" ]; then
apply-patch x265_git x265_git-arm.patch
fi
if [ "$BUILD_ARCH" == "arm64" ]; then
apply-patch x265_git x265_git-arm64.patch
X265_ARGS="$X265_ARGS -DENABLE_ASSEMBLY=OFF"
fi
apply-patch x265_git x265_git-version.patch
case $BUILD_ARCH in
amd64) CMAKE_ARCH=AMD64 ;;
x86) CMAKE_ARCH=x86 ;;
arm64) CMAKE_ARCH=ARM64 ;;
arm) CMAKE_ARCH=ARM ;;
esac
git -C x265_git fetch --tags
X265_VER=$(git -C x265_git describe --abbrev=0 --tags 2>/dev/null || echo "0.0")
./build-cmake-dep.sh x265_git/source -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_ARCH -DX265_LATEST_TAG=$X265_VER -DENABLE_SHARED=$ENABLE_SHARED -DENABLE_CLI=OFF $X265_ARGS
add_ffargs "--enable-libx265"
if [ "$BUILD_TYPE" == "shared" ]; then
apply-patch x264 x264-${BUILD_TYPE}.patch
fi
if [[ "$BUILD_ARCH" =~ arm ]]; then
X264_ARGS="--disable-asm"
fi
INSTALL_TARGET=install-lib-${BUILD_TYPE} ./build-make-dep.sh x264 --enable-${BUILD_TYPE} $X264_ARGS
add_ffargs "--enable-libx264"
fi
./build-ffmpeg.sh FFmpeg $FF_ARGS
./reprefix.sh