最近解码视频生成的是yuv数据,然后需要生成jpg图片,之前的方案是yuv-rgb-bmp-jpg这样的话是很慢的,计算了时间大概要300ms左右,导致多次点击照相,会造成视频画面的延迟,所以只能使用别的方案替代,在网上查询libjpeg,但是又看了一篇文章http://www.linuxsir.org/bbs/thread374093.html说libjpeg-turbo比libjpeg快了2-3倍时间,所以打算使用libjpg-turbo来实现yuv转换为jpg图像。下面是使用ndk来交叉编译libjpeg-turbo生成libjpeg-turbo.so。
1、从官网下载最新的libjpeg-turbo源码,http://sourceforge.net/projects/libjpeg-turbo/ ,现在最新的版本是libjpeg-turbo-1.2.1
2、解压缩下载的文件,然后进入,并创建jni文件夹,最后将里面的文件都拷贝到jni文件中
3、进入jni目录,然后创建配置文件(例如jconfig.h,config.h),在终端输入:
./configure --with-jpeg8
就会生成
config.status: creating config.h
config.status: creating jconfig.h4、接下来是创建Android.mk文件
# Makefile for libjpeg-turbo
##################################################
### simd ###
##################################################
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -D__ARM_HAVE_NEON
# From autoconf-generated Makefile
EXTRA_DIST = simd/nasm_lt.sh simd/jcclrmmx.asm simd/jcclrss2.asm simd/jdclrmmx.asm simd/jdclrss2.asm \
simd/jdmrgmmx.asm simd/jdmrgss2.asm simd/jcclrss2-64.asm simd/jdclrss2-64.asm \
simd/jdmrgss2-64.asm simd/CMakeLists.txt
libsimd_SOURCES_DIST = simd/jsimd_arm_neon.S \
simd/jsimd_arm.c
LOCAL_SRC_FILES := $(libsimd_SOURCES_DIST)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/simd \
$(LOCAL_PATH)/android
AM_CFLAGS := -march=armv7-a -mfpu=neon
AM_CCASFLAGS := -march=armv7-a -mfpu=neon
LOCAL_ARM_MODE=arm
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := libsimd
include $(BUILD_STATIC_LIBRARY)
######################################################
### libjpeg.so ##
######################################################
include $(CLEAR_VARS)
# From autoconf-generated Makefile
libjpeg_SOURCES_DIST = jcapimin.c jcapistd.c jccoefct.c jccolor.c \
jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
jcomapi.c jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c \
jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \
jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c \
jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c \
jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c \
jaricom.c jcarith.c jdarith.c \
turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c \
turbojpeg-mapfile
LOCAL_SRC_FILES:= $(libjpeg_SOURCES_DIST)
LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_STATIC_LIBRARIES := libsimd
LOCAL_ARM_MODE=arm
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS :=-O3 -fstrict-aliasing -fprefetch-loop-arrays -DANDROID \
-DANDROID_TILE_BASED_DECODE -DENABLE_ANDROID_NULL_CONVERT -D__ARM_HAVE_NEON
AM_CFLAGS := -march=armv7-a -mfpu=neon
AM_CCASFLAGS := -march=armv7-a -mfpu=neon
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_STATIC_LIBRARY)
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := libjpeg
include $(BUILD_SHARED_LIBRARY)
5、然后在终端输入ndk-build,结果如下:
root@zhangjie:/home/libjpeg-turbo-1.2.1/jni# ndk-build
Android NDK: WARNING: Unsupported source file extensions in /home/libjpeg-turbo-1.2.1/jni/Android.mk for module jpeg
Android NDK: turbojpeg-mapfile
Compile arm : jpeg <= jcapimin.c
Compile arm : jpeg <= jcapistd.c
Compile arm : jpeg <= jccoefct.c
Compile arm : jpeg <= jccolor.c
Compile arm : jpeg <= jcdctmgr.c
Compile arm : jpeg <= jchuff.c
Compile arm : jpeg <= jcinit.c
Compile arm : jpeg <= jcmainct.c
Compile arm : jpeg <= jcmarker.c
Compile arm : jpeg <= jcmaster.c
Compile arm : jpeg <= jcomapi.c
Compile arm : jpeg <= jcparam.c
Compile arm : jpeg <= jcphuff.c
Compile arm : jpeg <= jcprepct.c
Compile arm : jpeg <= jcsample.c
Compile arm : jpeg <= jctrans.c
Compile arm : jpeg <= jdapimin.c
Compile arm : jpeg <= jdapistd.c
Compile arm : jpeg <= jdatadst.c
Compile arm : jpeg <= jdatasrc.c
Compile arm : jpeg <= jdcoefct.c
Compile arm : jpeg <= jdcolor.c
Compile arm : jpeg <= jddctmgr.c
Compile arm : jpeg <= jdhuff.c
Compile arm : jpeg <= jdinput.c
Compile arm : jpeg <= jdmainct.c
Compile arm : jpeg <= jdmarker.c
Compile arm : jpeg <= jdmaster.c
Compile arm : jpeg <= jdmerge.c
Compile arm : jpeg <= jdphuff.c
Compile arm : jpeg <= jdpostct.c
Compile arm : jpeg <= jdsample.c
Compile arm : jpeg <= jdtrans.c
Compile arm : jpeg <= jerror.c
Compile arm : jpeg <= jfdctflt.c
Compile arm : jpeg <= jfdctfst.c
Compile arm : jpeg <= jfdctint.c
Compile arm : jpeg <= jidctflt.c
Compile arm : jpeg <= jidctfst.c
Compile arm : jpeg <= jidctint.c
Compile arm : jpeg <= jidctred.c
Compile arm : jpeg <= jquant1.c
Compile arm : jpeg <= jquant2.c
Compile arm : jpeg <= jutils.c
Compile arm : jpeg <= jmemmgr.c
Compile arm : jpeg <= jmemnobs.c
Compile arm : jpeg <= jaricom.c
Compile arm : jpeg <= jcarith.c
Compile arm : jpeg <= jdarith.c
Compile arm : jpeg <= turbojpeg.c
Compile arm : jpeg <= transupp.c
Compile arm : jpeg <= jdatadst-tj.c
Compile arm : jpeg <= jdatasrc-tj.c
Compile arm : simd <= jsimd_arm_neon.S
Compile arm : simd <= jsimd_arm.c
StaticLibrary : libsimd.a
SharedLibrary : libjpeg.so
Install : libjpeg.so => libs/armeabi/libjpeg.so