title: Unable to port FFmpeg C library into android
body: <p><strong>What I exactly want to-do</strong>: Access the <strong>ffmpeg.c</strong> file to modify the <strong>int main(int argc, char **argv)</strong> function to <strong>JNI</strong> and passing the command of ffmpeg as string.</p>
  
  <p>I have tried to port ffmpeg C library to android(ARM processor). I followed following different ways to do this.</p>
  
  <p>1st Try: using official ffmpeg installation documentation. Steps as follows</p>
  
  <p>a) git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg</p>
  
  <p>b) Read the INSTALL file.</p>
  
  <p>c) Download x264 library and build by using <strong>build_x264.sh</strong> which build successfully.   </p>
  
  <pre><code>    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
  </code></pre>
  
  <p>d) Then I download <strong>ffmpeg library</strong> from (<a href="http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2" rel="nofollow noreferrer">http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2</a>) build it by using <strong>build_android.sh</strong></p>
  
  <pre><code>#!/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
  </code></pre>
  
  <p>e) Initially it works perfectly. But after that <strong>error</strong> comes:  </p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Result:</strong> <strong>libffmpeg.so</strong> not found.</p>
  
  <p>2nd Try: Then I follow steps in <a href="http://dl.dropbox.com/u/22605641/ffmpeg_android/main.html" rel="nofollow noreferrer">http://dl.dropbox.com/u/22605641/ffmpeg_android/main.html</a>-> Builds</p>
  
  <p>a) I downloaded Pre-Build <strong>libffmpeg.so</strong> from above link.</p>
  
  <p>b) Add <strong>libffmpeg.so</strong> to <strong>libs/armeabi/</strong> .</p>
  
  <p>c) Make <strong>Android.mk</strong> </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>d) Then I do all ndk set up and all.Copy <strong>ffmpeg.c</strong> from library to <strong>ffmpeg-test.c</strong> by changing its <strong>int main</strong> function to my <strong>JNI</strong> functin and include all necessary include files.</p>
  
  <p><strong>Error:</strong> </p>
  
  <p><strong>Console:</strong></p>
  
  <pre><code>  /home/nav/Work/android/ndk/ndk-build all 
  Prebuilt       : libffmpeg.so &lt;= jni/
  Install        : libffmpeg.so =&gt; libs/armeabi/libffmpeg.so
  Compile thumb  : main &lt;= 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'
  </code></pre>
  
  <p>and many other undefined references.</p>