x264 android移植 ndk下编译
1.下载x264源码(我的版本是x264-snapshot-20130215-2245)
http://www.videolan.org/developers/x264.html
2.解压,生成x264-snapshot-20130215-2245目录,我这改成x264(只为简单),进到x264目录下,新建jni目录,将其他的所有文件及文件夹放到jni目录下
3.进到x264/jni目录下,在终端中打开,并运行
- lx@PC120288:~/x264/jni$ ./configure --disable-asm
4.打开config.h文件,将里面的所有内容替换为
- #define HAVE_MALLOC_H 1
- #define ARCH_ARM 1
- #define SYS_LINUX 0
- #define HAVE_POSIXTHREAD 1
- #define HAVE_CPU_COUNT 1
- #define HAVE_THREAD 1
- #define HAVE_LOG2F 0
- #define HAVE_SWSCALE 0
- #define HAVE_VECTOREXT 1
- #define fseek fseeko
- #define ftell ftello
- #define HAVE_GPL 1
- #define HAVE_INTERLACED 1
- #define HAVE_ALTIVEC 0
- #define HAVE_ALTIVEC_H 0
- #define HAVE_MMX 0
- #define HAVE_ARMV6 0
- #define HAVE_ARMV6T2 0
- #define HAVE_NEON 0
- #define HAVE_BEOSTHREAD 0
- #define HAVE_WIN32THREAD 0
- #define HAVE_VISUALIZE 0
- #define HAVE_LAVF 0
- #define HAVE_FFMS 0
- #define HAVE_GPAC 0
- #define HAVE_GF_MALLOC 0
- #define HAVE_AVS 0
5.新建Android.mk文件,里面的内容为
- LOCAL_PATH := $(call my-dir)
- include $(CLEAR_VARS)
- CONFIG := $(shell cat config.h)
- SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
- common/frame.c common/dct.c common/cpu.c common/cabac.c \
- common/common.c common/osdep.c common/rectangle.c \
- common/set.c common/quant.c common/deblock.c common/vlc.c \
- common/mvpred.c common/bitstream.c \
- encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
- encoder/set.c encoder/macroblock.c encoder/cabac.c \
- encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
- SRCCLI = x264.c input/input.c input/timecode.c input/raw.c input/y4m.c \
- output/raw.c output/matroska.c output/matroska_ebml.c \
- output/flv.c output/flv_bytestream.c filters/filters.c \
- filters/video/video.c filters/video/source.c filters/video/internal.c \
- filters/video/resize.c filters/video/cache.c filters/video/fix_vfr_pts.c \
- filters/video/select_every.c filters/video/crop.c filters/video/depth.c
- # GPL-only files
- ifneq ($(findstring HAVE_GPL 1, $(CONFIG)),)
- SRCCLI +=
- endif
- # Optional module sources
- ifneq ($(findstring HAVE_AVS 1, $(CONFIG)),)
- SRCCLI += input/avs.c
- endif
- ifneq ($(findstring HAVE_THREAD 1, $(CONFIG)),)
- SRCCLI += input/thread.c
- SRCS += common/threadpool.c
- endif
- ifneq ($(findstring HAVE_WIN32THREAD 1, $(CONFIG)),)
- SRCS += common/win32thread.c
- endif
- ifneq ($(findstring HAVE_LAVF 1, $(CONFIG)),)
- SRCCLI += input/lavf.c
- endif
- ifneq ($(findstring HAVE_FFMS 1, $(CONFIG)),)
- SRCCLI += input/ffms.c
- endif
- ifneq ($(findstring HAVE_GPAC 1, $(CONFIG)),)
- SRCCLI += output/mp4.c
- endif
- # Visualization sources
- ifneq ($(findstring HAVE_VISUALIZE 1, $(CONFIG)),)
- SRCS += common/visualize.c common/display-x11.c
- endif
- # NEON optims
- ASMSRC += common/arm/cpu-a.S common/arm/pixel-a.S common/arm/mc-a.S \
- common/arm/dct-a.S common/arm/quant-a.S common/arm/deblock-a.S \
- common/arm/predict-a.S
- SRCS += common/arm/mc-c.c common/arm/predict-c.c
- ifneq ($(HAVE_GETOPT_LONG),1)
- SRCCLI += extras/getopt.c
- endif
- LOCAL_SRC_FILES := $(SRCS) $(SRCCLI) $(ASMSRC)
- LOCAL_C_INCLUDES := \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/input \
- $(LOCAL_PATH)/output \
- $(LOCAL_PATH)/encoder \
- $(LOCAL_PATH)/filters \
- $(LOCAL_PATH)/filters/video \
- $(LOCAL_PATH)/common \
- $(LOCAL_PATH)/common/arm \
- LOCAL_PRELINK_MODULE := false
- LOCAL_MODULE := libx264
- LOCAL_CFLAGS+= -std=c99
- LOCAL_CFLAGS+= -lpthread -lm
- LOCAL_ARM_MODE:= arm
- LOCAL_MODULE_TAGS := optional
- include $(BUILD_SHARED_LIBRARY)
6.运行
- lx@PC120288:~/x264/jni$ ndk-build
7.有报错,是两个汇编文件,注释掉出错的对应行(在出错的行前面加'#'注释)
8.再次编译运行,即可生成so库,我这边的结果如下
- Compile arm : x264 <= mc.c
- Compile arm : x264 <= predict.c
- Compile arm : x264 <= pixel.c
- Compile arm : x264 <= macroblock.c
- Compile arm : x264 <= frame.c
- Compile arm : x264 <= dct.c
- Compile arm : x264 <= cpu.c
- Compile arm : x264 <= cabac.c
- Compile arm : x264 <= common.c
- Compile arm : x264 <= osdep.c
- Compile arm : x264 <= rectangle.c
- Compile arm : x264 <= set.c
- Compile arm : x264 <= quant.c
- Compile arm : x264 <= deblock.c
- Compile arm : x264 <= vlc.c
- Compile arm : x264 <= mvpred.c
- Compile arm : x264 <= bitstream.c
- Compile arm : x264 <= analyse.c
- Compile arm : x264 <= me.c
- Compile arm : x264 <= ratecontrol.c
- Compile arm : x264 <= set.c
- Compile arm : x264 <= macroblock.c
- Compile arm : x264 <= cabac.c
- Compile arm : x264 <= cavlc.c
- Compile arm : x264 <= encoder.c
- Compile arm : x264 <= lookahead.c
- Compile arm : x264 <= threadpool.c
- Compile arm : x264 <= mc-c.c
- /home/lx/x264/jni/common/arm/mc-c.c: In function 'x264_weight_cache_neon':
- /home/lx/x264/jni/common/arm/mc-c.c:89: warning: assignment discards qualifiers from pointer target type
- /home/lx/x264/jni/common/arm/mc-c.c:94: warning: assignment discards qualifiers from pointer target type
- /home/lx/x264/jni/common/arm/mc-c.c:99: warning: assignment discards qualifiers from pointer target type
- /home/lx/x264/jni/common/arm/mc-c.c:101: warning: assignment discards qualifiers from pointer target type
- /home/lx/x264/jni/common/arm/mc-c.c: In function 'x264_mc_init_arm':
- /home/lx/x264/jni/common/arm/mc-c.c:236: warning: assignment discards qualifiers from pointer target type
- /home/lx/x264/jni/common/arm/mc-c.c:237: warning: assignment discards qualifiers from pointer target type
- /home/lx/x264/jni/common/arm/mc-c.c:238: warning: assignment discards qualifiers from pointer target type
- Compile arm : x264 <= predict-c.c
- Compile arm : x264 <= x264.c
- Compile arm : x264 <= input.c
- Compile arm : x264 <= timecode.c
- Compile arm : x264 <= raw.c
- Compile arm : x264 <= y4m.c
- Compile arm : x264 <= raw.c
- Compile arm : x264 <= matroska.c
- Compile arm : x264 <= matroska_ebml.c
- Compile arm : x264 <= flv.c
- Compile arm : x264 <= flv_bytestream.c
- Compile arm : x264 <= filters.c
- Compile arm : x264 <= video.c
- Compile arm : x264 <= source.c
- Compile arm : x264 <= internal.c
- Compile arm : x264 <= resize.c
- Compile arm : x264 <= cache.c
- Compile arm : x264 <= fix_vfr_pts.c
- Compile arm : x264 <= select_every.c
- Compile arm : x264 <= crop.c
- Compile arm : x264 <= depth.c
- Compile arm : x264 <= thread.c
- Compile arm : x264 <= getopt.c
- /home/lx/x264/jni/extras/getopt.c: In function '_getopt_internal':
- /home/lx/x264/jni/extras/getopt.c:577: warning: implicit declaration of function 'strcmp'
- /home/lx/x264/jni/extras/getopt.c:653: warning: implicit declaration of function 'strncmp'
- /home/lx/x264/jni/extras/getopt.c:656: warning: implicit declaration of function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:656: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:683: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:715: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:731: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:736: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:847: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:870: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:890: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:904: warning: incompatible implicit declaration of built-in function 'strlen'
- /home/lx/x264/jni/extras/getopt.c:908: warning: incompatible implicit declaration of built-in function 'strlen'
- Compile arm : x264 <= cpu-a.S
- Compile arm : x264 <= pixel-a.S
- Compile arm : x264 <= mc-a.S
- Compile arm : x264 <= dct-a.S
- Compile arm : x264 <= quant-a.S
- /home/lx/x264/jni/common/arm/quant-a.S: Assembler messages:
- /home/lx/x264/jni/common/arm/quant-a.S:222: Rd and Rm should be different in mul
- /home/lx/x264/jni/common/arm/quant-a.S:223: Rd and Rm should be different in mul
- /home/lx/x264/jni/common/arm/quant-a.S:227: Rd and Rm should be different in mul
- Compile arm : x264 <= deblock-a.S
- Compile arm : x264 <= predict-a.S
- SharedLibrary : libx264.so
- Install : libx264.so => libs/armeabi/libx264.so
大家可以一试,可能有的代码并未编进库中。