libyuv是Google开源的实现各种YUV与RGB之间相互转换、旋转、缩放的库。支持在Windows、Linux、Mac、等平台 和x86、x64、arm架构上进行编译执行,支持SSE、AVX、NEON等SIMD指令加速。
##下载
下载地址:
https://code.google.com/p/libyuv/source/checkout
或者
https://github.com/lemenkov/libyuv
##编译
ubuntu 下编译:
- android-ndk-r13b
- git
下载:
git clone https://github.com/lemenkov/libyuv.git
下载后是libyuv,其目录如下:
配置ndk环境
gedit .bashrc
//在里面添加ndk环境如下
export PATH="/home/lammy/ffmpeg/android-ndk-r13b/:$PATH"
source .bashrc
新建jni目录
按其他博客说的只需要执行 ndk-build
就可以了,但我执行一直报错:
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/home/lammy/ffmpeg/android-ndk-r13b/build/core/build-local.mk:151: *** Android NDK:
Aborting . Stop.
后来查了很多资料后才得知,ndk只编译jin,所以在libyuv 下面新建了jni目录,然后将所有文件拷贝进去。
修改Android.mk文件
将LOCAL_MODULE := libyuv-static
替换为LOCAL_MODULE := libyuv
(这里只是修改编译的库名,可不操作)
将include $(BUILD_STATIC_LIBRARY)
替换为include $(BUILD_SHARED_LIBRARY)
# This is the Android makefile for libyuv for both platform and 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_neon64.cc \
source/compare_gcc.cc \
source/convert.cc \
source/convert_argb.cc \
source/convert_from.cc \
source/convert_from_argb.cc \
source/convert_to_argb.cc \
source/convert_to_i420.cc \
source/cpu_id.cc \
source/planar_functions.cc \
source/rotate.cc \
source/rotate_any.cc \
source/rotate_argb.cc \
source/rotate_common.cc \
source/rotate_mips.cc \
source/rotate_neon64.cc \
source/rotate_gcc.cc \
source/row_any.cc \
source/row_common.cc \
source/row_mips.cc \
source/row_neon64.cc \
source/row_gcc.cc \
source/scale.cc \
source/scale_any.cc \
source/scale_argb.cc \
source/scale_common.cc \
source/scale_mips.cc \
source/scale_neon64.cc \
source/scale_gcc.cc \
source/video_common.cc
# TODO(fbarchard): Enable mjpeg encoder.
# source/mjpeg_decoder.cc
# source/convert_jpeg.cc
# source/mjpeg_validate.cc
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_CFLAGS += -DLIBYUV_NEON
LOCAL_SRC_FILES += \
source/compare_neon.cc.neon \
source/rotate_neon.cc.neon \
source/row_neon.cc.neon \
source/scale_neon.cc.neon
endif
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
#LOCAL_MODULE := libyuv-static
LOCAL_MODULE := libyuv
LOCAL_MODULE_TAGS := optional
# include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
然后回到libyuv目录执行:
ndk-build clean
ndk-build
则可以看到生成objec和lib目录
libs下就是我们编译的库文件
在android上为了使用,我们得将jni/include/libyuv 目录拷贝出来,是头文件和so一起,方便ndk 底层c使用。
这里给出我编译好的so和头文件压缩包,欢迎各位老铁下载。