第18课 移植FFmpeg和openCV到Android环境

2024-01-08 13:12:06

要在Android下从事音视频开发,同样也绕不开ffmpeg+opencv,不管是初学者还是有一定经验的程序,面临的首要问题就是环境的搭建和库文件的编译配置等问题,特别是初学者,往往会在实际开发前浪费大量的时间来编译ffmpeg及opencv的动态库.so文件。因此作者整理了自己实际开发用的ffmpeg及opencv库文件(ffmpeg已集成x264+aac+mp3编码),并集成到Eclipse开发环境中(JNI方式)实际运行成功后作为一个模板提供给大家,方便初学者快速上手进行实际开发,节省您大量宝贵时间。当然,Android SDK和NDK需要自己下载,然后在Eclipse中指定相应路径就可以了。

1.下载模板文件到本地磁盘并解压,解压后的路径如E:\jPro\demo\AndroidManifest.xml。

2.启动eclipse并导入该项目。

3.导入后如图所示:

4.用usb连接线把你的手机与电脑连接起来并允许在手机上调试项目。

5.右单击项目并选择调试为Android程序。

6.选中手机单击ok按钮会在手机上安装应用,安装成功后显示如下界面则表示成功。

然后你就可以在此基础上自由的开发了!

现在,让我们回过头来看下与jni有关的重要选项。

7./demo/jni/Android.mk内容如下:

LOCAL_PATH := $(call my-dir)


#ffmpeg lib
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES := lib/libavcodec.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avdevice
LOCAL_SRC_FILES := lib/libavdevice.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avfilter
LOCAL_SRC_FILES := lib/libavfilter.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avformat
LOCAL_SRC_FILES := lib/libavformat.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := lib/libavutil.so
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := postproc
LOCAL_SRC_FILES := lib/libpostproc.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swresample
LOCAL_SRC_FILES := lib/libswresample.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES := lib/libswscale.so
include $(PREBUILT_SHARED_LIBRARY)

#x264 lib
include $(CLEAR_VARS)
LOCAL_MODULE := libx264
LOCAL_SRC_FILES := lib/libx264.161.so
include $(PREBUILT_SHARED_LIBRARY)

#opencv lib
include $(CLEAR_VARS)
LOCAL_MODULE := opencv
LOCAL_SRC_FILES :=lib/libopencv_java3.so
include $(PREBUILT_SHARED_LIBRARY)

#demo
include $(CLEAR_VARS)
LOCAL_MODULE    := demo
LOCAL_SRC_FILES := demo.cpp


LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
##-landroid for native windows
LOCAL_LDLIBS := -llog -landroid 
#LOCAL_LDLIBS := -llog -lz 
LOCAL_SHARED_LIBRARIES :=opencv libx264 avcodec avdevice avfilter avformat avutil postproc swresample swscale


include $(BUILD_SHARED_LIBRARY)

8./demo/jni/Application.mk:

APP_ABI := armeabi-v7a
APP_STL:=gnustl_static  
APP_CPPFLAGS:=-frtti -fexceptions  

文章来源:https://blog.csdn.net/XiBuQiuChong/article/details/135450094
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。