forked from gavinlin/FFmpeg-Android
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FFmpeg-Android.sh
executable file
·164 lines (145 loc) · 4.9 KB
/
FFmpeg-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
#!/bin/bash
#
# FFmpeg-Android, a bash script to build FFmpeg for Android.
#
# Copyright (c) 2012 Cedric Fung <[email protected]>
#
# FFmpeg-Android will build FFmpeg for Android automatically,
# with patches from VPlayer's Android version <https://vplayer.net/>.
#
# FFmpeg-Android is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# FFmpeg-Android is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with FFmpeg-Android; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#
# Instruction:
#
# 0. Install git and Android ndk
# 1. $ export ANDROID_NDK=/path/to/your/android-ndk
# 2. $ ./FFmpeg-Android.sh
# 3. libffmpeg.so will be built to build/ffmpeg/{neon,armv7,vfp,armv6}/
#
#
DEST=`pwd`/build/ffmpeg && rm -rf $DEST
SOURCE=`pwd`/ffmpeg
if [ -d ffmpeg ]; then
cd ffmpeg
else
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
fi
git reset --hard
git clean -f -d
git checkout `cat ../ffmpeg-version`
#patch -p1 <../FFmpeg-VPlayer.patch
#[ $PIPESTATUS == 0 ] || exit 1
git log --pretty=format:%H -1 > ../ffmpeg-version
TOOLCHAIN=/tmp/toolchain
SYSROOT=$TOOLCHAIN/sysroot/
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-18 --install-dir=$TOOLCHAIN --system=darwin-x86
export PATH=$TOOLCHAIN/bin:$PATH
export CC="arm-linux-androideabi-gcc"
export LD=arm-linux-androideabi-ld
export AR=arm-linux-androideabi-ar
CFLAGS="-O3 -Wall -mthumb -pipe -fpic -fasm \
-finline-limit=300 -ffast-math \
-fstrict-aliasing -Werror=strict-aliasing \
-fmodulo-sched -fmodulo-sched-allow-regmoves \
-Wno-psabi -Wa,--noexecstack \
-D__ARM_ARCH_5__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__ \
-DANDROID -DNDEBUG"
FFMPEG_FLAGS="--target-os=linux \
--arch=arm \
--enable-cross-compile \
--cross-prefix=arm-linux-androideabi- \
--enable-shared \
--disable-symver \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-ffplay \
--disable-ffmpeg \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-bsfs \
--disable-devices \
--disable-everything \
--disable-protocols \
--enable-protocol=file \
--enable-protocol=pipe \
--disable-parsers \
--enable-parser=h264 \
--enable-parser=aac \
--disable-demuxers \
--enable-demuxer=mp4 \
--enable-demuxer=mov \
--disable-decoders \
--enable-decoder=aac \
--enable-decoder=h264 \
--disable-muxers \
--enable-muxer=mp4 \
--disable-encoders \
--enable-encoder=aac \
--enable-gpl \
--enable-network \
--enable-swscale \
--enable-hwaccels \
--enable-avfilter \
--enable-filter=transpose \
--enable-filter=scale \
--enable-asm \
--enable-version3 "
# neon armv7 vfp armv6
for version in armv7; do
cd $SOURCE
case $version in
neon)
EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
;;
armv7)
EXTRA_CFLAGS="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
;;
vfp)
EXTRA_CFLAGS="-march=armv6 -mfpu=vfp -mfloat-abi=softfp"
EXTRA_LDFLAGS=""
;;
armv6)
EXTRA_CFLAGS="-march=armv6"
EXTRA_LDFLAGS=""
;;
*)
EXTRA_CFLAGS=""
EXTRA_LDFLAGS=""
;;
esac
PREFIX="$DEST/$version" && mkdir -p $PREFIX
FFMPEG_FLAGS="$FFMPEG_FLAGS --prefix=$PREFIX"
./configure $FFMPEG_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" | tee $PREFIX/configuration.txt
cp config.* $PREFIX
[ $PIPESTATUS == 0 ] || exit 1
make clean
make -j10 || exit 1
make install || exit 1
#not in our version....
#rm libavcodec/inverse.o
rm libavcodec/log2_tab.o
rm libswresample/log2_tab.o
rm libavformat/log2_tab.o
echo "$CC -lm -lz -shared --sysroot=$SYSROOT -Wl,--no-undefined -Wl,-z,noexecstack $EXTRA_LDFLAGS libavutil/*.o libavutil/arm/*.o libavcodec/*.o libavcodec/arm/*.o libavformat/*.o libswresample/*.o libswscale/*.o compat/*.o libswresample/arm/*.o libavfilter/*.o -o $PREFIX/libffmpeg.so"
$CC -lm -lz -shared --sysroot=$SYSROOT -Wl,--no-undefined -Wl,-z,noexecstack $EXTRA_LDFLAGS libavutil/*.o libavutil/arm/*.o libavcodec/*.o libavcodec/arm/*.o libavformat/*.o libswresample/*.o libswscale/*.o compat/*.o libswresample/arm/*.o libavfilter/*.o -o $PREFIX/libffmpeg.so
cp $PREFIX/libffmpeg.so $PREFIX/libffmpeg-debug.so
arm-linux-androideabi-strip --strip-unneeded $PREFIX/libffmpeg.so
done