gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:25:04 25 4
gpt4 key购买 nike

我正在尝试使用 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 端的静态初始化程序中加载我的库)。

libavcodec/avcodec.h中有“avcodec_find_best_pix_fmt_of_2”函数,不知道为什么找不到。 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)

我已经无计可施了。如果有人有任何想法,我们将不胜感激。

最佳答案

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

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

关于android - Android NDK 中的 FFMPEG - 无法加载库 "libavfilter.so",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27991329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com