Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions Android.mk
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
LOCAL_PATH := $(call my-dir)

ifeq ($(TARGET_ARCH_ABI),x86)
LIB_VERSION=x86
else
LIB_VERSION=neon
endif

include $(CLEAR_VARS)

LOCAL_MODULE := encoding

# These need to be in the right order
FFMPEG_LIBS := $(addprefix ffmpeg/, \
libavdevice/libavdevice.a \
libavformat/libavformat.a \
libavcodec/libavcodec.a \
libavfilter/libavfilter.a \
libavresample/libavresample.a \
libswscale/libswscale.a \
libswresample/libswresample.a \
libavutil/libavutil.a \
libpostproc/libpostproc.a )
FFMPEG_LIBS := $(addprefix ./build/ffmpeg/$(LIB_VERSION)/lib/, \
libavdevice.a \
libavformat.a \
libavcodec.a \
libavfilter.a \
libavresample.a \
libswscale.a \
libswresample.a \
libavutil.a \
libpostproc.a )


# ffmpeg uses its own deprecated functions liberally, so turn off that annoying noise
LOCAL_CFLAGS += -g -Iffmpeg -Irun -Wno-deprecated-declarations
LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) x264/libx264.a
LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) ./build/x264/$(LIB_VERSION)/lib/libx264.a
LOCAL_SRC_FILES := run/co_vine_android_recorder_Processor.c run/ffmpeg.c run/cmdutils.c
include $(BUILD_SHARED_LIBRARY)

Expand All @@ -27,4 +37,4 @@ LOCAL_MODULE := ffmpeginvoke
LOCAL_SRC_FILES := ffmpeg_invoke/ffmpeg_invoke.c
LOCAL_LDLIBS := -ldl

include $(BUILD_SHARED_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
112 changes: 68 additions & 44 deletions FFmpeg-Android.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
#!/bin/bash
DEST=`pwd`/build/ffmpeg && rm -rf $DEST
SOURCE=`pwd`/ffmpeg
X264_DEST=`pwd`/build/x264 && rm -rf $X264_DEST
X264_SOURCE=`pwd`/x264

TOOLCHAIN=/tmp/vplayer
SYSROOT=$TOOLCHAIN/sysroot/
TOOLCHAIN_ARM=/tmp/vplayer-arm
TOOLCHAIN_X86=/tmp/vplayer-x86
SYSROOT_ARM=$TOOLCHAIN_ARM/sysroot/
SYSROOT_X86=$TOOLCHAIN_X86/sysroot/
EXTRA_ARM_CFLAGS="-mthumb -fstrict-aliasing -Werror=strict-aliasing -D__ARM_ARCH_5__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__ -Wl,--fix-cortex-a8"

export PATH=$TOOLCHAIN/bin:$PATH
export CC="ccache arm-linux-androideabi-gcc"
export LD=arm-linux-androideabi-ld
export AR=arm-linux-androideabi-ar
export PATH=$TOOLCHAIN_ARM/bin:$TOOLCHAIN_X86/bin:$PATH

CFLAGS="-O3 -Wall -mthumb -pipe -fpic -fasm \
CFLAGS="-O3 -Wall -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"

X264_FLAGS="--cross-prefix=arm-linux-androideabi- \
--enable-pic --enable-static -Wl --fix-cortex-a8 \
--prefix=$PREFIX \
--host=arm-linux"
X264_FLAGS="--enable-pic --enable-static"

FFMPEG_FLAGS="--target-os=linux \
--arch=arm \
--enable-cross-compile \
--cross-prefix=arm-linux-androideabi- \
--enable-shared \
--disable-symver \
--disable-doc \
Expand Down Expand Up @@ -55,10 +49,16 @@ FFMPEG_FLAGS="--target-os=linux \
--enable-gpl \
--enable-version3"

if [ -d $TOOLCHAIN ]; then
echo "Toolchain is already built."
if [ -d $TOOLCHAIN_ARM ]; then
echo "arm toolchain is already built."
else
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-14 --install-dir=$TOOLCHAIN
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-14 --install-dir=$TOOLCHAIN_ARM
fi

if [ -d $TOOLCHAIN_X86 ]; then
echo "x86 toolchain is already built."
else
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-14 --arch=x86 --install-dir=$TOOLCHAIN_X86
fi


Expand All @@ -68,15 +68,6 @@ else
git submodule update --init
fi

if [ -f $X264_SOURCE/libx264.a ]; then
echo "libx264 is already built."
else
echo "configure and make x264"
cd $X264_SOURCE
./configure $X264_FLAGS
make STRIP=
fi

if [ -d ffmpeg ]; then
echo "ffmpeg is already cloned and patched."
cd ffmpeg
Expand All @@ -94,43 +85,75 @@ else
fi


for version in neon; do

cd $SOURCE

for version in neon x86; do
case $version in
neon)
EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad"
TOOLCHAIN_PREFIX=arm-linux-androideabi
TARGET_ARCH=arm
TARGET_ARCH_X264=arm
EXTRA_CFLAGS="$EXTRA_ARM_CFLAGS -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
LIB_SUB="armeabi-v7a"
LOCAL_ARM_NEON= true
;;
armv7)
EXTRA_CFLAGS="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp"
TOOLCHAIN_PREFIX=arm-linux-androideabi
TARGET_ARCH=arm
TARGET_ARCH_X264=arm
EXTRA_CFLAGS="$EXTRA_ARM_CFLAGS -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
LIB_SUB="armeabi-v7a"
LOCAL_ARM_NEON= false
;;
vfp)
EXTRA_CFLAGS="-march=armv6 -mfpu=vfp -mfloat-abi=softfp"
TOOLCHAIN_PREFIX=arm-linux-androideabi
TARGET_ARCH=arm
TARGET_ARCH_X264=arm
EXTRA_CFLAGS="$EXTRA_ARM_CFLAGS -march=armv6 -mfpu=vfp -mfloat-abi=softfp"
EXTRA_LDFLAGS=""
;;
armv6)
EXTRA_CFLAGS="-march=armv6"
TOOLCHAIN_PREFIX=arm-linux-androideabi
TARGET_ARCH=arm
TARGET_ARCH_X264=arm
EXTRA_CFLAGS="$EXTRA_ARM_CFLAGS -march=armv6"
EXTRA_LDFLAGS=""
LOCAL_ARM_NEON := false
;;
x86)
TOOLCHAIN_PREFIX=i686-linux-android
TARGET_ARCH=x86
TARGET_ARCH_X264=i686
EXTRA_CFLAGS="-mtune=atom -mssse3 -mfpmath=sse"
EXTRA_LDFLAGS=""
EXTRA_FFMPEG_FLAGS="--disable-avx"
LIB_SUB="x86"
;;
*)
EXTRA_CFLAGS=""
EXTRA_LDFLAGS=""
;;
esac

export CC="ccache $TOOLCHAIN_PREFIX-gcc"
export LD=$TOOLCHAIN_PREFIX-ld
export AR=$TOOLCHAIN_PREFIX-ar

X264_PREFIX="$X264_DEST/$version" && mkdir -p $X264_PREFIX

if [ -f $X264_DEST/$version/lib/libx264.a ]; then
echo "libx264.a ($TARGET_ARCH) is already built."
else
echo "configure and make x264"
cd $X264_SOURCE
./configure --cross-prefix=$TOOLCHAIN_PREFIX- --prefix=$X264_PREFIX --host=$TARGET_ARCH_X264-linux $X264_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS" | tee $X264_PREFIX/configuration.txt
make clean
make -j4 STRIP= || exit 1
make install || exit 1
fi

PREFIX="$DEST/$version" && mkdir -p $PREFIX
FFMPEG_FLAGS="$FFMPEG_FLAGS --prefix=$PREFIX"

cd $SOURCE
echo "Configure ffmpeg for $version."
./configure $FFMPEG_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS -I$X264_SOURCE" --extra-ldflags="$EXTRA_LDFLAGS -L$X264_SOURCE" | tee $PREFIX/configuration.txt
./configure --prefix=$PREFIX --arch=$TARGET_ARCH --cross-prefix=$TOOLCHAIN_PREFIX- $FFMPEG_FLAGS $EXTRA_FFMPEG_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS -I$X264_PREFIX/include" --extra-ldflags="$EXTRA_LDFLAGS -L$X264_PREFIX/lib" | tee $PREFIX/configuration.txt
cp config.* $PREFIX
[ $PIPESTATUS == 0 ] || exit 1

Expand All @@ -140,12 +163,13 @@ for version in neon; do

rm libavcodec/inverse.o

cd ..
$ANDROID_NDK/ndk-build -d -e TARGET_ARCH_ABI=$LIB_SUB LOCAL_ARM_NEON=$LOCAL_ARM_NEON
#mv ../libs/armeabi ../libs/$LIB_SUB
#mv ../libs/armeabi ../libs/$LIB_SUB
#$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 -o $PREFIX/libffmpeg.so

#cp $PREFIX/libffmpeg.so $PREFIX/libffmpeg-debug.so
#arm-linux-androideabi-strip --strip-unneeded $PREFIX/libffmpeg.so
done

done
cd ..
$ANDROID_NDK/ndk-build -d -e APP_ABI="armeabi-v7a x86" LOCAL_ARM_NEON=true

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ http://vec.io/posts/how-to-build-ffmpeg-with-android-ndk
0. Install git, Android ndk
1. `$ export ANDROID_NDK=/path/to/your/android-ndk`
2. `$ ./FFmpeg-Android.sh`
3. libencoding.so and libffmpeginvoke.so will be built to `build/ffmpeg/{neon,armv7,vfp,armv6}/`
3. libencoding.so and libffmpeginvoke.so will be built to `build/ffmpeg/{neon,armv7,vfp,armv6,x86}/`