ffmpeg移植到android中使用

ffmpeg编译好了对应android平台的文件之后就可以移植到anroid上使用了。

一、在android studio中创建一个支持C++的项目
android studio sdk tools下载cmake、ndk。
在这里插入图片描述
将编译好的ffmpeg头文件跟so文件拷贝到android项目对应目录下。
在这里插入图片描述
二、配置相关信息
在CMakeLists.txt里面配置

cmake_minimum_required(VERSION 3.4.1)
include_directories(../../../includes)
#set ffmpeg
set(ffmpeg ${CMAKE_SOURCE_DIR}/../../../jniLibs/${ANDROID_ABI})
add_library(avcodec SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${ffmpeg}/libavcodec.so)
add_library( # Sets the name of the library.
             native-lib
             # Sets the library as a shared library.
             SHARED
             # Provides a relative path to your source file(s).
             native-lib.cpp )
##you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
              log-lib
              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

target_link_libraries( # Specifies the target library.
                       native-lib
                       avcodec
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

在build.gradle中配置,ndk设置调用armeabi-v7a,设置jniLib目录。
在这里插入图片描述
注意,这里要加上 pickFirst ‘lib/armeabi-v7a/libavcodec.so’,
否则编译时会报
More than one file was found with OS independent path ‘lib/armeabi-v7a/libavcodec.so’
在这里插入图片描述
三、调用ffmpeg
在native-lib.cpp中 调用 avcodec configuration

#include <jni.h>
#include <string>
#include <android/log.h>
#define LOG_TAG  "C_TAG"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG ,__VA_ARGS__) // 定义LOGI类型

extern "C" {
    #include <libavcodec/avcodec.h>
}

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_ffmpeg_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    //std::string hello = "avcodec configuration info ";
    std::string config = avcodec_configuration();

    LOGI("configuration %s\n",config.c_str());

    return env->NewStringUTF(config.c_str());
}

在这里插入图片描述
打印出配置信息,表示编译的ffmpeg在android调用成功。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值