1.
利用ndk自带sample中的hello-jni,将好的libffmpeg.so和ffmpeg源码拷贝到hello-jni的jni目录,我的为F:\android-ndk-r7b\samples\hello-jni\jni。
目录结构如下:
2.
修改hello-jni.c
- /*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
- #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
- */
- jstring
- Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
- jobject thiz )
- {
- char str[50] = {0};
- char ver[25] = {0};
- sprintf(ver, "%d", avcodec_version());
- strcpy(str,"Hello from JNI ! + ffmpeg ver:");
- strcat(str,ver);
- return (*env)->NewStringUTF(env, str);
- }
3.
修改android.mk如下:
- # Copyright (C) 2009 The Android Open Source Project
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- LOCAL_PATH := $(call my-dir)
-
- #copy libffmpeg.so to libs
- include $(CLEAR_VARS)
- LOCAL_MODULE := libffmpeg-prebuild
- LOCAL_SRC_FILES := libffmpeg.so
- LOCAL_MODULE_TAGS := prebuild
- include $(PREBUILT_SHARED_LIBRARY)
-
- #generate libhello-jni.so to libs
- include $(CLEAR_VARS)
- PATH_TO_FFMPEG_SOURCE := $(LOCAL_PATH)/ffmpeg
- LOCAL_C_INCLUDES += $(PATH_TO_FFMPEG_SOURCE)
- #LOCAL_LDLIBS := -lffmpeg
- LOCAL_SHARED_LIBRARIES := libffmpeg-prebuild
- LOCAL_MODULE := hello-jni
- LOCAL_SRC_FILES := hello-jni.c
-
- 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.
阅读(2982) | 评论(0) | 转发(0) |