I am trying to build FFMPEG with libx264 for Android.
I can successfully build and use FFMPEG for Android but I realized that I need the ability to encode, therefore
I've put together a Android build system for ffmpeg+x264 here: https://github.com/guardianproject/android-ffmpeg
We're working on some wrapper Java too for running it, but that's not really usable yet.
I had the same problem. But after downgrading NDK to version 5c it works as described by halfninja. (ubuntu 64bit). there seem to be some changes in the toolchain from 5 to 7.
timo@serverplusplus:/tmp/android-ffmpeg-x264/Project/jni$ ndk-build
Compile thumb : ffmpeg <= ffmpeg.c
Compile thumb : ffmpeg <= cmdutils.c
Executable : ffmpeg
Install : ffmpeg => libs/armeabi/ffmpeg
Compile thumb : videokit <= uk_co_halfninja_videokit_Videokit.c
Compile thumb : videokit <= ffmpeg.c
Compile thumb : videokit <= cmdutils.c
SharedLibrary : libvideokit.so
Install : libvideokit.so => libs/armeabi/libvideokit.so
I have met the same issue before, and I tried several times to find out the reason:
You must make sure the x264 and the ffmpeg are using same way to compile. like: using Android NDK. Using the same gcc compiler.
So you can not compile ffmpeg with this command:"--cross-prefix=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-", but compile the x264 without that. Here is my x264 compile script:
./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM
make
sudo make install
sudo ldconfig
I've discovered the --enable-static option does not have any effect on ffmpeg linking behaviour for libx264. I managed to build a copy of ffmpeg with libx264 included statically by editing the config.mak after I'd run ./configure
Before
EXTRALIBS=-ldl -lX11 -lx264 etc.
After
EXTRALIBS=/home/adam/x264sourcebuild/libx264.a -ldl -lX11 etc.
These are my working flags:
x264 (a recent stable):
./configure --cross-prefix=arm-linux-androideabi- \
--enable-pic \
--enable-static \
--disable-cli \
--disable-asm \
--host=arm-linux
ffmpeg (release/0.10):
./configure --enable-cross-compile \
--arch=arm5te \
--enable-armv5te \
--target-os=linux \
--disable-stripping \
--prefix=../output \
--disable-neon \
--enable-version3 \
--disable-shared \
--enable-static \
--enable-gpl \
--enable-memalign-hack \
--cc=arm-linux-androideabi-gcc \
--ld=arm-linux-androideabi-gcc \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated" \
--disable-everything \
--enable-decoder=h264 \
--enable-demuxer=mov \
--enable-muxer=mp4 \
--enable-encoder=libx264 \
--enable-libx264 \
--enable-protocol=file \
--enable-decoder=aac \
--enable-encoder=aac \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
--enable-filter=buffer \
--enable-filter=buffersink \
--enable-filter=scale \
--disable-demuxer=v4l \
--disable-demuxer=v4l2 \
--disable-indev=v4l \
--disable-indev=v4l2 \
--extra-cflags="-I../x264" \
--extra-ldflags="-L../x264" \
--extra-libs="-lgcc"
Obviously you will have to adjust the paths.
The ffmpeg source code seems to be updated, and I could compile ffmpeg with x264 for Android NDK as the following.
1 Download the halfninja's android-ffmpeg-x264 git file from https://github.com/halfninja/android-ffmpeg-x264
2 At "halfninja-android-ffmpeg-x264-fe12be0/Project/jni" directory, modify "configure_ffmpeg.sh" to link "libgcc.a" for solving a problem that can not resolve "__aeabi_f2uiz".
./configure $DEBUG_FLAG --enable-cross-compile \
--arch=arm5te \
--enable-armv5te \
--target-os=linux \
--disable-stripping \
--prefix=../output \
--disable-neon \
--enable-version3 \
--disable-shared \
--enable-static \
--enable-gpl \
--enable-memalign-hack \
--cc=arm-linux-androideabi-gcc \
--ld=arm-linux-androideabi-ld \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -I../x264 -Ivideokit" \
$featureflags \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
--enable-filter=buffer \
--enable-filter=buffersink \
--disable-demuxer=v4l \
--disable-demuxer=v4l2 \
--disable-indev=v4l \
--disable-indev=v4l2 \
--extra-ldflags="-L../x264 -L../toolchain/lib/gcc/arm-linux-androideabi/4.4.3" \
--extra-libs="-lgcc"
3 Modify "Android.mk" to link new library "libswresample.a".
FFMPEG_LIBS := $(addprefix ffmpeg/, \
libavdevice/libavdevice.a \
libavformat/libavformat.a \
libavcodec/libavcodec.a \
libavfilter/libavfilter.a \
libswscale/libswscale.a \
libavutil/libavutil.a \
libswresample/libswresample.a \
libpostproc/libpostproc.a )
4 Replace ffmpeg.c and cmdutils.c in videokit directory with ones in ffmpeg directory.
5 Follow a procedure described in README.textile.