Android搭建ffmpeg环境

创建一个Android项目,添加c++支持

Android搭建ffmpeg环境

 

 

 静态库复制到制定目录

 

Android搭建ffmpeg环境

 

 

 

支持的平台

Android搭建ffmpeg环境

 

 

 Android搭建ffmpeg环境

 

 

 

加载文件的目录

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
        }
    }

配置文件

cmake_minimum_required(VERSION 3.10.2)

project("ffmpeddemo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(libs ${CMAKE_SOURCE_DIR}/../libs)
set(libname play)  #编译之后的名字  不一样要和文件名相同

#编译的文件 在include文件夹下、、、

include_directories(
        include
        play
        utils
        play/decor
        play/decor/base
#        ${CMAKE_SOURCE_DIR}/util
)

link_directories(
        ${libs}/${ANDROID_ABI})

#编译那些文件
file(GLOB src-files
        ${CMAKE_SOURCE_DIR}/*.cpp
        ${CMAKE_SOURCE_DIR}/play/*.cpp
        ${CMAKE_SOURCE_DIR}/play/*.h
        ${CMAKE_SOURCE_DIR}/utils/*.cpp
        ${CMAKE_SOURCE_DIR}/utils/*.h
        ${CMAKE_SOURCE_DIR}/play/decor/*.cpp
        ${CMAKE_SOURCE_DIR}/play/decor/*.h
        ${CMAKE_SOURCE_DIR}/play/decor/base/*.cpp
        ${CMAKE_SOURCE_DIR}/play/decor/base/*.h
        )

add_library( # Sets the name of the library.
        ${libname}
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
        ${src-files}  #加入的就是上面指定文件下的所有
        )

set(third-party-libs
        avformat
        avcodec
        avfilter
        swresample
        swscale
        avutil
        fdk-aac
        x264
        )

set(native-libs
        android
        log
        OpenSLES
        )

target_link_libraries( # Specifies the target library.
        ${libname}
        ${log-lib}
        ${third-party-libs}
        ${native-libs}
        android
        z
        )

  编写测试代码

extern "C"
JNIEXPORT jstring JNICALL
Java_com_kangwang_ffmpeddemo_FFmpegdiaPlayer_native_1version(JNIEnv *env, jobject thiz) {
    string hello = av_version_info();
    string avutil = to_string(avutil_version());
    hello.append(avutil);
    LOGCATI("avutil");
    return env->NewStringUTF(hello.c_str());
}

  java层测试代码

    public String versionInfo() {
        return native_version();
    }

    private native String native_version();

  

https://github.com/wangwangla/learnffmpeg

 

上一篇:在线常用库 + API手册


下一篇:百度ai文字识别 安卓SDK导入防坑记