blob: 9eea514315275c1c9d335d7f979f77eb8be84c81 (
plain)
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
|
#!/usr/bin/env bash
# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
# This script will build and install FFmpeg static libs
# Can take an optional final parameter to control installation directory
set -ex
# Must match or be lower than the minimum iOS version supported by the version of Qt that is
# is currently being built.
readonly MINIMUM_IOS_VERSION="16.0"
source "${BASH_SOURCE%/*}/../unix/ffmpeg-installation-utils.sh"
ffmpeg_source_dir=$(download_ffmpeg)
ffmpeg_config_options=$(get_ffmpeg_config_options "shared")
default_prefix="/usr/local/ios/ffmpeg"
prefix="${1:-$default_prefix}"
dylib_regex="^@rpath/.*\.dylib$"
build_ffmpeg_ios() {
local target_platform=$1
local target_cpu_arch=""
if [ "$target_platform" == "arm64-simulator" ]; then
target_sdk="iphonesimulator"
target_cpu_arch="arm64"
minos="-mios-simulator-version-min=$MINIMUM_IOS_VERSION"
elif [ "$target_platform" == "x86_64-simulator" ]; then
target_sdk="iphonesimulator"
target_cpu_arch="x86_64"
minos="-mios-simulator-version-min=$MINIMUM_IOS_VERSION"
elif [ "$target_platform" == "arm64-iphoneos" ]; then
target_sdk="iphoneos"
target_cpu_arch="arm64"
minos="-miphoneos-version-min=$MINIMUM_IOS_VERSION"
else
echo "Error when building FFmpeg for iOS. Unknown parameter given for target_platform: '${target_platform}'"
exit 1
fi
local build_dir="$ffmpeg_source_dir/build_ios/$target_platform"
sudo mkdir -p "$build_dir"
pushd "$build_dir"
# shellcheck disable=SC2086
sudo "$ffmpeg_source_dir/configure" $ffmpeg_config_options \
--sysroot="$(xcrun --sdk "$target_sdk" --show-sdk-path)" \
--enable-cross-compile \
--enable-optimizations \
--prefix=$prefix \
--arch=$target_cpu_arch \
--cc="xcrun --sdk ${target_sdk} clang -arch $target_cpu_arch" \
--cxx="xcrun --sdk ${target_sdk} clang++ -arch $target_cpu_arch" \
--target-os=darwin \
--extra-ldflags="$minos" \
--enable-shared \
--disable-static \
--install-name-dir='@rpath' \
--disable-audiotoolbox
sudo make install DESTDIR="$build_dir/installed" -j4
popd
}
build_info_plist() {
local file_path="$1"
local framework_name="$2"
local framework_id="$3"
local minimum_version_key="MinimumOSVersion"
local supported_platforms="iPhoneOS"
# TODO: This should be filled out with the actual version of FFmpeg that we are
# deploying.
info_plist="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${framework_name}</string>
<key>CFBundleIdentifier</key>
<string>${framework_id}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${framework_name}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>7.0.2</string>
<key>CFBundleVersion</key>
<string>7.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>${minimum_version_key}</key>
<string>${MINIMUM_IOS_VERSION}</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>${supported_platforms}</string>
</array>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>"
echo $info_plist | sudo tee ${file_path} 1>/dev/null
}
create_framework() {
# Create a 'traditional' framework from the corresponding dylib.
local framework_name="$1"
local platform="$2" # For now it's either arm64 or arm64-simulator, see below.
local ffmpeg_library_path="$ffmpeg_source_dir/build_ios/${platform}/installed$prefix"
local framework_complete_path="${ffmpeg_library_path}/framework/${framework_name}.framework/${framework_name}"
sudo mkdir -p "${ffmpeg_library_path}/framework/${framework_name}.framework"
sudo cp "${ffmpeg_library_path}/lib/${framework_name}.dylib" "${ffmpeg_library_path}/framework/${framework_name}.framework/${framework_name}"
# Fix LC_ID_DYLIB (to be libavcodec.framework/libavcodec instead of @rpath/libavcodec.xx.yy.dylib
sudo install_name_tool -id @rpath/${framework_name}.framework/${framework_name} "${framework_complete_path}"
build_info_plist "${ffmpeg_library_path}/framework/${framework_name}.framework/Info.plist" "${framework_name}" "io.qt.ffmpegkit."${framework_name}
# Fix all FFmpeg-related LC_LOAD_DYLIB, similar to how we fixed LC_ID_DYLIB above:
otool -L "$framework_complete_path" | awk '/\t/ {print $1}' | egrep "$dylib_regex" | while read -r dependency_path; do
found_name=$(tmp=${dependency_path/*\/}; echo ${tmp/\.*})
if [ "$found_name" != "$framework_name" ]
then
sudo install_name_tool -change "$dependency_path" @rpath/${found_name}.framework/${found_name} "${framework_complete_path}"
fi
done
#sudo mkdir -p "$prefix/framework/"
#sudo cp -r "${ffmpeg_library_path}/framework/${framework_name}.framework" "$prefix/framework/"
}
create_xcframework() {
# Create 'traditional' framework from the corresponding dylib,
# also creating
local framework_name="$1"
local target_platform_a="$2"
local target_platform_b="$3"
local fw_a="$ffmpeg_source_dir/build_ios/${target_platform_a}/installed$prefix/framework/${framework_name}.framework"
local fw_b="$ffmpeg_source_dir/build_ios/${target_platform_b}/installed$prefix/framework/${framework_name}.framework"
sudo mkdir -p "$prefix/framework/"
sudo xcodebuild -create-xcframework -framework $fw_a -framework $fw_b -output "${prefix}/framework/${framework_name}.xcframework"
}
build_ffmpeg_ios "x86_64-simulator"
build_ffmpeg_ios "arm64-iphoneos"
ffmpeg_libs="libavcodec libavformat libavutil libswresample libswscale"
for name in $ffmpeg_libs; do
create_framework $name "arm64-iphoneos"
create_framework $name "x86_64-simulator"
done
# Create corresponding (xc)frameworks containing both arm64 and arm64-simulator frameworks:
for name in $ffmpeg_libs; do
create_xcframework $name "arm64-iphoneos" "x86_64-simulator"
done
# xcframeworks are already installed directly into the target output directory.
# We need to install headers
sudo cp -r "$ffmpeg_source_dir/build_ios/arm64-iphoneos/installed$prefix/include" $prefix
# The set_ffmpeg_dir_env_var requires the presence of the "lib" subfolder in order to validate
# our FFmpeg install. On iOS we don't use this subfolder, we only rely on the "framework" subfolder.
# So we create a dummy "lib" folder to pass the check.
sudo mkdir -p "${prefix}/lib"
set_ffmpeg_dir_env_var "FFMPEG_DIR_IOS" $prefix
|