What I exactly want to-do: Access the ffmpeg.c file to modify the int main(int argc, char **argv) function to JNI and passing the command of ffmpeg as string.
I have tried to port ffmpeg C library to android(ARM processor). I followed following different ways to do this.
1st Try: using official ffmpeg installation documentation. Steps as follows
a) git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
b) Read the INSTALL file.
c) Download x264 library and build by using build_x264.sh which build successfully.
NDK=/home/nav/Work/android/ndk
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt
PLATFORM=$NDK/platforms/android-8/arch-arm
PREFIX=/home/nav/28ffmpeg/android-ffmpeg
./configure --prefix=$PREFIX --enable-static --enable-pic --disable-asm --disable-cli --host=arm-linux --cross-prefix=$PREBUILT/linux-x86/bin/arm-linux-androideabi- --sysroot=$PLATFORM
make
sudo make install
sudo ldconfig
d) Then I download ffmpeg library from (http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2) build it by using build_android.sh
#!/bin/bash
NDK=/home/nav/Work/android/ndk
PLATFORM=$NDK/platforms/android-8/arch-arm
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
PREFIX=/home/nav/28ffmpeg/android-ffmpeg
function build_one
{
./configure --target-os=linux --prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-nonfree \
--enable-version3 \
--disable-everything \
--enable-gpl \
--disable-doc \
--enable-avresample \
--enable-demuxer=rtsp \
--enable-muxer=rtsp \
--disable-ffplay \
--disable-ffserver \
--enable-ffmpeg \
--disable-ffprobe \
--enable-libx264 \
--enable-encoder=libx264 \
--enable-decoder=h264 \
--enable-protocol=rtp \
--enable-hwaccels \
--enable-zlib \
--disable-devices \
--disable-avdevice \
--extra-cflags="-I/home/android-ffmpeg/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
--extra-ldflags="-L/home/android-ffmpeg/lib"
make -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L$PREFIX/lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavfilter/libavfilter.a libavresample/libavresample.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog -lx264 --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
}
build_one
e) Initially it works perfectly. But after that error comes:
libavformat/libavformat.a(log2_tab.o):(.rodata+0x0): multiple definition of `ff_log2_tab'
libavcodec/libavcodec.a(log2_tab.o):(.rodata+0x0): first defined here
libavutil/libavutil.a(log2_tab.o):(.rodata+0x0): multiple definition of `ff_log2_tab'
libavcodec/libavcodec.a(log2_tab.o):(.rodata+0x0): first defined here
build_android.sh: 48: build_one: not found
Result: libffmpeg.so not found.
2nd Try: Then I follow steps in http://dl.dropbox.com/u/22605641/ffmpeg_android/main.html-> Builds
a) I downloaded Pre-Build libffmpeg.so from above link.
b) Add libffmpeg.so to libs/armeabi/ .
c) Make Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := libffmpeg.so
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_STATIC_LIBRARIES += ffmpeg
LOCAL_SRC_FILES := ffmpeg-test.c
include $(BUILD_SHARED_LIBRARY)
d) Then I do all ndk set up and all.Copy ffmpeg.c from library to ffmpeg-test.c by changing its int main function to my JNI functin and include all necessary include files.
Error:
Console:
/home/nav/Work/android/ndk/ndk-build all
Prebuilt : libffmpeg.so <= jni/
Install : libffmpeg.so => libs/armeabi/libffmpeg.so
Compile thumb : main <= ffmpeg-test.c
jni/ffmpeg-test.c: In function 'print_report':
jni/ffmpeg-test.c:1139:94: warning: incompatible implicit declaration of built-in function 'log2' [enabled by default]
SharedLibrary : libmain.so
/home/nav/Work/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/main/ffmpeg-test.o: in function check_keyboard_interaction:jni/ffmpeg-test.c:2496: error: undefined reference to 'qp_hist'
and many other undefined references.
https://github.com/guardianproject/android-ffmpeg
look at this project on git for clues on making changes to 'ffmpeg.c.main()' I believe that the build for this project will work fine on release of NDK mentioned in the readme.
Note:
you should spend some time with all the doc files in the NDK distro so that u understand how the make works.
The exit condition of the 'main()' function usually needs to be altered slightly for android JNI .
To fix the multiple definitions add:
But you might also want to add this config option:
This way I managed to compile the HEAD version of ffmpeg with ndk v8 but using the LGPL license which contains lots less features.
To fix the multiple defination problem you need to delete the duplicate *.o so that clashes dont happen. I was able to achieve the same using the following command.
rm /libavcodec/log2_tab.o
rm /ffmpeg-3.0.1/libavcodec/reverse.o