10

I have built FFMPEG executables and libraries as provided by Bambuser (http://bambuser.com/opensource). So I managed to build the Android executables and libraties. How can I link these libs in my Eclipse project and invoke the FFmpeg functions from Java? The open source code includes the C header-files.

I am new to native coding for Android, and I could not find an easy answer for this. In basic : having a bunch of Android compatible libraries and some C header files what do I have to do to reuse those libaries' functionality from java (+Android SDK)?

Any help would be appreciated.

Kind regards,

WhyHow

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Whyhow
  • 101
  • 2
  • 4
  • could you please tell the steps you followed to build ffmpeg? I am using windows and cygwin 1.7.9 . – Swathi EP Sep 20 '11 at 05:58
  • After a lot of research, it appears that there are some filename/filepath convention issues that will not let you compile ffmpeg using Windows. I used vmware to install Ubuntu and compiled them that way. – gtcompscientist Dec 18 '11 at 06:22
  • @Swathi EP: Almost guide threads are working on Linux or Mac OS not on Windows. I haven't found out any posts for Windows yet, but I have find out the website that contained libs already built for android. So you can download them and use right now. That website is http://code.google.com/p/javacv/downloads/list, good luck! – Levanphong7887 Oct 08 '12 at 04:52

1 Answers1

5

You have to write some C glue code using the JNI conventions to expose the FFmpeg functionalities to Java code. Here's an example of a JNI method implemented in C from the Android NDK samples:

jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
    return (*env)->NewStringUTF(env, "Hello from JNI !");
}

You also need some Java code to load the library and declare the native method.

public class HelloJni
{
    public native String  stringFromJNI();

     static {
        System.loadLibrary("hello-jni");
    }
}

I found this project on sourceforge which already has implemented some JNI interface to ffmpeg to integrate it with the Java Media Framework. You may find it useful.

There's another Java FFI technology called JNA (Java Native Access) that allows you to declare native function prototypes in Java and call them directly. Using it may require less boilerplate code. See this project for an Android implementation. (I have never used it myself)

Alex Jasmin
  • 39,094
  • 7
  • 77
  • 67