Android开发

Android搭建ffmpeg环境

本文主要是介绍Android搭建ffmpeg环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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

 

 

 静态库复制到制定目录

 

 

 

 

支持的平台

 

 

 

 

 

 

加载文件的目录

    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

 

这篇关于Android搭建ffmpeg环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!