Android NDK中的FFMPEG - 无法加载库" libavfilter.so"

时间:2015-01-16 19:26:20

标签: android android-ndk ffmpeg java-native-interface libav

我正在尝试使用FFMPEG使用Android NDK裁剪视频。我可以成功构建ffmpeg,但我遇到了libavfilter的问题。一旦我将它包含在Android.mk中的LOCAL_SHARED_LIBRARIES中,我就会得到这个UnsatisfiedLinkError:

java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libavfilter.so" needed by "videocrop.so"; caused by cannot locate symbol "avcodec_find_best_pix_fmt_of_2" referenced by "libavfilter.so"...
        at java.lang.Runtime.loadLibrary(Runtime.java:371)
        at java.lang.System.loadLibrary(System.java:989)

(我正在尝试使用System.loadLibrary在Java端的静态初始化程序中加载我的库。)

“avcodec_find_best_pix_fmt_of_2”函数存在于libavcodec / avcodec.h中,所以我不知道它为什么找不到它。 libavfilter.so文件(以及所有其他库)似乎构建得很好,位于libs /文件夹中。我已经尝试编辑FFMPEG配置和重建,并尝试更改Android.mk中的LOCAL_C_INCLUDES以包含libavcodec的头文件,但没有任何运气。

这是我的模块的Android.mk:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := videocrop
LOCAL_CFLAGS :=
LOCAL_SRC_FILES := VideoCrop.c
    LOCAL_C_INCLUDES += $(LOCAL_PATH)/../ffmpeg/ffmpeg/$(TARGET_ARCH)/include/libavcodec/
    LOCAL_SHARED_LIBRARIES := libavformat libavutil libavcodec libavfilter

    LOCAL_LDLIBS := -llog
    LOCAL_LDFLAGS +=-ljnigraphics

    include $(BUILD_SHARED_LIBRARY)

这是ffmpeg库本身的Android.mk,虽然非常简单:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libavfilter
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

LOCAL_PATH:= $(call my-dir)

我已经结束了。如果有人有任何想法,将非常感激。

1 个答案:

答案 0 :(得分:1)

您需要以反向依赖顺序加载库,例如像这样:

System.loadLibrary("avutil");
System.loadLibrary("avcodec");
System.loadLibrary("avformat");
System.loadLibrary("swscale");
System.loadLibrary("avfilter");
System.loadLibrary("videocrop");

参见例如这篇文章了解更多详情:Loading shared libs that depend on other shared libs