Skip to content

Commit 824daae

Browse files
committed
First Commit
1 parent 8436774 commit 824daae

14 files changed

+339
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

FFmpeg_Android_Share_OK.zip

29.8 MB
Binary file not shown.

FFmpeg_Android_Static_OK.zip

32.9 MB
Binary file not shown.

build-ffmpeg-android.sh

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
#需要编译FFpmeg版本号
4+
FF_VERSION="3.4.2"
5+
SOURCE="ffmpeg-$FF_VERSION"
6+
SHELL_PATH=`pwd`
7+
FF_PATH=$SHELL_PATH/$SOURCE
8+
#输出路径
9+
PREFIX=$SHELL_PATH/FFmpeg_android
10+
COMP_BUILD=$1
11+
12+
#需要编译的Android API版本
13+
ANDROID_API=21
14+
#需要编译的NDK路径,NDK版本需大等于r15c
15+
NDK=/Users/lzj/Library/Android/sdk/ndk-bundle
16+
17+
#x264库路径
18+
x264=$SHELL_PATH/x264_android
19+
if [ "$x264" ] && [[ $FF_VERSION == 3.0.* ]] || [[ $FF_VERSION == 3.1.* ]]
20+
then
21+
echo "Use low version x264"
22+
sh $SHELL_PATH/build-x264-android.sh $COMP_BUILD
23+
elif [ "$x264" ]
24+
then
25+
echo "Use last version x264"
26+
sh $SHELL_PATH/build-x264-android.sh $COMP_BUILD last $ANDROID_API $NDK
27+
fi
28+
29+
#需要编译的平台:arm arm64 x86 x86_64,可传入平台单独编译对应的库
30+
ARCHS=(arm arm64 x86 x86_64)
31+
TRIPLES=(arm-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android)
32+
TRIPLES_PATH=(arm-linux-androideabi-4.9 aarch64-linux-android-4.9 x86-4.9 x86_64-4.9)
33+
34+
FF_CONFIGURE_FLAGS="--enable-static --disable-shared --enable-pic --enable-gpl --enable-postproc --disable-stripping --enable-small --enable-version3 --enable-jni --enable-mediacodec --enable-decoder=h264_mediacodec --enable-hwaccel=h264_mediacodec --enable-decoder=hevc_mediacodec --enable-decoder=mpeg4_mediacodec --enable-decoder=vp8_mediacodec --enable-decoder=vp9_mediacodec"
35+
36+
rm -rf "$SOURCE"
37+
if [ ! -r $SOURCE ]
38+
then
39+
if [ ! -f "$SOURCE.tar.bz2" ]
40+
then
41+
echo "$SOURCE source not found, Trying to download..."
42+
curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj || exit 1
43+
else
44+
mkdir $FF_PATH
45+
tar zxvf $SHELL_PATH/"$SOURCE.tar.bz2" --strip-components 1 -C $FF_PATH || exit 1
46+
fi
47+
fi
48+
49+
#若使用android-ndk-r15c及以上NDK需要打此补丁(修改FFmepg与NDK代码冲突)
50+
sh $SHELL_PATH/build-ffmpeg-patch.sh $FF_PATH
51+
52+
cd $FF_PATH
53+
export TMPDIR=$FF_PATH/tmpdir
54+
mkdir $TMPDIR
55+
for i in "${!ARCHS[@]}";
56+
do
57+
ARCH=${ARCHS[$i]}
58+
TOOLCHAIN=$NDK/toolchains/${TRIPLES_PATH[$i]}/prebuilt/darwin-x86_64
59+
SYSROOT=$NDK/platforms/android-$ANDROID_API/arch-$ARCH/
60+
ISYSROOT=$NDK/sysroot
61+
ASM=$ISYSROOT/usr/include/${TRIPLES[$i]}
62+
CROSS_PREFIX=$TOOLCHAIN/bin/${TRIPLES[$i]}-
63+
PREFIX_ARCH=$PREFIX/$ARCH
64+
65+
if [ "$COMP_BUILD" = "" -o "$COMP_BUILD" = "$ARCH" ]
66+
then
67+
if [ "$ARCH" = "arm" ]
68+
then
69+
FF_EXTRA_CONFIGURE_FLAGS="--disable-asm"
70+
FF_EXTRA_CFLAGS="-fpic -ffunction-sections -funwind-tables -fstack-protector -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300"
71+
TRMP_P="eabi-v7a"
72+
PREFIX_ARCH="$PREFIX_ARCH$TRMP_P"
73+
elif [ "$ARCH" = "arm64" ]
74+
then
75+
if [ $ANDROID_API -lt 21 ]
76+
then
77+
continue
78+
else
79+
FF_EXTRA_CONFIGURE_FLAGS=""
80+
FF_EXTRA_CFLAGS="-fpic"
81+
TRMP_P="-v8a"
82+
PREFIX_ARCH="$PREFIX_ARCH$TRMP_P"
83+
fi
84+
elif [ "$ARCH" = "x86" -o "$ARCH" = "x86_64" ]
85+
then
86+
if [ "$ARCH" = "x86_64" -a $ANDROID_API -lt 21 ]
87+
then
88+
continue
89+
else
90+
FF_EXTRA_CONFIGURE_FLAGS="--disable-asm"
91+
FF_EXTRA_CFLAGS="-fpic -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -fomit-frame-pointer -march=k8"
92+
fi
93+
else
94+
echo "Unrecognized arch:$ARCH"
95+
exit 1
96+
fi
97+
98+
if [ "$x264" ]
99+
then
100+
FF_EXTRA_CONFIGURE_FLAGS="$FF_EXTRA_CONFIGURE_FLAGS --enable-libx264 --enable-encoder=libx264"
101+
FF_EXTRA_CFLAGS="$FF_EXTRA_CFLAGS -I$x264/${ARCHS[$i]}$TRMP_P/include"
102+
FF_LDFLAGS="-L$x264/${ARCHS[$i]}$TRMP_P/lib"
103+
else
104+
FF_LDFLAGS=""
105+
fi
106+
else
107+
continue
108+
fi
109+
FF_CFLAGS="-I$ASM -isysroot $ISYSROOT -D__ANDROID_API__=$ANDROID_API -U_FILE_OFFSET_BITS -O3 -pipe -Wall -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID"
110+
111+
./configure \
112+
--prefix=$PREFIX_ARCH \
113+
--sysroot=$SYSROOT \
114+
--target-os=android \
115+
--arch=$ARCH \
116+
--cross-prefix=$CROSS_PREFIX \
117+
--enable-cross-compile \
118+
--disable-runtime-cpudetect \
119+
--disable-doc \
120+
--disable-debug \
121+
--disable-ffmpeg \
122+
--disable-ffprobe \
123+
--disable-ffserver \
124+
$FF_CONFIGURE_FLAGS \
125+
$FF_EXTRA_CONFIGURE_FLAGS \
126+
--extra-cflags="$FF_EXTRA_CFLAGS $FF_CFLAGS" \
127+
--extra-ldflags="$FF_LDFLAGS" \
128+
$ADDITIONAL_CONFIGURE_FLAG || exit 1
129+
make -j3 install || exit 1
130+
make distclean
131+
rm -rf "$PREFIX_ARCH/share"
132+
rm -rf "$PREFIX_ARCH/lib/pkgconfig"
133+
done
134+
135+
echo "Android FFmpeg bulid success!"
136+
137+

build-ffmpeg-patch.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
FF_PATH=$1
4+
SHELL_PATH=`pwd`
5+
6+
set -x
7+
patch -p0 -N --dry-run --silent -f $FF_PATH/libavcodec/aaccoder.c < $SHELL_PATH/ffmpeg_modify_aacoder.patch 1>/dev/null
8+
if [ $? -eq 0 ]; then
9+
patch -p0 -f $FF_PATH/libavcodec/aaccoder.c < $SHELL_PATH/ffmpeg_modify_aacoder.patch
10+
fi
11+
12+
patch -p0 -N --dry-run --silent -f $FF_PATH/libavcodec/hevc_mvs.c < $SHELL_PATH/ffmpeg_modify_hevc_mvs.patch 1>/dev/null
13+
if [ $? -eq 0 ]; then
14+
patch -p0 -f $FF_PATH/libavcodec/hevc_mvs.c < $SHELL_PATH/ffmpeg_modify_hevc_mvs.patch
15+
fi
16+
17+
patch -p0 -N --dry-run --silent -f $FF_PATH/libavcodec/opus_pvq.c < $SHELL_PATH/ffmpeg_modify_opus_pvq.patch 1>/dev/null
18+
if [ $? -eq 0 ]; then
19+
patch -p0 -f $FF_PATH/libavcodec/opus_pvq.c < $SHELL_PATH/ffmpeg_modify_opus_pvq.patch
20+
fi
21+
22+
patch -p0 -N --dry-run --silent -f $FF_PATH/configure < $SHELL_PATH/ffmpeg_modify_configure.patch 1>/dev/null
23+
if [ $? -eq 0 ]; then
24+
patch -p0 -f $FF_PATH/configure < $SHELL_PATH/ffmpeg_modify_configure.patch
25+
fi
26+
set +x
27+
28+

build-x264-android.sh

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
X264_VERSION=""
4+
SOURCE="x264"
5+
SHELL_PATH=`pwd`
6+
X264_PATH=$SHELL_PATH/$SOURCE
7+
#输出路径
8+
PREFIX=$SHELL_PATH/x264_android
9+
COMP_BUILD=$1
10+
LAST_VERSION=$2
11+
ANDROID_API=$3
12+
NDK=$4
13+
14+
#需要编译的Android API版本
15+
if [ ! "$ANDROID_API" ]
16+
then
17+
ANDROID_API=21
18+
fi
19+
#需要编译的NDK路径,NDK版本需大等于r15c
20+
if [ ! "$NDK" ]
21+
then
22+
NDK=/Users/lzj/Library/Android/sdk/ndk-bundle
23+
fi
24+
echo ANDROID_API=$ANDROID_API
25+
echo NDK=$NDK
26+
27+
#需要编译的平台:arm arm64 x86 x86_64
28+
ARCHS=(arm arm64 x86 x86_64)
29+
TRIPLES=(arm-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android)
30+
TRIPLES_PATH=(arm-linux-androideabi-4.9 aarch64-linux-android-4.9 x86-4.9 x86_64-4.9)
31+
32+
FF_CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli"
33+
#FF_CONFIGURE_FLAGS="--enable-shared --enable-pic --disable-cli"
34+
35+
#rm -rf "$SOURCE"
36+
if [ ! -r $SOURCE ]
37+
then
38+
if [ "$LAST_VERSION" ] && [ $ANDROID_API -ge 21 ]
39+
then
40+
X264_TAR_NAME="x264-snapshot-20180630-2245.tar.bz2"
41+
else
42+
X264_TAR_NAME="x264-snapshot-20160114-2245.tar.bz2"
43+
fi
44+
if [ ! -f "$SHELL_PATH/$X264_TAR_NAME" ]
45+
then
46+
echo "$X264_TAR_NAME source not found, Trying to download..."
47+
curl -O http://download.videolan.org/pub/videolan/x264/snapshots/$X264_TAR_NAME
48+
fi
49+
mkdir $X264_PATH
50+
tar zxvf $SHELL_PATH/$X264_TAR_NAME --strip-components 1 -C $X264_PATH || exit 1
51+
fi
52+
53+
cd $X264_PATH
54+
for i in "${!ARCHS[@]}";
55+
do
56+
ARCH=${ARCHS[$i]}
57+
TOOLCHAIN=$NDK/toolchains/${TRIPLES_PATH[$i]}/prebuilt/darwin-x86_64
58+
SYSROOT=$NDK/platforms/android-$ANDROID_API/arch-$ARCH/
59+
ISYSROOT=$NDK/sysroot
60+
ASM=$ISYSROOT/usr/include/${TRIPLES[$i]}
61+
CROSS_PREFIX=$TOOLCHAIN/bin/${TRIPLES[$i]}-
62+
PREFIX_ARCH=$PREFIX/$ARCH
63+
64+
if [ "$COMP_BUILD" = "" -o "$COMP_BUILD" = "$ARCH" ]
65+
then
66+
if [ "$ARCH" = "arm" ]
67+
then
68+
TRMP_P="eabi-v7a"
69+
PREFIX_ARCH="$PREFIX_ARCH$TRMP_P"
70+
FF_CONFIGURE_FLAGS="$FF_CONFIGURE_FLAGS --disable-asm"
71+
elif [ "$ARCH" = "arm64" ]
72+
then
73+
if [ $ANDROID_API -lt 21 ]
74+
then
75+
continue
76+
else
77+
TRMP_P="-v8a"
78+
PREFIX_ARCH="$PREFIX_ARCH$TRMP_P"
79+
FF_CONFIGURE_FLAGS="$FF_CONFIGURE_FLAGS"
80+
fi
81+
elif [ "$ARCH" = "x86_64" -a $ANDROID_API -lt 21 ]
82+
then
83+
continue
84+
else
85+
FF_CONFIGURE_FLAGS="$FF_CONFIGURE_FLAGS --disable-asm"
86+
fi
87+
else
88+
continue
89+
fi
90+
91+
FF_CFLAGS="-I$ASM -isysroot $ISYSROOT -D__ANDROID_API__=$ANDROID_API -U_FILE_OFFSET_BITS -DANDROID -fPIC"
92+
93+
./configure \
94+
--prefix=$PREFIX_ARCH \
95+
--sysroot=$SYSROOT \
96+
--host=${TRIPLES[$i]} \
97+
--cross-prefix=$CROSS_PREFIX \
98+
$FF_CONFIGURE_FLAGS \
99+
--extra-cflags="$FF_CFLAGS" \
100+
--extra-ldflags="" \
101+
$ADDITIONAL_CONFIGURE_FLAG || exit 1
102+
make -j3 install || exit 1
103+
make distclean
104+
rm -rf "$PREFIX_ARCH/lib/pkgconfig"
105+
if [[ $FF_CONFIGURE_FLAGS == *--enable-shared* ]]
106+
then
107+
mv $PREFIX_ARCH/lib/libx264.so.* $PREFIX_ARCH/lib/libx264.so
108+
fi
109+
done
110+
111+
echo "Android x264 bulid success!"
112+
113+

ffmpeg-3.4.2.tar.bz2

9.71 MB
Binary file not shown.

ffmpeg_modify_aacoder.patch

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- a/ffmpeg/libavcodec/aaccoder.c
2+
+++ b/ffmpeg/libavcodec/aaccoder.c
3+
@@ -58,12 +58,13 @@
4+
5+
/* Parameter of f(x) = a*(100/lambda), defines how much PNS is allowed to
6+
* replace low energy non zero bands */
7+
#define NOISE_LAMBDA_REPLACE 1.948f
8+
9+
#include "libavcodec/aaccoder_trellis.h"
10+
+#undef B0
11+
12+
/**
13+
* structure used in optimal codebook search
14+
*/
15+
typedef struct BandCodingPath {
16+
int prev_idx; ///< pointer to the previous path point

ffmpeg_modify_configure.patch

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/ffmpeg/configure
2+
+++ b/ffmpeg/configure
3+
@@ -3415,4 +3415,4 @@
4+
-SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
5+
-LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
6+
-SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
7+
-SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
8+
+SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
9+
+LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
10+
+SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
11+
+SLIB_INSTALL_LINKS='$(SLIBNAME)'

ffmpeg_modify_hevc_mvs.patch

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- a/ffmpeg/libavcodec/hevc_mvs.c
2+
+++ b/ffmpeg/libavcodec/hevc_mvs.c
3+
@@ -20,12 +20,13 @@
4+
* License along with FFmpeg; if not, write to the Free Software
5+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6+
*/
7+
8+
#include "hevc.h"
9+
#include "hevcdec.h"
10+
+#undef B0
11+
12+
static const uint8_t l0_l1_cand_idx[12][2] = {
13+
{ 0, 1, },
14+
{ 1, 0, },
15+
{ 0, 2, },
16+
{ 2, 0, },

ffmpeg_modify_opus_pvq.patch

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/ffmpeg/libavcodec/opus_pvq.c
2+
+++ b/ffmpeg/libavcodec/opus_pvq.c
3+
@@ -22,13 +22,14 @@
4+
* License along with FFmpeg; if not, write to the Free Software
5+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6+
*/
7+
8+
#include "opustab.h"
9+
#include "opus_pvq.h"
10+
-
11+
+#undef B0
12+
+
13+
#define CELT_PVQ_U(n, k) (ff_celt_pvq_u_row[FFMIN(n, k)][FFMAX(n, k)])
14+
#define CELT_PVQ_V(n, k) (CELT_PVQ_U(n, k) + CELT_PVQ_U(n, (k) + 1))
15+
16+
static inline int16_t celt_cos(int16_t x)
17+
{
18+
x = (MUL16(x, x) + 4096) >> 13;

x264-snapshot-20160114-2245.tar.bz2

708 KB
Binary file not shown.

x264-snapshot-20180401-2245.tar.bz2

748 KB
Binary file not shown.

x264-snapshot-20180630-2245.tar.bz2

748 KB
Binary file not shown.

0 commit comments

Comments
 (0)