导入FFmpeg遇到的各种问题

问题1:java.lang.UnsatisfiedLinkError: dlopen failed: file offset for the library 

一般原因是libs下.so库文件损坏,重新拷贝放入即可

 

问题2: error: undefined reference to 

引入头文件需要写到extern "c"里面才行

导入FFmpeg遇到的各种问题_第1张图片

 

问题3:目录so库找不到   ninja: error: '/libavutil-55.so', needed by 'E:/xy/hly/MyFFmpeg/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so', missing and no known rule to make it

在CMakeList.txt文件中设置的.so库路径错误,参考如下(注意:CMakeList.txt的位置,新版本自动生成的CMakeList.txt再cpp目录下)不正确参考错误日志修改路径正确即可

导入FFmpeg遇到的各种问题_第2张图片

 

问题4:include头文件引入位置错误

导入的include头文件报错,在我的项目里是将include文件加拷贝放在cpp目录下,然后用统一替换功能在导入位置前面加../,如下图

导入FFmpeg遇到的各种问题_第3张图片导入FFmpeg遇到的各种问题_第4张图片

 

 

目录结构如下:

导入FFmpeg遇到的各种问题_第5张图片

导入FFmpeg遇到的各种问题_第6张图片

 

native-lib.cpp文件

#include 
#include 

extern "C"
{
//写里面才行
#include "include/libavformat/avformat.h"
#include "include/libavcodec/avcodec.h"
#include "include/libavutil/avutil.h"
#include "include/libavfilter/avfilter.h"


jstring
Java_demo_xy_com_myffmpeg_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

jstring
Java_demo_xy_com_myffmpeg_MainActivity_urlprotocolinfo(
        JNIEnv *env, jobject) {
    char info[40000] = {0};
    av_register_all();

    struct URLProtocol *pup = NULL;

    struct URLProtocol **p_temp = &pup;
    avio_enum_protocols((void **) p_temp, 0);

    while ((*p_temp) != NULL) {
        sprintf(info, "%sInput: %s\n", info, avio_enum_protocols((void **) p_temp, 0));
    }
    pup = NULL;
    avio_enum_protocols((void **) p_temp, 1);
    while ((*p_temp) != NULL) {
        sprintf(info, "%sInput: %s\n", info, avio_enum_protocols((void **) p_temp, 1));
    }
    return env->NewStringUTF(info);
}

jstring
Java_demo_xy_com_myffmpeg_MainActivity_avformatinfo(
        JNIEnv *env, jobject) {
    char info[40000] = {0};

    av_register_all();

    AVInputFormat *if_temp = av_iformat_next(NULL);
    AVOutputFormat *of_temp = av_oformat_next(NULL);
    while (if_temp != NULL) {
        sprintf(info, "%sInput: %s\n", info, if_temp->name);
        if_temp = if_temp->next;
    }
    while (of_temp != NULL) {
        sprintf(info, "%sOutput: %s\n", info, of_temp->name);
        of_temp = of_temp->next;
    }
    return env->NewStringUTF(info);
}

jstring
Java_demo_xy_com_myffmpeg_MainActivity_avcodecinfo(
        JNIEnv *env, jobject) {
    char info[40000] = {0};

    av_register_all();

    AVCodec *c_temp = av_codec_next(NULL);

    while (c_temp != NULL) {
        if (c_temp->decode != NULL) {
            sprintf(info, "%sdecode:", info);
        } else {
            sprintf(info, "%sencode:", info);
        }
        switch (c_temp->type) {
            case AVMEDIA_TYPE_VIDEO:
                sprintf(info, "%s(video):", info);
                break;
            case AVMEDIA_TYPE_AUDIO:
                sprintf(info, "%s(audio):", info);
                break;
            default:
                sprintf(info, "%s(other):", info);
                break;
        }
        sprintf(info, "%s[%10s]\n", info, c_temp->name);
        c_temp = c_temp->next;
    }

    return env->NewStringUTF(info);
}

jstring
Java_demo_xy_com_myffmpeg_MainActivity_avfilterinfo(
        JNIEnv *env, jobject) {
    char info[40000] = {0};
    avfilter_register_all();

    AVFilter *f_temp = (AVFilter *)avfilter_next(NULL);
    while(f_temp != NULL) {
        sprintf(info, "%s%s\n", info, f_temp->name);
        f_temp = f_temp->next;
    }
    return env->NewStringUTF(info);
}
}

 

你可能感兴趣的:(jni&ndk)