FFmpeg包装器(适用于Android)

时间:2019-02-23 11:29:19

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

我成功编译了ffmpeg并获得了.so文件,这些文件用于不同的拱门,例如amreabi,armeabi-v7a等。

我设法通过自己的CMakeLists.txt包装器使用.cpp将这些预构建的库集成到我的android项目中。问题是我没有C ++技能。因此,使用ffmpeg的另一种方法是调用main()的{​​{1}}函数。 This链接介绍了操作步骤。

在我的项目中:

  

结构

Structure

  

Application.mk

ffmpeg.c
  

Android.mk

APP_ABI := armeabi-v7a
APP_PLATFORM := android-21
  

ffmpeg / android / armeabi-v7a / Android.mk

LOCAL_PATH := $(call my-dir)
#$(warning $(LOCAL_PATH))

include $(CLEAR_VARS)
LOCAL_MODULE    := libffmpeg
LOCAL_LDLIBS := -llog -ljnigraphics -lz -landroid
LOCAL_CFLAGS := -Wdeprecated-declarations
ANDROID_LIB := -landroid
LOCAL_C_INCLUDES:=./ffmpeg
LOCAL_SRC_FILES :=  ffmpeg_controller.c ffmpeg.c ffmpeg_filter.c ffmpeg_opt.c cmdutils.c
LOCAL_SHARED_LIBRARIES := libavformat libavcodec libswscale libavutil libswresample libavfilter libavdevice

include $(BUILD_SHARED_LIBRARY)
$(call import-add-path,D:/My-Project/app/src/main/jni)
$(call import-module,ffmpeg/android/armeabi-v7a)
  

build.gradle

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE:= libavdevice
LOCAL_SRC_FILES:= lib/libavdevice-57.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

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

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

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

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

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

include $(CLEAR_VARS)
LOCAL_MODULE:= libswresample
LOCAL_SRC_FILES:= lib/libswresample-2.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

在生成项目之后,它在... ndk { abiFilters "armeabi", "armeabi-v7a" } ... packagingOptions { exclude 'META-INF/LICENSE' doNotStrip "*/armeabi/*.so" doNotStrip "*/armeabi-v7a/*.so" doNotStrip "*/x86/*.so" doNotStrip "*/x86_64/*.so" doNotStrip "*/arm64-v8a/*.so" } ... sourceSets.main { jniLibs.srcDir 'src/main/libs' jni.srcDirs = ["jni"] //disable automatic ndk-build call } lintOptions { warning 'InvalidPackage' warning 'MissingPermission' warning 'MissingConstraints' } externalNativeBuild { ndkBuild { path 'src/main/jni/Android.mk' } } ffmpeg/*.c文件以及ffmpeg/*.hjni/ffmpeg.c等文件中给出了许多错误。错误类似于“找不到config.h” “找不到libavformat / os_support.h” 。如果我将jni/cmdutils.c文件从config.h添加到jni/文件夹中,并将ffmpeg/替换为libavformat/os_support.h,则错误消失了,但是语法为ffmpeg/libavformat/os_support.h错误仍然存​​在。根据教程,我不能在源代码中进行此类更改,并且一切都可以。

我做错了什么?我还能在Android Project中使用ffmpeg命令行工具吗?

Android NDK版本-13b, FFmpeg版本-3.0.12

1 个答案:

答案 0 :(得分:0)

我还发现包装器是在Android上处理ffmpeg的最简单方法-与您采用的方法类似。

我确实设法构建并运行了ffmpeg包装器,但是在此过程中发现了很多问题,并且仅针对当时正在使用的特定系统架构。

如果我要再做一次(或者即使我必须在完成本次练习后5分钟再做一次……),我肯定会使用一个受良好支持的常用开源包装器。最受欢迎的两个是:

这些通常已经解决了您必须查找和解决的问题,否则还可以支持多种系统体系结构。