# cmake version, 创建native module升成
cmake_minimum_required(VERSION3.22.1)# 项目名, 创建native module升成
project("native_ffmpeg")#引入头文件, 引入include文件夹
include_directories(include)add_library(${CMAKE_PROJECT_NAME}SHARED# List C/C++ source files with relative paths to this CMakeLists.txt.
native_ffmpeg.cpp)# Set a normal, cache, or environment variable to a given value
# cmake官方这么写解释set, 设置变量
set(ANDROID_SO_DIR${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})# add_library: Add a library to the project using the specified source files.
# set_target_properties: Sets properties on targets. The syntax for the command is to list all the targets you want to change, and then provide the values you want to set next.
# avcodec
add_library(avcodecSHAREDIMPORTED)set_target_properties(avcodecPROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libavcodec.so)# avfilter
add_library(avfilterSHAREDIMPORTED)set_target_properties(avfilterPROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libavfilter.so)# avformat
add_library(avformatSHAREDIMPORTED)set_target_properties(avformatPROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libavformat.so)# avutil
add_library(avutilSHAREDIMPORTED)set_target_properties(avutilPROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libavutil.so)# postproc
add_library(postprocSHAREDIMPORTED)set_target_properties(postprocPROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libpostproc.so)# swresample
add_library(swresampleSHAREDIMPORTED)set_target_properties(swresamplePROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libswresample.so)# swscale
add_library(swscaleSHAREDIMPORTED)set_target_properties(swscalePROPERTIESIMPORTED_LOCATION${ANDROID_SO_DIR}/libswscale.so)# Specify libraries or flags to use when linking a given target and/or its dependents.
# 还是cmake官方的解释
target_link_libraries(${CMAKE_PROJECT_NAME}# List libraries link to the target library
androidlog# ffmpeg libs
avcodecavfilteravformatavutilpostprocswresampleswscale)
#include<jni.h>#include<string>// CPP中添加C的头文件
extern"C"{#include<libavcodec/avcodec.h>}extern"C"JNIEXPORTjstringJNICALLJava_com_example_native_1ffmpeg_NativeLib_stringFromJNI(JNIEnv*env,jobject/* this */){returnenv->NewStringUTF(avcodec_configuration());}