[英]Using openssl with FFmpeg on Android with NDK
I cross compiled FFmpeg with openssl support using the scripts from the Guardian project however my code crashes whenever I execute the following:我使用 Guardian 项目中的脚本交叉编译了支持 openssl 的 FFmpeg,但是每当我执行以下操作时,我的代码就会崩溃:
System.loadLibrary("crypto"); // loads OK
System.loadLibrary("ssl"); // loads OK
System.loadLibrary("avformat"); // crashes
The error:错误:
dlopen("/data/data/wseemann.media.demo/lib/libavformat.so") failed: dlopen failed: cannot locate symbol "SSL_library_init" referenced by "libavformat.so"...
I build libavformat with a toolchain and then run ndk-build using the following Android.mk file to create the .so files:我使用工具链构建 libavformat,然后使用以下 Android.mk 文件运行 ndk-build 以创建 .so 文件:
LOCAL_PATH := $(call my-dir)
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)
It would seem that libavformat needs libcrypto and libssl when it is loaded but it can't find them or isn't loading them.似乎 libavformat 在加载时需要 libcrypto 和 libssl 但找不到它们或没有加载它们。 Does anyone know how to fix this issue?
有谁知道如何解决这个问题?
The problem is that there normally is libssl.so
in /system/lib
. 问题是通常在
/system/lib
中有libssl.so
。 The loader System.loadLibrary() prefers that path to your app lib directory ( /data/data/your.package.name/lib
), and this is what may cause confusion. 加载程序System.loadLibrary()首选使用该路径到您的应用程序lib目录(
/data/data/your.package.name/lib
),这可能会引起混乱。 The easiest fix is to use System.load("/data/data/your.package.name/lib/libssl.so") instead (there are correct ways to obtain the path, too). 最简单的解决方法是改为使用System.load(“ / data / data / your.package.name / lib / libssl.so”) (也有正确的方法来获取路径)。
Another fix could be to rename libssl.so
that you prepared, to libavssl.so
, and call System.loadLibrary("avssl")
. 另一个解决方法是将您准备的
libssl.so
重命名为libavssl.so
,然后调用System.loadLibrary("avssl")
。 Note that maybe you will be required to recompile libavformat
so that it looks for libavssl.so
. 请注意, 也许您可能需要重新编译
libavformat
才能查找libavssl.so
。
This worked for me in FFmpegMediaPlayer.java line 614:这在 FFmpegMediaPlayer.java 第 614 行对我有用:
static {
System.loadLibrary("crypto"); // loads OK
System.loadLibrary("ssl"); // loads OK
for (int i = 0; i < JNI_LIBRARIES.length; i++) {
Log.d("TAG", JNI_LIBRARIES[i]);
System.loadLibrary(JNI_LIBRARIES[i]);
}
native_init();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.