感谢http://blog.csdn.net/cbzhaojay/article/details/8524915?reload的作者,FFmpeg终于编译成功。
1:下载android-ndk-r8e,在终端下命令jar -vxfj xxxx解压。在root下进入/etc/bash.bashc,添加以下代码配置ndk路径,其中NDK路径需要填写正确的路径
NDK=/home/zhutj/android-ndk-r8e/
export PATH="$PATH:$NDK"
2:以/home/zhutj/androidProject/ffmpeg_project/jni形式创建一个工程,其中androidProject是我取的一个存放所有工程的目录,ffmpeg_project为我将要编译的工程名,然后把
FFmpeg-0.7.15解压到jni下,解压后把FFmpeg-0.7.15重命名为ffmpeg
3:以下开始编辑Android.mk文件以及ffmpeg的配置文件config.sh
a:在jni下编辑Android.mk文件,内容如下:
include $(all-subdir-makefiles)
b:在jni/ffmpeg下编辑Android.mk文件,内容如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_WHOLE_STATIC_LIBRARIES := libavformat libavcodec libavutil libpostproc libswscale
LOCAL_MODULE := ffmpeg
include $(BUILD_SHARED_LIBRARY)
include $(call all-makefiles-under,$(LOCAL_PATH))
c:在jni/ffmpeg下编辑av.mk文件,内容如下:
# LOCAL_PATH is one of libavutil,libavcodec,libavformat,or libswscale
#include $(LOCAL_PATH)/../config-$(TARGET_ARCH).mak
include $(LOCAL_PATH)/../config.mak
OBJS :=
OBJS-yes :=
MMX-OBJS-yes :=
include $(LOCAL_PATH)/Makefile
# collect objects
OBJS-$(HAVE_MMX) += $(MMX-OBJS-yes)
OBJS += $(OBJS-yes)
FFNAME := lib$(NAME)
FFLIBS := $(foreach,NAME,$(FFLIBS),lib$(NAME))
FFCFLAGS = -DHAVE_AV_CONFIG_H -Wno-sign-compare -Wno-switch -Wno-pointer-sign
FFCFLAGS += -DTARGET_CONFIG=\"config-$(TARGET_ARCH).h\"
ALL_S_FILES := $(wildcard $(LOCAL_PATH)/$(TARGET_ARCH)/*.S)
ALL_S_FILES := $(addprefix $(TARGET_ARCH)/, $(notdir $(ALL_S_FILES)))
ifneq ($(ALL_S_FILES),)
ALL_S_OBJS := $(patsubst %.S,%.o,$(ALL_S_FILES))
C_OBJS := $(filter-out $(ALL_S_OBJS),$(OBJS))
S_OBJS := $(filter $(ALL_S_OBJS),$(OBJS))
else
C_OBJS := $(OBJS)
S_OBJS :=
endif
C_FILES := $(patsubst %.o,%.c,$(C_OBJS))
S_FILES := $(patsubst %.o,%.S,$(S_OBJS))
FFFILES := $(sort $(S_FILES)) $(sort $(C_FILES))
d:在jni/ffmpeg/libavformat编辑Android,mk,内容如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/../av.mk
LOCAL_SRC_FILES := $(FFFILES)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/..
LOCAL_CFLAGS += $(FFCFLAGS)
LOCAL_CFLAGS += -include "string.h" -Dipv6mr_interface=ipv6mr_ifindex
LOCAL_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := $(FFLIBS)
LOCAL_MODULE := $(FFNAME)
include $(BUILD_STATIC_LIBRARY)
e:在jni/ffmpeg/libavcodec编辑Android,mk,内容如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/../av.mk
LOCAL_SRC_FILES := $(FFFILES)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/..
LOCAL_CFLAGS += $(FFCFLAGS)
LOCAL_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := $(FFLIBS)
LOCAL_MODULE := $(FFNAME)
include $(BUILD_STATIC_LIBRARY)
f:在jni/ffmpeg/libavutil libpostproc libswscale编辑Android,mk内容如下:(高版本可能有libswresample目录)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/../av.mk
LOCAL_SRC_FILES := $(FFFILES)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/..
LOCAL_CFLAGS += $(FFCFLAGS)
LOCAL_STATIC_LIBRARIES := $(FFLIBS)
LOCAL_MODULE := $(FFNAME)
include $(BUILD_STATIC_LIBRARY)
g:在jni/ffmpeg下编辑config.sh,内容如下:
#!/bin/bash
PREBUILT=/home/zhutj/android-ndk-r8e/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
PLATFORM=/home/zhutj/android-ndk-r8e/platforms/android-9/arch-arm
./configure --target-os=linux \
--arch=arm \
--enable-version3 \
--enable-gpl \
--enable-nonfree \
--enable-shared \
--disable-stripping \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-ffprobe \
--disable-symver \
--enable-encoders \
--enable-muxers \
--disable-devices \
--disable-protocols \
--enable-protocol=file \
--enable-avfilter \
--disable-network \
--disable-avdevice \
--disable-asm \
--enable-cross-compile \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--strip=$PREBUILT/bin/arm-linux-androideabi-strip \
--extra-cflags="-fPIC -DANDROID" \
--extra-ldflags="-Wl,-T,$PREBUILT/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtbegin.o $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtend.o -lc -lm -ldl" \
sed -i 's/HAVE_LRINT 0/HAVE_LRINT 1/g' config.h
sed -i 's/HAVE_LRINTF 0/HAVE_LRINTF 1/g' config.h
sed -i 's/HAVE_ROUND 0/HAVE_ROUND 1/g' config.h
sed -i 's/HAVE_ROUNDF 0/HAVE_ROUNDF 1/g' config.h
sed -i 's/HAVE_TRUNC 0/HAVE_TRUNC 1/g' config.h
sed -i 's/HAVE_TRUNCF 0/HAVE_TRUNCF 1/g' config.h
sed -i 's/HAVE_CBRT 0/HAVE_CBRT 1/g' config.h
sed -i 's/HAVE_CBRTF 0/HAVE_CBRTF 1/g' config.h
sed -i 's/HAVE_ISINF 0/HAVE_ISINF 1/g' config.h
sed -i 's/HAVE_ISNAN 0/HAVE_ISNAN 1/g' config.h
sed -i 's/HAVE_SINF 0/HAVE_SINF 1/g' config.h
sed -i 's/HAVE_RINT 0/HAVE_RINT 1/g' config.h
上面PREBUILT PLATFORM的路径自己根据NDK的路径自己更改,并增加可执行权限,命令如下:
chmod +x config.sh
4:终端下进入/jni/ffmpeg下执行
./config.sh
注意: 1、出现command not found错误,则删除config.sh中每行之间的空格.
2、出现yasm not found错误,使用apt-get stall yasm下载安装yasm或者在config.sh中写上--disable-yasm(yasm是汇编中的,ffmpeg为了提高效率而使用)
执行成功后会生成config.h和config.mk文件
5:修改
a、删除 libavformat libavcodec libavutil libpostproc libswscale 目录下Makefile下的
include $(SUBDIR)../config.mak
include $(SUBDIR)../subdir.mak
b、修改jni/ffmpeg/config.h下的
6:进入ffmpeg_project目录下编译:
ndk-build
注意:1、出现miising sepatator Stop错误,有可能是Android.mk文件中的空格引起(编码格式引起的),删掉空格( \ 后面的空格 )
2、multiple definition ‘ff_inverse'(重复定义函数),在编译FFmpeg-0.7.15时是因为libavcode中的inverse.c引用了libavutil中的inverse.h注释掉libavcode中inverse.c引用代码即可