经过多次折腾
在Windows 8下 + cywin 无法正常编译。
最后无奈换成Ubuntu12.1, 终于编译成功 ffmpeg 1.1.4。 先上图
经测试:ffmpeg 1.2 由于种种原因无法编译成功。
关于如何用虚拟机安装 Ubuntu12.1 请参考我另外一篇博文
http://hiandroidstudio.blog.51cto.com/5902332/1167953
关于VMware下Ubuntu下如何连接上网,请查看
http://hiandroidstudio.blog.51cto.com/blog/5902332/1166977
关于如何在Ubuntu下如何安装Android NDK ,请查看
http://hiandroidstudio.blog.51cto.com/blog/5902332/1167180
关于如何在Ubuntu下安装Android SDK,请查看
http://hiandroidstudio.blog.51cto.com/blog/5902332/1167319
关于如何在Ubuntu下安装 JDK ,请查看
http://hiandroidstudio.blog.51cto.com/blog/5902332/1167272
完成了上面的配置以后,我们就可以开始安装ffmpeg1.1.4了。
1、下载ffmpeg1.1.4
下载地址:https://ffmpeg.org/releases/ffmpeg-1.1.4.tar.bz2
2、解压到ndk目录中
使用 tar jxvf ffmpeg-1.1.4.tar.bz2 命令解压到NDK 中的samples 目录下。
我的目录是:/home/ryan/android/android-ndk-r8b/samples/ffmpeg-1.1/jni/ffmpeg
3、添加Android.mk,av.mk,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 libswresample
- 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 libswresample
下添加 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_STATIC_LIBRARIES := $(FFLIBS)
- LOCAL_MODULE := $(FFNAME)
- include $(BUILD_STATIC_LIBRARY)
g. 在jni/ffmpeg 下添加可执行文件config.sh, 内容如下:
- #!/bin/bash
- PREBUILT=/home/ryan/android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
- PLATFORM=/home/ryan/android/android-ndk-r8b/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的路径自己更改。
4、修改执行权限,并执行 ./config.sh 生成文件
- chmod +x config.sh
- ./config.sh
如果配置正确的话显示出来的最后两行是这样的:
License: nonfree and unredistributable
Creating config.mak and config.h...
执行完成会在ffmpeg目录下生成 config.h 和 config.mak
5、修改ffmpeg下的某些文件
a、删除 libavformat libavcodec libavutil libpostproc libswscale libswresample 目录下Makefile下的
include $(SUBDIR)../config.mak
b、删除libavcodec libavutil libswresample目录下Makefile下的
log2_tab.o \
或者
OBJS-$(CONFIG_SHARED) += log2_tab.o
c、修改jni/ffmpeg/config.h下的
#define avrestrict restrict为#define restrict
d、注释掉/jni/ffmpeg/libavutil 目录中的 libm.h下的所有静态(static)方法
e、把 ffmpeg/libavutil/time.h更名为avtime.h,
同时修改下面文件中的引用libavutil/time.h为libavutil/avtime.h
ffmpeg/libavformat/avformat.h:211
ffmpeg/libavformat/avio.c:25
ffmpeg/libavformat/hls.c:33
ffmpeg/libavformat/mux.c:39:30
ffmpeg/libavformat/utils.c:40
ffmpeg/libavutil/time.c:36
6、返回到 jni/ffmpeg 目录 执行 ndk-build 编译代码。
7、大约20多分钟后,就可以编译成功了。