Android Studio引入FFmpeg的方法
新建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' } }}
復(fù)制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中)#查找系統(tǒng)的log庫,并賦值給變量log-libfind_library( log-lib log)#將上面log-lib變量里的庫連接到native-lib中target_link_libraries( native-lib ${log-lib})
CMakeLists中添加FFmpeg頭文件路徑
#設(shè)置FFmpeg頭文件的路徑include_directories( include#因為和CMakeLists.txt在同一級,所以直接寫include)
CMakeLists中添加libavcodec.so
#定義一個變量avcodecadd_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)#設(shè)置FFmpeg頭文件的路徑include_directories( include#因為和CMakeLists.txt在同一級,所以直接寫include)add_library(native-lib SHARED native-lib.cpp)find_library( log-lib log)#1.定義一個變量avcodecadd_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)
編寫測試函數(shù)
#include <jni.h>#include <string>extern 'C' {#include 'libavcodec/avcodec.h'}extern 'C' JNIEXPORT jstring JNICALLJava_com_example_myffmpegcmd_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */) { std::string hello = 'Hello from C++'; return env->NewStringUTF(avcodec_configuration());}
總結(jié)
到此這篇關(guān)于Android Studio引入FFmpeg的文章就介紹到這了,更多相關(guān)Android Studio引入FFmpeg內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法2. Nginx+php配置文件及原理解析3. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題4. .NET中l(wèi)ambda表達式合并問題及解決方法5. JSP數(shù)據(jù)交互實現(xiàn)過程解析6. 淺談python出錯時traceback的解讀7. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解8. Ajax實現(xiàn)表格中信息不刷新頁面進行更新數(shù)據(jù)9. Python importlib動態(tài)導(dǎo)入模塊實現(xiàn)代碼10. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
