Android Studio2.2.3 通过JNI引用ffmpeg库小结
修改步骤:
-
首先通过NDK14编译出libffmpeg.so ,将include目录取出
-
通过AS建立基于jni的工程项目,将include目录放到cpp下;创建jniLibs/armeabi目录,将libffmpeg.so放到里边
3.配置CMakeLists.txt
添加如下:
#add the ffmpeg lib
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/include)
add_library(ffmpeg-lib SHARED IMPORTED )
set_target_properties(ffmpeg-lib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/armeabi/libffmpeg.so)
target_link_libraries( native-lib
ffmpeg-lib #ffmpeg lib
android #use the android log lib
${log-lib} )
4.配置build.gradle
主要添加arguments 和 ndk的配置
externalNativeBuild { cmake { cppFlags " " arguments '-DANDROID_TOOLCHAIN=clang','-DANDROID_STL=gnustl_static' } ndk { abiFilters 'armeabi' } }
5.native_lib.cpp
#include <jni.h>#include <string>
#include <android/log.h>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include "libavutil/avutil.h"
}
#define LOG_TAG "MyTagFFmpeg"
#define ALOGE(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
extern "C"
jstring
Java_letv_com_myffmpeg_MainActivityFFmpeg_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello ,this is the first ffmpeg test !";
ALOGE("%s",hello.c_str());
char info[10000] = { 0 };
sprintf(info, "%s\n", avcodec_configuration());
hello += info;
return env->NewStringUTF(hello.c_str());
}
That's all.
本文转自 曾永刚 51CTO博客,原文链接:http://blog.51cto.com/zyg0227/1947097

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
AAC ADTS流解析总结
这里列出Android里将aac编码器输出的音频帧加上ADTS头的代码: + int tmpFd; + tmpFd = ::open("/data/src.aac", O_WRONLY | O_APPEND ); + if ( tmpFd < 0 ) { + LOGE("No dump decode file %s",strerror(errno)); + } + else + { + unsigned char adts_hdr[7] = {0xff, 0xf9, 0x5c, 0x80, 0x00,0x1f, 0xfc}; + + adts_hdr[3] = 0x80 | ((mConfig->inputBufferCurrentLength >> 11) & 3); + adts_hdr[4] = (mConfig->inputBufferCurrentLength >> 3) & 0xff; + adts_hdr[5] = ((mConfig->inputBufferCurrentLength & ...
-
下一篇
Android Studio2.2.3 使用教程-入门篇
最近学习下Android APK的内容,保持学习的一些文章: Android Studio 2.2.3工具使用: http://blog.csdn.net/qq_16313365/article/details/52537397 2. Android Studio SDL 2.0 ndk编译配置 http://blog.csdn.net/gongxp123456/article/details/60468548 本文转自 曾永刚 51CTO博客,原文链接:http://blog.51cto.com/zyg0227/1945405
相关文章
文章评论
共有0条评论来说两句吧...