Android 上的 FFMpeg,未定义对 libavcodec 函数的引用,尽管它在命令行中列出 [英] FFMpeg on Android, undefined references to libavcodec functions, although it is listed on command line

查看:21
本文介绍了Android 上的 FFMpeg,未定义对 libavcodec 函数的引用,尽管它在命令行中列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个未解决的对 ffmpeg 的 libavcodec 函数的引用的问题,到目前为止未能在其他地方找到答案(包括我的想法):)

I have a problem with unresolved references to ffmpeg's libavcodec functions, so far failed to find the answer in other places (including my mind) :)

让我描述一下我的设置 - 它占用空间,但非常基本,可能是我没有看到一些错误......

Let me describe my setup - it takes space, but is really basic, it might be that I'm failing to see some error...

我用 ndk r5 工具链构建了一个 FFMPeg,我从 http://bambuser.com/opensource(如此处其他问题中所推荐).它构建得很好,所以我在我的项目中放置了几个静态库,如下所示:

I built an FFMPeg with ndk r5 toolchain, ffmpeg port I got from http://bambuser.com/opensource (as recommended in other questions here). It built fine, so I put several static libraries in my project like this:

<project>/jni/bambuser_ffmpeg/libavcodec.a
<project>/jni/bambuser_ffmpeg/libavformat.a
<project>/jni/bambuser_ffmpeg/libavcore.a
<project>/jni/bambuser_ffmpeg/libavutil.a

接下来,我在 bambuser_ffmpeg 文件夹中创建了一个 Android.mk 以将这些库列为预建库:

Next, I created an Android.mk in bambuser_ffmpeg folder to list these libs as a prebuilt ones:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavcore
LOCAL_SRC_FILES := libavcore.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavformat
LOCAL_SRC_FILES := libavformat.a
include $(PREBUILT_STATIC_LIBRARY)

(same for other two libs)

接下来,我有另一个模块在其 Android.mk 中引用这些库,设置包含路径等:

Next, I have another module which references these libs in its Android.mk, sets up include paths, etc:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := ffmpegtest
LOCAL_STATIC_LIBRARIES := bambuser-libavcodec bambuser-libavcore bambuser-libavformat bambuser-libavutil
LOCAL_SRC_FILES := ffmpeg_test.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../bambuser_ffmpeg/include
LOCAL_LDLIBS    := -llog -lz

include $(BUILD_SHARED_LIBRARY)

最后我有了我的 ffmpeg_test.cpp,它非常基础,就像这样:

And finally I have my ffmpeg_test.cpp which is really basic, like this:

#include <jni.h>

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

extern "C" {
    JNIEXPORT jint JNICALL Java_com_the7art_ffmpegtest_PaintThread_testFFMpeg(JNIEnv* env, jobject obj, jstring fileName);
}

JNIEXPORT jint JNICALL Java_com_the7art_ffmpegtest_PaintThread_testFFMpeg(JNIEnv* env, jobject obj, jstring fileName)
{
    av_register_all();
    return 0;
}

当我运行 ndk-build 时,它编译得很好,但是在链接时,它打印出对 libavcodec 中几乎每个函数的未解析引用.看起来只有这个库的函数没有找到:

When I run ndk-build, it compiles fine, but when linking it prints an unresolved reference to almost every function in libavcodec. Looks like only this lib's functions are failing to be located:

/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(allformats.o): In function `av_register_all':
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/allformats.c:47: undefined reference to `avcodec_register_all'
/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `parse_frame_rate':
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:3240: undefined reference to `av_parse_video_rate'
/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `parse_image_size':
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:3234: undefined reference to `av_parse_video_size'
/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `flush_packet_queue':
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:1277: undefined reference to `av_free_packet'
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:1283: undefined reference to `av_free_packet'
/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `get_audio_frame_size':
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:766: undefined reference to `av_get_bits_per_sample'
/home/dimka/src/mobile/android/ffmpegtest/obj/local/armeabi/libavformat.a(utils.o): In function `ff_interleave_add_packet':
/home/dimka/work/suzy/tmp/ffmpeg-android/ffmpeg/libavformat/utils.c:2909: undefined reference to `av_dup_packet'
and so on...

我不明白为什么会发生这种情况.我尝试运行 ndk-build V=1 来检查实际的链接命令,并且 libavcodec 完全正确地坐在那里,就像它应该的那样.所有其他 ffmpeg 库也在那里.

I fail to figure why this is happening. I tried running ndk-build V=1 to check the actual linking command, and libavcodec is sitting there perfectly right, like it should. All other ffmpeg libs are there too.

有什么提示吗?

推荐答案

我也一直将 ffmpeg 用于一些 Android 工作.不过,我的构建有点不同.我从 bambuser.com 构建中获取 lib*.a 文件和包含目录,然后直接将它们包含在我的 jni 目录中,我的 Android.mk 看起来像这样:

I've been using ffmpeg for some Android work too. I do my build a bit different though. I take the lib*.a files and the include dir from the bambuser.com build and just directly include them in my jni directory, my Android.mk looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := ndk1
LOCAL_SRC_FILES := native.c

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LDLIBS := -L$(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-arm/usr/lib -L$(LOCAL_PATH) -lavformat -lavcodec -lavdevice -lavfilter -lavutil -lswscale -llog -ljnigraphics -lz -ldl -lgcc

include $(BUILD_SHARED_LIBRARY)

那里可能有些杂乱,但也许它会帮助您指明正确的方向.我尝试遵循 NDK 示例项目中列出的一些表单,就像您拥有的一样.将库捆绑到一个模块中,然后引用它.但最终还是回到了简单的直接包含只是为了让事情正常工作,并且到目前为止还没有理由重新审视它.

There might be some cruft in there, but maybe it'll help point you in the right direction. I tried following some of the forms laid out in the NDK example projects like you have. Bundling up the libs into a module and then referencing that. But ended up falling back on the simple direct include just to get things working, and so far haven't had reason to revisit it.

这篇关于Android 上的 FFMpeg,未定义对 libavcodec 函数的引用,尽管它在命令行中列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆