1)把编译生成的so库复制到libs文件夹下,同时把include里面的头文件也复制到libs文件夹下。

2)在build.gradle中添加一下代码

defaultConfig {        applicationId "com.houde.ffmpeg.test"        minSdkVersion 21        targetSdkVersion 28        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"        externalNativeBuild {            cmake {                cppFlags "-frtti -fexceptions"                abiFilters 'armeabi-v7a'            }        }        sourceSets{            main{                jniLibs.srcDirs = ['libs']            }        }        ndk{            abiFilters 'armeabi-v7a'        }    }

3)在CMakeList.txt中添加一下代码

include_directories(libs/include)set(DIR ${CMAKE_SOURCE_DIR}/libs)add_library(avcodec        SHARED        IMPORTED)set_target_properties(avcodec        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libavcodec.so)add_library(avdevice        SHARED        IMPORTED)set_target_properties(avdevice        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libavdevice.so)add_library(avformat        SHARED        IMPORTED)set_target_properties(avformat        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libavformat.so)add_library(avutil        SHARED        IMPORTED)set_target_properties(avutil        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libavutil.so)add_library(postproc        SHARED        IMPORTED)set_target_properties(postproc        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libpostproc.so)add_library(swresample        SHARED        IMPORTED)set_target_properties(swresample        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libswresample.so)add_library(swscale        SHARED        IMPORTED)set_target_properties(swscale        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libswscale.so)add_library(avfilter        SHARED        IMPORTED)set_target_properties(avfilter        PROPERTIES IMPORTED_LOCATION        ${DIR}/armeabi-v7a/libavfilter.so)add_library( # Sets the name of the library.        native-lib        # Sets the library as a shared library.        SHARED        # Provides a relative path to your source file(s).        src/main/cpp/native-lib.cpp)target_link_libraries( # Specifies the target library.        native-lib        avfilter        avcodec        avdevice        avformat        avutil        postproc        swresample        swscale        # Links the target library to the log library        # included in the NDK.        ${log-lib})

4)检查配置的so是否正确,在native-lib.cpp文件中引入libavcodec/avcodec.h,修改返回的字符串内容:

 std::string hello = avcodec_configuration();    return env->NewStringUTF(hello.c_str());

显示结果:

错误记录:
1)ffmpeg函数不能被识别
编译是出现" undefined reference to 'avcodec_register_all()"和“Error:(15) undefined reference to 'avcodec_configuration()”,错误如下

Error:(15) undefined reference to 'avcodec_register_all()'Error:(15) undefined reference to 'avcodec_configuration()'

这是因为ffmpeg是一个纯C语言编写的库,使用C++调用C代码时候,需要使用“extern “C””包围头文件“avcodec.h”和相关代码,如下:

#include #include #ifdef __cplusplusextern "C" {#endif#include "libavcodec/avcodec.h"#include "libavutil/avutil.h"JNIEXPORT jstring JNICALLJava_com_houde_ffmpeg_test_MainActivity_stringFromJNI(        JNIEnv *env,        jobject /* this */) {    std::string hello = avcodec_configuration();    return env->NewStringUTF(hello.c_str());}#ifdef __cplusplus};#endif

参考文章:
https://www.jianshu.com/p/435bb46b33a9
https://blog.csdn.net/eieihihi/article/details/74153201

更多相关文章

  1. Android游戏引擎AndEngine使用注意事项
  2. mac下反编译android apk
  3. 发布一个Android打电话的例子
  4. Android(安卓)Unparsed aapt error(s)! Check the console for o
  5. Android浏览器开发 WebView setBlockNetworkImage来龙去脉
  6. Android(安卓)4.0源代码windows平台下载方法
  7. Android(安卓)Compatibility Test Suite
  8. android 设置textview跑马灯效果
  9. android 常用混淆

随机推荐

  1. Android(安卓)Paint
  2. Android的UI主线程和子线程
  3. Android 4.4 音量调节流程分析(一)
  4. Android 中几个重要的View
  5. Linux下搭建Android开发环境及Android真
  6. android中实现view的更新UI有两组方法的
  7. android Animation动画效果基础
  8. Android(安卓)View 绘制流程之四:绘制流程
  9. 《Android开发从零开始》――18.消息处理
  10. Android(安卓)之 Activity的加载模式