我放了一个编译好的版本,地址:https://www.raoyunsoft.com/public/bzblog/libyuvbuild.zip
libyuv是Google开源的一款处理YUV的底层库,下载地址:https://chromium.googlesource.com/libyuv/libyuv 可惜这个地址被墙了,我下载下来了,放到我服务器上了,地址:https://www.raoyunsoft.com/public/bzblog/libyuv.zip 好了接下来就是编译了,首先我们新建一个文件夹叫libyuvbuild,让后把libyuv目录拖进去,并重命名为jni(这么做事为了方便ndk-build),如图所示:
然后就是修改Android.mk了,由于libyuv默认是需要libjpeg参与编译,这个库是负责解码图片,我们在Android开发中一般是不会用到的,直接去掉就好了,最终Android.mk修改如下:
# This is the Android makefile for libyuv for NDK.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := \
source/compare.cc \
source/compare_common.cc \
source/compare_gcc.cc \
source/compare_mmi.cc \
source/compare_msa.cc \
source/compare_neon64.cc \
source/compare_neon.cc \
source/compare_win.cc \
source/convert_argb.cc \
source/convert.cc \
source/convert_from_argb.cc \
source/convert_from.cc \
source/convert_to_argb.cc \
source/convert_to_i420.cc \
source/cpu_id.cc \
source/planar_functions.cc \
source/rotate_any.cc \
source/rotate_argb.cc \
source/rotate.cc \
source/rotate_common.cc \
source/rotate_gcc.cc \
source/rotate_mmi.cc \
source/rotate_msa.cc \
source/rotate_neon64.cc \
source/rotate_neon.cc \
source/rotate_win.cc \
source/row_any.cc \
source/row_common.cc \
source/row_gcc.cc \
source/row_mmi.cc \
source/row_msa.cc \
source/row_neon64.cc \
source/row_neon.cc \
source/row_win.cc \
source/scale_any.cc \
source/scale_argb.cc \
source/scale.cc \
source/scale_common.cc \
source/scale_gcc.cc \
source/scale_mmi.cc \
source/scale_msa.cc \
source/scale_neon64.cc \
source/scale_neon.cc \
source/scale_win.cc \
source/video_common.cc
common_CFLAGS := -Wall -fexceptions
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_MODULE := libyuv_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_WHOLE_STATIC_LIBRARIES := libyuv_static
LOCAL_MODULE := libyuv
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := libyuv_static
LOCAL_MODULE_TAGS := tests
LOCAL_CPP_EXTENSION := .cc
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_SRC_FILES := \
unit_test/unit_test.cc \
unit_test/basictypes_test.cc \
unit_test/color_test.cc \
unit_test/compare_test.cc \
unit_test/convert_test.cc \
unit_test/cpu_test.cc \
unit_test/cpu_thread_test.cc \
unit_test/math_test.cc \
unit_test/planar_test.cc \
unit_test/rotate_argb_test.cc \
unit_test/rotate_test.cc \
unit_test/scale_argb_test.cc \
unit_test/scale_test.cc \
unit_test/video_common_test.cc
LOCAL_MODULE := libyuv_unittest
include $(BUILD_NATIVE_TEST)
再然后就是添加Application.mk支持多种CPU架构,文件内容如下:
NDK_TOOLCHAIN_VERSION := clang
APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
APP_CPPFLAGS := -std=c++11 -frtti -fexceptions
APP_PLATFORM := android-11
APP_STL := gnustl_static
#APP_CFLAGS+=-DDLIB_NO_GUI_SUPPORT=on
#APP_CFLAGS+=-DDLIB_PNG_SUPPORT=off
APP_CFLAGS+=-DDLIB_JPEG_SUPPORT=on
APP_CFLAGS+=-DDLIB_JPEG_STATIC=on
最后就是cd 到libyuvbuild目录然后执行ndk-build就好了,默认会编译静态和动态库(需要注意ndk-build的环境变量是添加过来),编译过的结果如下:
libyuv的封装:https://120.27.239.50/wordpress/index.php/2020/05/25/androidlibyuv/
Hi there, I enjoy reading through your article post.
I like to write a little comment to support you.