Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMpeg jni in Android?

Tags:

android

ffmpeg

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

like image 710
Whyhow Avatar asked Dec 05 '10 08:12

Whyhow


People also ask

Does FFmpeg work on Android?

Android doesn't have efficient and robust APIs for multimedia which could provide functionalities like FFmpeg. The only API which android has is MediaCodec API, but it is faster than FFmpeg because it uses the device hardware for video processing.

What is FFmpeg in Android?

FFmpeg is a free and open-source software project consisting of a large suite of libraries and programs for handling video, audio, and other multimedia files and streams. The FFmpeg core itself designed for the command-line-based processing of multimedia files.

Is JNI an android?

JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).

What is NDK and JNI?

JNI is just the way that Java handles calling into native/C++ code, and calling back into Java from there. It has nothing to say about Android - it is a Java language feature. The Android NDK is a way to write Android applications using code called by JNI.


1 Answers

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)

like image 64
Alex Jasmin Avatar answered Oct 21 '22 04:10

Alex Jasmin