forked from FFmpeg/FFmpeg
-
Notifications
You must be signed in to change notification settings - Fork 97
/
build_android.sh
executable file
·320 lines (285 loc) · 9.47 KB
/
build_android.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/bin/bash
echo " _ __ _ __ _ "
echo " | | / / (_) / /_ ____ _ ____ ___ (_) ___ "
echo " | | / / / / / __/ / __ \/ / __ __ \ / / / __ \ "
echo " | |/ / / / / /_ / /_/ / / / / / / / / / / /_/ / "
echo " |___/ /_/ \__/ \____/ /_/ /_/ /_/ /_/ \____/ "
echo " "
# export ANDROID_NDK=
# Detect ANDROID_NDK
if [ -z "$ANDROID_NDK" ]; then
echo "You must define ANDROID_NDK before starting."
echo "They must point to your NDK directories.\n"
exit 1
fi
#SSL=$SSL
if [ -z "$SSL" ]; then
echo "No define SSL before starting"
echo "Please clone from [email protected]:yixia/OpenSSL-Vitamio.git, and run ndk-build ";
exit 1
fi
# Detect OS
OS=`uname`
HOST_ARCH=`uname -m`
export CCACHE=; type ccache >/dev/null 2>&1 && export CCACHE=ccache
if [ $OS == 'Linux' ]; then
export HOST_SYSTEM=linux-$HOST_ARCH
elif [ $OS == 'Darwin' ]; then
export HOST_SYSTEM=darwin-$HOST_ARCH
fi
platform="$1"
version_type="$2"
function arm_toolchain()
{
export CROSS_PREFIX=arm-linux-androideabi-
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --toolchain=${CROSS_PREFIX}4.8 \
--system=$HOST_SYSTEM --install-dir=$TOOLCHAIN
}
function x86_toolchain()
{
export CROSS_PREFIX=i686-linux-android-
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --toolchain=x86-4.8 \
--system=$HOST_SYSTEM --install-dir=$TOOLCHAIN
}
function mips_toolchain()
{
export CROSS_PREFIX=mipsel-linux-android-
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --toolchain=${CROSS_PREFIX}4.8 \
--system=$HOST_SYSTEM --install-dir=$TOOLCHAIN
}
SOURCE=`pwd`
DEST=$SOURCE/build/android
TOOLCHAIN=/tmp/vitamio
SYSROOT=$TOOLCHAIN/sysroot/
if [ "$platform" = "x86" ];then
echo "Build Android x86 ffmpeg\n"
x86_toolchain
TARGET="x86"
elif [ "$platform" = "mips" ];then
echo "Build Android mips ffmpeg\n"
mips_toolchain
TARGET="mips"
else
echo "Build Android arm ffmpeg\n"
arm_toolchain
TARGET="neon armv7 vfp armv6"
fi
export PATH=$TOOLCHAIN/bin:$PATH
export CC="$CCACHE ${CROSS_PREFIX}gcc"
export CXX=${CROSS_PREFIX}g++
export LD=${CROSS_PREFIX}ld
export AR=${CROSS_PREFIX}ar
export STRIP=${CROSS_PREFIX}strip
CFLAGS="-std=c99 -O3 -Wall -pipe -fpic -fasm \
-finline-limit=300 -ffast-math \
-fstrict-aliasing -Werror=strict-aliasing \
-Wno-psabi -Wa,--noexecstack \
-fdiagnostics-color=always \
-DANDROID -DNDEBUG \
-I$SSL/include"
LDFLAGS="-lm -lz -Wl,--no-undefined -Wl,-z,noexecstack"
case $CROSS_PREFIX in
arm-*)
CFLAGS="-mthumb $CFLAGS \
-D__ARM_ARCH_5__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__"
;;
x86-*)
;;
mipsel-*)
CFLAGS="-std=c99 -O3 -Wall -pipe -fpic -fasm \
-ftree-vectorize -ffunction-sections -funwind-tables -fomit-frame-pointer -funswitch-loops \
-finline-limit=300 -finline-functions -fpredictive-commoning -fgcse-after-reload -fipa-cp-clone \
-Wno-psabi -Wa,--noexecstack \
-DANDROID -DNDEBUG \
-I$SSL/include"
;;
esac
if [ "$version_type" = "online" ]; then
FFMPEG_FLAGS_COMMON="--target-os=linux \
--cross-prefix=$CROSS_PREFIX \
--enable-cross-compile \
--enable-version3 \
--enable-shared \
--disable-static \
--disable-symver \
--disable-programs \
--disable-doc \
--disable-avdevice \
--disable-encoders \
--disable-muxers \
--disable-devices \
--disable-everything \
--disable-protocols \
--disable-demuxers \
--disable-decoders \
--disable-bsfs \
--disable-debug \
--enable-optimizations \
--enable-filters \
--enable-parsers \
--disable-parser=hevc \
--enable-swscale \
--enable-network \
--enable-protocol=file \
--enable-protocol=http \
--enable-protocol=rtmp \
--enable-protocol=rtp \
--enable-protocol=mmst \
--enable-protocol=mmsh \
--enable-protocol=crypto \
--enable-protocol=hls \
--enable-demuxer=hls \
--enable-demuxer=mpegts \
--enable-demuxer=mpegtsraw \
--enable-demuxer=mpegvideo \
--enable-demuxer=concat \
--enable-demuxer=mov \
--enable-demuxer=flv \
--enable-demuxer=rtsp \
--enable-demuxer=mp3 \
--enable-demuxer=matroska \
--enable-decoder=mpeg4 \
--enable-decoder=mpegvideo \
--enable-decoder=mpeg1video \
--enable-decoder=mpeg2video \
--enable-decoder=h264 \
--enable-decoder=h263 \
--enable-decoder=flv \
--enable-decoder=vp8 \
--enable-decoder=wmv3 \
--enable-decoder=aac \
--enable-decoder=ac3 \
--enable-decoder=mp3 \
--enable-decoder=nellymoser \
--enable-muxer=mp4 \
--enable-asm \
--enable-pic"
else
FFMPEG_FLAGS_COMMON="--target-os=linux \
--enable-cross-compile \
--cross-prefix=$CROSS_PREFIX \
--enable-version3 \
--enable-optimizations \
--enable-shared \
--disable-fast-unaligned \
--disable-static \
--disable-symver \
--disable-programs \
--disable-doc \
--disable-avdevice \
--disable-postproc \
--disable-encoders \
--disable-muxers \
--enable-muxer=mp4 \
--disable-devices \
--disable-demuxer=sbg \
--disable-demuxer=dts \
--disable-parser=dca \
--disable-decoder=dca \
--disable-decoder=svq3 \
--disable-debug \
--enable-network \
--enable-asm"
fi
# --disable-decoder=ac3 --disable-decoder=eac3 --disable-decoder=mlp \
for version in $TARGET; do
cd $SOURCE
FFMPEG_FLAGS="$FFMPEG_FLAGS_COMMON"
case $version in
neon)
FFMPEG_FLAGS="--arch=armv7-a \
--cpu=cortex-a8 \
--enable-openssl \
--disable-runtime-cpudetect \
$FFMPEG_FLAGS"
EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$SSL/libs/armeabi-v7a"
SSL_OBJS=`find $SSL/obj/local/armeabi-v7a/objs/ssl $SSL/obj/local/armeabi-v7a/objs/crypto -type f -name "*.o"`
;;
armv7)
FFMPEG_FLAGS="--arch=armv7-a \
--cpu=cortex-a8 \
--enable-openssl \
--disable-runtime-cpudetect \
$FFMPEG_FLAGS"
EXTRA_CFLAGS="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$SSL/libs/armeabi-v7a"
SSL_OBJS=`find $SSL/obj/local/armeabi-v7a/objs/ssl $SSL/obj/local/armeabi-v7a/objs/crypto -type f -name "*.o"`
;;
vfp)
FFMPEG_FLAGS="--arch=arm \
--disable-runtime-cpudetect \
$FFMPEG_FLAGS"
EXTRA_CFLAGS="-march=armv6 -mfpu=vfp -mfloat-abi=softfp"
EXTRA_LDFLAGS=""
SSL_OBJS=""
;;
armv6)
FFMPEG_FLAGS="--arch=arm \
--disable-runtime-cpudetect \
$FFMPEG_FLAGS"
EXTRA_CFLAGS="-march=armv6 -msoft-float"
EXTRA_LDFLAGS=""
SSL_OBJS=""
;;
x86)
FFMPEG_FLAGS="--arch=x86 \
--cpu=i686 \
--enable-runtime-cpudetect
--enable-openssl \
--enable-yasm \
--disable-amd3dnow \
--disable-amd3dnowext \
$FFMPEG_FLAGS"
EXTRA_CFLAGS="-march=atom -msse3 -ffast-math -mfpmath=sse"
EXTRA_LDFLAGS="-L$SSL/libs/x86"
SSL_OBJS=`find $SSL/obj/local/x86/objs/ssl $SSL/obj/local/x86/objs/crypto -type f -name "*.o"`
;;
mips)
FFMPEG_FLAGS="--arch=mips \
--cpu=mips32r2 \
--enable-runtime-cpudetect \
--enable-openssl \
--enable-yasm \
--disable-mipsfpu \
--disable-mipsdspr1 \
--disable-mipsdspr2 \
$FFMPEG_FLAGS"
EXTRA_CFLAGS="-fno-strict-aliasing -fmessage-length=0 -fno-inline-functions-called-once -frerun-cse-after-loop -frename-registers"
EXTRA_LDFLAGS="-L$SSL/libs/mips"
SSL_OBJS=`find $SSL/obj/local/mips/objs/ssl $SSL/obj/local/mips/objs/crypto -type f -name "*.o"`
;;
*)
FFMPEG_FLAGS=""
EXTRA_CFLAGS=""
EXTRA_LDFLAGS=""
SSL_OBJS=""
;;
esac
PREFIX="$DEST/$version" && rm -rf $PREFIX && mkdir -p $PREFIX
FFMPEG_FLAGS="$FFMPEG_FLAGS --prefix=$PREFIX"
./configure $FFMPEG_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS" --extra-ldflags="$LDFLAGS $EXTRA_LDFLAGS" | tee $PREFIX/configuration.txt
cp config.* $PREFIX
[ $PIPESTATUS == 0 ] || exit 1
make clean
find . -name "*.o" -type f -delete
make -j4 || exit 1
rm libavcodec/log2_tab.o libavformat/log2_tab.o libswresample/log2_tab.o
case $CROSS_PREFIX in
arm-*)
$CC -o $PREFIX/libffmpeg.so -shared $LDFLAGS $EXTRA_LDFLAGS $SSL_OBJS \
libavutil/*.o libavutil/arm/*.o libavcodec/*.o libavcodec/arm/*.o libavformat/*.o libavfilter/*.o libswresample/*.o libswresample/arm/*.o libswscale/*.o compat/*.o
;;
i686-*)
$CC -o $PREFIX/libffmpeg.so -shared $LDFLAGS $EXTRA_LDFLAGS $SSL_OBJS \
libavutil/*.o libavutil/x86/*.o libavcodec/*.o libavcodec/x86/*.o libavformat/*.o libavfilter/*.o libavfilter/x86/*.o libswresample/*.o libswresample/x86/*.o libswscale/*.o libswscale/x86/*.o compat/*.o
;;
mipsel-*)
$CC -o $PREFIX/libffmpeg.so -shared $LDFLAGS $EXTRA_LDFLAGS $SSL_OBJS \
libavutil/*.o libavutil/mips/*.o libavcodec/*.o libavcodec/mips/*.o libavformat/*.o libavfilter/*.o libswresample/*.o libswscale/*.o compat/*.o
;;
esac
cp $PREFIX/libffmpeg.so $PREFIX/libffmpeg-debug.so
${STRIP} --strip-unneeded $PREFIX/libffmpeg.so
echo "----------------------$version -----------------------------"
done