Chinaunix首页 | 论坛 | 博客
  • 博客访问: 63373
  • 博文数量: 8
  • 博客积分: 207
  • 博客等级: 入伍新兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-24 13:42
文章分类
文章存档

2012年(8)

分类: 嵌入式

2012-06-04 22:22:14


1.       利用ndk自带sample中的hello-jni,将好的libffmpeg.soffmpeg源码拷贝到hello-jnijni目录,我的为F:\android-ndk-r7b\samples\hello-jni\jni

目录结构如下:

 

2.       修改hello-jni.c

点击(此处)折叠或打开

  1. /*

  2.  * Copyright (C) 2009 The Android Open Source Project

  3.  *

  4.  * Licensed under the Apache License, Version 2.0 (the "License");

  5.  * you may not use this file except in compliance with the License.

  6.  * You may obtain a copy of the License at

  7.  *

  8.  * http://www.apache.org/licenses/LICENSE-2.0

  9.  *

  10.  * Unless required by applicable law or agreed to in writing, software

  11.  * distributed under the License is distributed on an "AS IS" BASIS,

  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  13.  * See the License for the specific language governing permissions and

  14.  * limitations under the License.

  15.  *

  16.  */

  17.  

  18. #include <string.h>

  19. #include <stdio.h>

  20. #include <android/log.h>

  21. #include <stdlib.h>

  22. #include <jni.h>

  23. #include <ffmpeg/libavcodec/avcodec.h>

  24.  

  25. /* This is a trivial JNI example where we use a native method

  26.  * to return a new VM String. See the corresponding Java source

  27.  * file located at:

  28.  *

  29.  * apps/samples/hello-jni/project/src/com/example/HelloJni/HelloJni.java

  30.  */

  31. jstring

  32. Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,

  33.                                                   jobject thiz )

  34. {

  35.          char str[50] = {0};

  36.          char ver[25] = {0};

  37.       sprintf(ver, "%d", avcodec_version());

  38.       strcpy(str,"Hello from JNI ! + ffmpeg ver:");

  39.       strcat(str,ver);

  40.       return (*env)->NewStringUTF(env, str);

  41. }

 

3.       修改android.mk如下:


点击(此处)折叠或打开

  1. # Copyright (C) 2009 The Android Open Source Project

  2. #

  3. # Licensed under the Apache License, Version 2.0 (the "License");

  4. # you may not use this file except in compliance with the License.

  5. # You may obtain a copy of the License at

  6. #

  7. # http://www.apache.org/licenses/LICENSE-2.0

  8. #

  9. # Unless required by applicable law or agreed to in writing, software

  10. # distributed under the License is distributed on an "AS IS" BASIS,

  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  12. # See the License for the specific language governing permissions and

  13. # limitations under the License.

  14. #

  15. LOCAL_PATH := $(call my-dir)

  16.  

  17. #copy libffmpeg.so to libs

  18. include $(CLEAR_VARS)

  19. LOCAL_MODULE := libffmpeg-prebuild

  20. LOCAL_SRC_FILES := libffmpeg.so

  21. LOCAL_MODULE_TAGS := prebuild

  22. include $(PREBUILT_SHARED_LIBRARY)

  23.  

  24. #generate libhello-jni.so to libs

  25. include $(CLEAR_VARS)

  26. PATH_TO_FFMPEG_SOURCE := $(LOCAL_PATH)/ffmpeg

  27. LOCAL_C_INCLUDES += $(PATH_TO_FFMPEG_SOURCE)

  28. #LOCAL_LDLIBS := -lffmpeg

  29. LOCAL_SHARED_LIBRARIES := libffmpeg-prebuild

  30. LOCAL_MODULE := hello-jni

  31. LOCAL_SRC_FILES := hello-jni.c

  32.  

  33. include $(BUILD_SHARED_LIBRARY)

4.       ndk编译

Cygwin命令行里$NDK/ndk-build,会在hello-jni目录下生成连个目录obj,libs.

而生成的.so会在libs/armeabi目录下     

 

 

5.       将工程导入到eclipse,修改hello-jni.java如下:

    static {

        System.loadLibrary("ffmpeg");

        System.loadLibrary("hello-jni");

}

 

 

6.       运行工程:

   

   3475456就是ffmpeg avcodec version.

阅读(2973) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~