您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
小编给大家分享一下Android Studio如何引入FFmpeg的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国Google公司和开放手机联盟领导及开发。
新建C++工程
新建
两个externalNativeBuild
一个sourceSets(指定so路径)
android { compileSdkVersion 29 buildToolsVersion "29.0.3" defaultConfig { ... externalNativeBuild { cmake { cppFlags "-std=c++11 -frtti -fexceptions" abiFilters 'armeabi-v7a' } } sourceSets { main { jniLibs.srcDirs = ['src/main/jniLibs'] } } } ... externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } }
复制so和include文件
编写CMakeLists.txt
以下是默认值
cmake_minimum_required(VERSION 3.4.1) add_library(native-lib SHARED native-lib.cpp #nativ-lib2.cpp 如果有其他cpp文件可以一并打包到native-lib中) #查找系统的log库,并赋值给变量log-lib find_library( log-lib log) #将上面log-lib变量里的库连接到native-lib中 target_link_libraries( native-lib ${log-lib})
CMakeLists中添加FFmpeg头文件路径
#设置FFmpeg头文件的路径 include_directories( include#因为和CMakeLists.txt在同一级,所以直接写include )
CMakeLists中添加libavcodec.so
#定义一个变量avcodec add_library( avcodec SHARED IMPORTED ) #给avcodec这个变量赋值 set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libavcodec.so) #将avcodec混合编译到native-lib中 target_link_libraries( native-lib ${log-lib} avcodec )
CMakeLists中添加全部的so
cmake_minimum_required(VERSION 3.4.1) #设置FFmpeg头文件的路径 include_directories( include#因为和CMakeLists.txt在同一级,所以直接写include ) add_library(native-lib SHARED native-lib.cpp) find_library( log-lib log) #1.定义一个变量avcodec add_library( avcodec SHARED IMPORTED ) #给avcodec这个变量赋值 set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libavcodec-57.so) #2. add_library( avdevice SHARED IMPORTED ) set_target_properties(avdevice PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libavdevice-57.so) #3. add_library( avfilter SHARED IMPORTED ) set_target_properties(avfilter PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libavfilter-6.so) #4. add_library( avformat SHARED IMPORTED ) set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libavformat-57.so) #5. add_library( avutil SHARED IMPORTED ) set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libavutil-55.so) #6. add_library( postproc SHARED IMPORTED ) set_target_properties(postproc PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libpostproc-54.so) #7. add_library( swresample SHARED IMPORTED ) set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libswresample-2.so) #8. add_library( swscale SHARED IMPORTED ) set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../main/jniLibs/${ANDROID_ABI}/libswscale-4.so) #将avcodec混合编译到native-lib中 target_link_libraries( native-lib ${log-lib} avcodec#1 avdevice#2 avfilter#3 avformat#4 avutil#5 postproc#6 swresample#7 swscale#8 )
编写测试函数
#include <jni.h> #include <string> extern "C" { #include "libavcodec/avcodec.h" } extern "C" JNIEXPORT jstring JNICALL Java_com_example_myffmpegcmd_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */) { std::string hello = "Hello from C++"; return env->NewStringUTF(avcodec_configuration()); }
以上是“Android Studio如何引入FFmpeg的方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。