FFMpeg jni在Android中? [英] FFMpeg jni in Android?

查看:119
本文介绍了FFMpeg jni在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了由Bambuser(http://bambuser.com/opensource)提供的FFMPEG可执行文件和库。所以我设法构建Android的可执行文件和图书馆。如何在Eclipse项目中链接这些库并从Java调用FFmpeg函数?开源代码包括C头文件。



我是Android的原生编码的新手,我找不到一个简单的答案。在基本的:有一堆Android兼容的库和一些C头文件我需要做什么来重用Java(+ Android SDK)中的这些库的功能?



任何帮助将不胜感激。



请问,



WhyHow

解决方案

您必须使用JNI约定编写一些C粘贴代码才能将FFmpeg功能公开到Java代码。以下是来自Android NDK样本的C中实现的JNI方法的示例:

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

您还需要一些Java代码来加载库并声明本机方法。

  public class HelloJni 
{
public native String stringFromJNI();

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

我发现 sourceforge上的这个项目,它已经实现了一些JFI接口,将其与Java Media Framework进行集成。您可能会发现它很有用。



另外还有一个名为JNA(Java Native Access)的Java FFI技术,可以使用Java声明本机函数原型,并直接调用它们。使用它可能需要较少的样板代码。有关Android实施,请参阅此项目。 (我从来没有使用过它)


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

解决方案

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)

这篇关于FFMpeg jni在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆