NDK使用libffmpeg.so文件测试

来源:互联网 发布:java二叉树非递归遍历 编辑:程序博客网 时间:2024/05/15 16:55
步骤参考http://tq09931.iteye.com/blog/1011895
1、将编译好的ffmpeg.so文件加入到NDK/platforms/android-9(2.3)/usr/lib中
2、新建Android工程,和原来一样,在工程代码下面建一个jni文件夹。此文件夹是用来放相关的C语言代码。将ffmpeg代码copy到jni文件下。
3、编写android.mk文件。
LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)PATH_TO_FFMPEG_SOURCE:=$(LOCAL_PATH)/ffmpegLOCAL_C_INCLUDES += $(PATH_TO_FFMPEG_SOURCE)LOCAL_LDLIBS := -lffmpegLOCAL_MODULE    := hello-jniLOCAL_SRC_FILES := hello-jni.cinclude $(BUILD_SHARED_LIBRARY)


4、编写hello-jni.c代码
#include <string.h>#include <stdio.h>#include <android/log.h>#include <stdlib.h>#include <jni.h>#include <ffmpeg/libavcodec/avcodec.h>/* This is a trivial JNI example where we use a native method* to return a new VM String. See the corresponding Java source* file located at:**   apps/samples/hello-jni/project/src/com/example/HelloJni/HelloJni.java*/jstringJava_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,                                                  jobject thiz ){    char str[25];    sprintf(str, "%d", avcodec_version());    return (*env)->NewStringUTF(env, str);}



使用~/android..../ndk-build命令进行编译。注意,最好在每个platform下都拷贝一份编译出来的libffmpeg.so文件,因为不知道到底是用哪个平台进行编译的

编译出来的libhello-jni.so文件

5、把libffmpeg.so文件也拷贝到上述文件夹下
6、修改java文件,加上
System.LoadLibrary("ffmpeg");
7、配置eclipse,让其支持相关的C++文件以及用ndk-build进行编译。
步骤参见http://www.cnblogs.com/luxiaofeng54/archive/2011/08/13/2136982.html
8、使用模拟器push libffmpeg.so到/System/lib下面的时候会报read-only file和out of memory两种错误
#emulator -partition-size 256 -avd 2.1
#adb remount

之后重新push就ok了
热泪盈眶。。。终于第一个NDK编译ok了


原创粉丝点击