forked from bilibili/ijkplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile-ffmpeg.sh
executable file
·159 lines (143 loc) · 4.76 KB
/
compile-ffmpeg.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
152
153
154
155
156
157
158
159
#! /usr/bin/env bash
#
# Copyright (C) 2013-2014 Zhang Rui <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#----------
# modify for your build tool
FF_ALL_ARCHS_IOS6_SDK="armv7 armv7s i386"
FF_ALL_ARCHS_IOS7_SDK="armv7 armv7s arm64 i386 x86_64"
FF_ALL_ARCHS_IOS8_SDK="armv7 arm64 i386 x86_64"
FF_ALL_ARCHS=$FF_ALL_ARCHS_IOS8_SDK
#----------
UNI_BUILD_ROOT=`pwd`
UNI_TMP="$UNI_BUILD_ROOT/tmp"
UNI_TMP_LLVM_VER_FILE="$UNI_TMP/llvm.ver.txt"
FF_TARGET=$1
FF_TARGET_EXTRA=$2
set -e
#----------
echo_archs() {
echo "===================="
echo "[*] check xcode version"
echo "===================="
echo "FF_ALL_ARCHS = $FF_ALL_ARCHS"
}
FF_LIBS="libavcodec libavfilter libavformat libavutil libswscale libswresample"
do_lipo_ffmpeg () {
LIB_FILE=$1
LIPO_FLAGS=
for ARCH in $FF_ALL_ARCHS
do
ARCH_LIB_FILE="$UNI_BUILD_ROOT/build/ffmpeg-$ARCH/output/lib/$LIB_FILE"
if [ -f "$ARCH_LIB_FILE" ]; then
LIPO_FLAGS="$LIPO_FLAGS $ARCH_LIB_FILE"
else
echo "skip $LIB_FILE of $ARCH";
fi
done
xcrun lipo -create $LIPO_FLAGS -output $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
xcrun lipo -info $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
}
SSL_LIBS="libcrypto libssl"
do_lipo_ssl () {
LIB_FILE=$1
LIPO_FLAGS=
for ARCH in $FF_ALL_ARCHS
do
ARCH_LIB_FILE="$UNI_BUILD_ROOT/build/openssl-$ARCH/output/lib/$LIB_FILE"
if [ -f "$ARCH_LIB_FILE" ]; then
LIPO_FLAGS="$LIPO_FLAGS $ARCH_LIB_FILE"
else
echo "skip $LIB_FILE of $ARCH";
fi
done
if [ "$LIPO_FLAGS" != "" ]; then
xcrun lipo -create $LIPO_FLAGS -output $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
xcrun lipo -info $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
fi
}
do_lipo_all () {
mkdir -p $UNI_BUILD_ROOT/build/universal/lib
echo "lipo archs: $FF_ALL_ARCHS"
for FF_LIB in $FF_LIBS
do
do_lipo_ffmpeg "$FF_LIB.a";
done
ANY_ARCH=
for ARCH in $FF_ALL_ARCHS
do
ARCH_INC_DIR="$UNI_BUILD_ROOT/build/ffmpeg-$ARCH/output/include"
if [ -d "$ARCH_INC_DIR" ]; then
if [ -z "$ANY_ARCH" ]; then
ANY_ARCH=$ARCH
cp -R "$ARCH_INC_DIR" "$UNI_BUILD_ROOT/build/universal/"
fi
UNI_INC_DIR="$UNI_BUILD_ROOT/build/universal/include"
mkdir -p "$UNI_INC_DIR/libavutil/$ARCH"
cp -f "$ARCH_INC_DIR/libavutil/avconfig.h" "$UNI_INC_DIR/libavutil/$ARCH/avconfig.h"
cp -f tools/avconfig.h "$UNI_INC_DIR/libavutil/avconfig.h"
cp -f "$ARCH_INC_DIR/libavutil/ffversion.h" "$UNI_INC_DIR/libavutil/$ARCH/ffversion.h"
cp -f tools/ffversion.h "$UNI_INC_DIR/libavutil/ffversion.h"
mkdir -p "$UNI_INC_DIR/libffmpeg/$ARCH"
cp -f "$ARCH_INC_DIR/libffmpeg/config.h" "$UNI_INC_DIR/libffmpeg/$ARCH/config.h"
cp -f tools/config.h "$UNI_INC_DIR/libffmpeg/config.h"
fi
done
for SSL_LIB in $SSL_LIBS
do
do_lipo_ssl "$SSL_LIB.a";
done
}
#----------
if [ "$FF_TARGET" = "armv7" -o "$FF_TARGET" = "armv7s" -o "$FF_TARGET" = "arm64" ]; then
echo_archs
sh tools/do-compile-ffmpeg.sh $FF_TARGET $FF_TARGET_EXTRA
do_lipo_all
elif [ "$FF_TARGET" = "i386" -o "$FF_TARGET" = "x86_64" ]; then
echo_archs
sh tools/do-compile-ffmpeg.sh $FF_TARGET $FF_TARGET_EXTRA
do_lipo_all
elif [ "$FF_TARGET" = "lipo" ]; then
echo_archs
do_lipo_all
elif [ "$FF_TARGET" = "all" ]; then
echo_archs
for ARCH in $FF_ALL_ARCHS
do
sh tools/do-compile-ffmpeg.sh $ARCH $FF_TARGET_EXTRA
done
do_lipo_all
elif [ "$FF_TARGET" = "check" ]; then
echo_archs
elif [ "$FF_TARGET" = "clean" ]; then
echo_archs
for ARCH in $FF_ALL_ARCHS
do
cd ffmpeg-$ARCH && git clean -xdf && cd -
done
rm -rf build/ffmpeg-*
rm -rf build/openssl-*
rm -rf build/universal/include
rm -rf build/universal/lib
else
echo "Usage:"
echo " compile-ffmpeg.sh armv7|arm64|i386|x86_64"
echo " compile-ffmpeg.sh armv7s (obselete)"
echo " compile-ffmpeg.sh lipo"
echo " compile-ffmpeg.sh all"
echo " compile-ffmpeg.sh clean"
echo " compile-ffmpeg.sh check"
exit 1
fi