-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_old_build_ffmpeg.sh
More file actions
317 lines (274 loc) · 8.73 KB
/
_old_build_ffmpeg.sh
File metadata and controls
317 lines (274 loc) · 8.73 KB
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
#!/bin/bash
set -e
# Set your own NDK here
NDK=~/Android/Sdk/ndk-bundle
#export NDK=`grep ndk.dir $PROPS | cut -d'=' -f2`
if [ "$NDK" = "" ] || [ ! -d $NDK ]; then
echo "NDK variable not set or path to NDK is invalid, exiting..."
exit 1
fi
export TARGET=$1
ARM_PLATFORM=$NDK/platforms/android-9/arch-arm/
ARM_PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
ARM64_PLATFORM=$NDK/platforms/android-21/arch-arm64/
ARM64_PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
X86_PLATFORM=$NDK/platforms/android-9/arch-x86/
X86_PREBUILT=$NDK/toolchains/x86-4.9/prebuilt/linux-x86_64
X86_64_PLATFORM=$NDK/platforms/android-21/arch-x86_64/
X86_64_PREBUILT=$NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64
MIPS_PLATFORM=$NDK/platforms/android-9/arch-mips/
MIPS_PREBUILT=$NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64
BUILD_DIR=`pwd`/libs
OPENSSL_BUILD_DIR=${BUILD_DIR}/lib
OPENSSL_SRC_DIR=`pwd`/src/openssl-android
FFMPEG_VERSION="3.3"
#FFMPEG_VERSION="3.0.1"
if [ ! -e "ffmpeg-${FFMPEG_VERSION}.tar.bz2" ]; then
echo "Downloading ffmpeg-${FFMPEG_VERSION}.tar.bz2"
curl -LO http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2
else
echo "Using ffmpeg-${FFMPEG_VERSION}.tar.bz2"
fi
tar -xvf ffmpeg-${FFMPEG_VERSION}.tar.bz2
for i in `find diffs -type f`; do
(cd ffmpeg-${FFMPEG_VERSION} && patch -p1 < ../$i)
done
######################################################
############### START die ############################
######################################################
#-- error function
function die {
code=-1
err="Unknown error!"
test "$1" && err=$1
cd ${top_root}
echo "$err"
echo "Check the build log: ${build_log}"
exit -1
}
######################################################
############### START die ############################
######################################################
######################################################
############### START build_one ######################
######################################################
function build_one
{
if [ $ARCH == "arm" ]
then
PLATFORM=$ARM_PLATFORM
PREBUILT=$ARM_PREBUILT
HOST=arm-linux-androideabi
#added by alexvas
elif [ $ARCH == "arm64" ]
then
PLATFORM=$ARM64_PLATFORM
PREBUILT=$ARM64_PREBUILT
HOST=aarch64-linux-android
elif [ $ARCH == "mips" ]
then
PLATFORM=$MIPS_PLATFORM
PREBUILT=$MIPS_PREBUILT
HOST=mipsel-linux-android
#alexvas
elif [ $ARCH == "x86_64" ]
then
PLATFORM=$X86_64_PLATFORM
PREBUILT=$X86_64_PREBUILT
HOST=x86_64-linux-android
else
PLATFORM=$X86_PLATFORM
PREBUILT=$X86_PREBUILT
HOST=i686-linux-android
fi
top_root=$(pwd)
patch_root=${top_root}/patches
configuration_log=${top_root}/configuration.log
# patch the configure script to use an Android-friendly versioning scheme
patch -u configure ${patch_root}/ffmpeg-configure.patch || die "Couldn't patch ffmpeg configure script!"
export PKG_CONFIG_PATH="${OPENSSL_SRC_DIR}"
echo "pkg-config path = ${PKG_CONFIG_PATH}"
openssl_addi_ldflags=""
# --prefix=$PREFIX \
#--incdir=$BUILD_DIR/include \
#--libdir=$BUILD_DIR/lib/$CPU \
# --extra-cflags="-fvisibility=hidden -fdata-sections -ffunction-sections -Os -fPIC -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
# --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
# TODO Adding aac decoder brings "libnative.so has text relocations. This is wasting memory and prevents security hardening. Please fix." message in Android.
pushd ffmpeg-$FFMPEG_VERSION
./configure \
--target-os=linux \
--incdir=$BUILD_DIR/include/$TARGET \
--libdir=$BUILD_DIR/lib/$TARGET \
--enable-cross-compile \
--extra-libs="-lgcc" \
--arch=$ARCH \
--cc=$PREBUILT/bin/$HOST-gcc \
--cross-prefix=$PREBUILT/bin/$HOST- \
--nm=$PREBUILT/bin/$HOST-nm \
--sysroot=$PLATFORM \
--extra-cflags="$OPTIMIZE_CFLAGS " \
--extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog -L${OPENSSL_BUILD_DIR}/${ABI} ${openssl_addi_ldflags}" \
--disable-static \
--disable-ffplay \
--disable-ffmpeg \
--disable-ffprobe \
--disable-ffserver \
--disable-doc \
--disable-postproc \
--disable-gpl \
--disable-encoders \
--disable-muxers \
--disable-bsfs \
--disable-protocols \
--disable-indevs \
--disable-outdevs \
--disable-devices \
--enable-shared \
--enable-small \
--enable-openssl \
--enable-encoder=png \
--enable-protocol=file,ftp,http,https,httpproxy,hls,mmsh,mmst,pipe,rtmp,rtmps,rtmpt,rtmpts,rtp,sctp,srtp,tcp,udp \
--pkg-config=$(which pkg-config) \
$ADDITIONAL_CONFIGURE_FLAG >> ${configuration_log} 2>&1 || die "Couldn't configure ffmpeg!"
make clean
make -j8 install V=1
$PREBUILT/bin/$HOST-ar d libavcodec/libavcodec.a inverse.o
#$PREBUILT/bin/$HOST-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/$HOST/4.6/libgcc.a
popd
# copy the binaries
mkdir -p $PREFIX
cp -r $BUILD_DIR/$TARGET/* $PREFIX
}
######################################################
############### END build_one ########################
######################################################
if [ $TARGET == 'arm-v5te' ]; then
#arm v5te
ABI=armeabi
CPU=armv5te
ARCH=arm
OPTIMIZE_CFLAGS="-marm -march=$CPU"
PREFIX=$BUILD_DIR/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'arm-v6' ]; then
#arm v6
ABI=armeabi
CPU=armv6
ARCH=arm
OPTIMIZE_CFLAGS="-marm -march=$CPU"
PREFIX=`pwd`/ffmpeg-android/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'arm-v7vfpv3' ]; then
#arm v7vfpv3
ABI=armeabi-v7a
CPU=armv7-a
ARCH=arm
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=$BUILD_DIR/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'arm-v7vfp' ]; then
#arm v7vfp
ABI=armeabi-v7a
CPU=armv7-a
ARCH=arm
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
PREFIX=`pwd`/ffmpeg-android/$CPU-vfp
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'arm-v7n' ]; then
#arm v7n
ABI=armeabi-v7a
CPU=armv7-a
ARCH=arm
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
PREFIX=`pwd`/ffmpeg-android/$CPU
ADDITIONAL_CONFIGURE_FLAG=--enable-neon
build_one
fi
if [ $TARGET == 'arm-v6+vfp' ]; then
#arm v6+vfp
ABI=armeabi
CPU=armv6
ARCH=arm
OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
PREFIX=`pwd`/ffmpeg-android/${CPU}_vfp
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'arm64-v8a' ]; then
#arm64-v8a
ABI=arm64-v8a
CPU=arm64-v8a
ARCH=arm64
OPTIMIZE_CFLAGS=
PREFIX=$BUILD_DIR/$CPU
PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/arm64-v8a
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'x86_64' ]; then
#x86_64
ABI=x86_64
CPU=x86_64
ARCH=x86_64
OPTIMIZE_CFLAGS="-fomit-frame-pointer"
#PREFIX=$BUILD_DIR/$CPU
PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/x86_64
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'i686' ]; then
#x86
ABI=x86
CPU=i686
ARCH=i686
OPTIMIZE_CFLAGS="-fomit-frame-pointer"
#PREFIX=$BUILD_DIR/$CPU
PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/x86
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'mips' ]; then
#mips
ABI=mips
CPU=mips
ARCH=mips
OPTIMIZE_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"
#PREFIX=$BUILD_DIR/$CPU
PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/mips
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'armv7-a' ]; then
#arm armv7-a
ABI=armeabi-v7a
CPU=armv7-a
ARCH=arm
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -marm -march=$CPU "
#PREFIX=`pwd`/ffmpeg-android/$CPU
PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/armeabi-v7a
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi
if [ $TARGET == 'arm' ]; then
#arm arm
ABI=armeabi
CPU=arm
ARCH=arm
OPTIMIZE_CFLAGS=""
#PREFIX=`pwd`/ffmpeg-android/$CPU
PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/armeabi
ADDITIONAL_CONFIGURE_FLAG=
build_one
fi