-
Notifications
You must be signed in to change notification settings - Fork 314
/
FFmpegConfig.sh
151 lines (139 loc) · 4.42 KB
/
FFmpegConfig.sh
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
#!/bin/bash
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Parse the options
options=$(getopt -o "" --long arch:,app-platform:,settings:,crt: -n "$0" -- "$@")
if [ $? -ne 0 ]; then
echo "ERROR: Invalid option(s)"
exit 1
fi
eval set -- "$options"
while true; do
case "$1" in
--arch)
arch=$2
shift 2
;;
--app-platform)
case "${2,,}" in
desktop)
app_platform_settings="--extra-cflags=\"-DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP\""
;;
onecore)
app_platform_settings=" \
--extra-cflags=\"-DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WIN32_WINNT=0x0A00\" \
--extra-ldflags=\"-APPCONTAINER WindowsApp.lib -NODEFAULTLIB:kernel32.lib -DEFAULTLIB:onecore.lib\""
;;
uwp)
app_platform_settings=" \
--extra-cflags=\"-DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WIN32_WINNT=0x0A00\" \
--extra-ldflags=\"-APPCONTAINER WindowsApp.lib\""
;;
*)
echo "Error: Invalid value for --app-platform: $2. Expected: desktop, onecore, or uwp"
exit 1
;;
esac
shift 2
;;
--crt)
case "${2,,}" in
dynamic)
crt_settings="--extra-cflags=\"-MD\""
;;
hybrid)
# The hybrid CRT is a technique using the Universal CRT AND the static CRT to get functional coverage
# without the overhead of the static CRT or the external dependency of the dynamic CRT.
#
# Learn more about the hybrid CRT:
# - https://github.com/microsoft/WindowsAppSDK/blob/main/docs/Coding-Guidelines/HybridCRT.md
# - https://www.youtube.com/watch?v=bNHGU6xmUzE&t=977s
crt_settings="--extra-cflags=\"-MT\" --extra-ldflags=\"-NODEFAULTLIB:libucrt.lib -DEFAULTLIB:ucrt.lib\""
;;
static)
crt_settings="--extra-cflags=\"-MT\""
;;
*)
echo "Error: Invalid value for --crt: $2. Expected: dynamic, hybrid, or static"
exit 1
;;
esac
shift 2
;;
--settings)
user_settings=$2
shift 2
;;
--)
shift
break
;;
*)
echo "ERROR: Invalid option: -$1" 1>&2
exit 1
;;
esac
done
# Common settings
common_settings=" \
--toolchain=msvc \
--target-os=win32 \
--disable-programs \
--disable-d3d11va \
--disable-dxva2 \
--enable-shared \
--enable-cross-compile \
--extra-cflags=\"-GUARD:CF -Qspectre -Gy -Gw\" \
--extra-ldflags=\"-PROFILE -GUARD:CF -DYNAMICBASE -OPT:ICF -OPT:REF\" \
"
# Architecture-specific settings
if [ -z $arch ]; then
echo "ERROR: No architecture set" 1>&2
exit 1
elif [ $arch == "x86" ]; then
arch_settings="
--arch=x86 \
--extra-ldflags=\"-CETCOMPAT\" \
--prefix=../../Build/$arch \
"
elif [ $arch == "x64" ]; then
arch_settings="
--arch=x86_64 \
--extra-ldflags=\"-CETCOMPAT\" \
--prefix=../../Build/$arch \
"
elif [ $arch == "arm" ]; then
arch_settings="
--arch=arm \
--as=armasm \
--cpu=armv7 \
--enable-thumb \
--extra-cflags=\"-D__ARM_PCS_VFP\" \
--prefix=../../Build/$arch \
"
elif [ $arch == "arm64" ]; then
arch_settings="
--arch=arm64 \
--as=armasm64 \
--cpu=armv7 \
--enable-thumb \
--extra-cflags=\"-D__ARM_PCS_VFP\" \
--prefix=../../Build/$arch \
"
else
echo "ERROR: $arch is not a valid architecture" 1>&2
exit 1
fi
# Build FFmpeg
pushd $dir/ffmpeg > /dev/null
rm -rf Output/$arch
mkdir -p Output/$arch
cd Output/$arch
eval ../../configure $common_settings $arch_settings $app_platform_settings $crt_settings $onecore_settings $user_settings &&
make -j`nproc` &&
make install
result=$?
popd > /dev/null
if [ $result -ne 0 ]; then
echo "ERROR: FFmpeg build for $arch failed with exit code $result" 1>&2
fi
exit $result