我试图在Android应用中使用FFmpeg 3.1.3。 ' libavcodec-57.so'在主活动中加载,如下所示:
static {
LogUtil.e("DEVICE ARCH", System.getProperty("os.arch"));
System.loadLibrary("avutil-55");
System.loadLibrary("avcodec-57");
}
logcat给了我:(时间不重要)
E/DEVICE ARCH: armv7l
D/dalvikvm: Trying to load lib /data/app-lib/<package_name>-1/libavutil-55.so 0x4d11fe10
D/houdini: [5955] Loading library(version: 4.1.1a_y.45536 RELEASE)... successfully.
D/dalvikvm: Added shared lib /data/app-lib/<package_name>-1/libavutil-55.so 0x4d11fe10
D/dalvikvm: No JNI_OnLoad found in /data/app-lib/<package_name>-1/libavutil-55.so 0x4d11fe10, skipping init
D/dalvikvm: Trying to load lib /data/app-lib/<package_name>-1/libavcodec-57.so 0x4d11fe10
D/houdini: [5955] Unsupported feature (ID:0x10600ccf).
D/houdini: [5955] Open Native Library /data/app-lib/<package_name>-1/libavcodec-57.so failed.
E/dalvikvm: Houdini dlopen("/data/app-lib/<package_name>-1/libavcodec-57.so") failed: Cannot load ARM library
W/dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lapp/Activity/MainActivity;
W/dalvikvm: Class init failed in newInstance call (Lapp/Activity/MainActivity;)
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4c810160)
W/TDLog: UncaughtException in Thread main
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/<package_name>-1/libavcodec-57.so" has unexpected e_machine: 40
at java.lang.Runtime.loadLibrary(Runtime.java:364)
at java.lang.System.loadLibrary(System.java:526)
at <package_name>.Activity.MainActivity.<clinit>(MainActivity.java:128)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2141)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2273)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
它说该设备的拱门是 ARM 。 libavcodec-57.so
无法加载,e_machine: 40
表示预期的拱门也是ARM(请参阅ELF header doc)。
此外,libavutil-55.so
和libavcodec-57.so
都位于同一目录中。
答案 0 :(得分:1)
解决方案是在加载之前加载libavcodec-57.so
所需的所有库。
执行readelf -d libavcodec-57.so | grep NEEDED
将获得所需的库:
0x00000001 (NEEDED) Shared library: [libswresample-2.so]
0x00000001 (NEEDED) Shared library: [libavutil-55.so]
0x00000001 (NEEDED) Shared library: [libx264-148.so]
0x00000001 (NEEDED) Shared library: [libfaac.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libz.so]
0x00000001 (NEEDED) Shared library: [libc.so]
除了内置库libm
,libz
和libc
之外,所有需要的库都应该在 <{strong> libavcodec-57.so
之前加载。所以Java代码改变如下:
static {
System.loadLibrary("faac");
System.loadLibrary("x264-148");
System.loadLibrary("avutil-55");
System.loadLibrary("swresample-2"); // need x264 and avutil
System.loadLibrary("avcodec-57"); // need all of the above
}