title: Running ffmpeg as library in android
body: <p>I've got a simple task to do. I need to merge set of pictures into a video using ffmpeg working in android environment. </p>
  
  <p>After over a week fighting with different tutorials and examples explaining how to run compile  ffmpeg I have, let's say, middle success. I've finally compiled ffmpeg for android. </p>
  
  <p>I followed this example:
  <a href="https://github.com/appunite/AndroidFFmpeg" rel="nofollow noreferrer">https://github.com/appunite/AndroidFFmpeg</a>
  which worked best for me. </p>
  
  <p>As a result of building ffmpeg a have following directory structure:</p>
  
  <pre><code>[Project]/jni/ffmpeg-build/armeabi-v7a/libffmpeg.so
  [Project]/jni/ffmpeg-build/armeabi/libffmpeg.so
  [Project]/jni/ffmpeg-build/mips/libffmpeg.so
  [Project]/jni/ffmpeg-build/x86/libffmpeg.so
  </code></pre>
  
  <p>I also followed the ndk examples so I have running c code from java:</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;jni.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;assert.h&gt;    
  #include &lt;android/log.h&gt;    
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  bool initted = false;    
  static JavaVM *sVm;
  
  jstring Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv* env, jobject thiz) {
  
      char **argv;
      char *cmd;
      int argc;
  
  //  cmd = "ffmpeg -version";
  //  argv = parsedargs(cmd, &amp;argc);
  //  ffmpeg(argc, argv);
  
      return (*env)-&gt;NewStringUTF(env, "Hello from JNI !");
  
  }
  </code></pre>
  
  <p>My question is how to run function from ffmpeg from my "hello-jni" c-file. I've read I need to write a wrapper over ffmpeg which my hello-jni is intended to be.</p>
  
  <p>Here is my Android.mk which probably is importat part to achieve my goal, but honestly I don't understand some lines set in this file. Or simply I don't know how to make things work.</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  LOCAL_MODULE := ffmpeg-prebuilt
  LOCAL_SRC_FILES := ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so
  LOCAL_EXPORT_C_INCLUDES := ffmpeg-build/$(TARGET_ARCH_ABI)/include
  LOCAL_EXPORT_LDLIBS := ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so
  LOCAL_PRELINK_MODULE := true
  include $(PREBUILT_SHARED_LIBRARY)
  
  
  include $(CLEAR_VARS)
  LOCAL_ALLOW_UNDEFINED_SYMBOLS=true
  LOCAL_MODULE    := hello-jni
  LOCAL_SRC_FILES := hello-jni.c
  LOCAL_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-build/$(TARGET_ARCH_ABI)/include
  LOCAL_SHARED_LIBRARY := ffmpeg-prebuilt
  #LOCAL_CFLAGS += -g -Iffmpeg-prebuilt -Ihello-jni -Wno-deprecated-declarations 
  #LOCAL_LDLIBS += -llog -lz -landroid ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so 
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p>One more thing. I've found an example how to wrap ffmpeg's main function. It'd be the easiest way to use ffmpeg for me sinse I don't know ffmpeg's api and I hope it's possible to run ffmpeg this way:
  <a href="https://stackoverflow.com/questions/2401764/can-ffmpeg-be-used-as-a-library-instead-of-a-standalone-program">Can FFmpeg be used as a library, instead of a standalone program?</a></p>
  
  <p>To sum up, I think my problems are due to completely lack of c/c++ knowledge at all, especially how to use run any function from .so library.</p>
  
  <p>I hope someone can help me :). </p>