1. wget http: //ffmpeg.org/releases/ffmpeg-0.6.tar.bz2
wget http://ffmpeg.org/releases/ffmpeg-0.6.tar.bz2

二、NDK目录准备

因为NDK编译时只识别JNI目录下的Android.mk, 所以需要做个链接

  1. export NDKRROOT=/backup/software/android/android-ndk-r8b
  2. export PREBUILT=$NDKRROOT/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86
  3. export PLATFORM=$NDKRROOT/platforms/android-14/arch-arm
  4. export PATH=$PATH:$PREBUILT/bin
  5. export TMPDIR=/tmp
  6. ./configure --target-os=linux \
  7. --arch=arm \
  8. --enable-version3 \
  9. --enable-gpl \
  10. --enable-nonfree \
  11. --disable-stripping \
  12. --disable-ffmpeg \
  13. --disable-ffplay \
  14. --disable-ffserver \
  15. --disable-ffprobe \
  16. --disable-encoders \
  17. --disable-muxers \
  18. --disable-devices \
  19. --disable-protocols \
  20. --enable-protocol=file \
  21. --enable-avfilter \
  22. --disable-network \
  23. --disable-mpegaudio-hp \
  24. --disable-avdevice \
  25. --enable-cross-compile \
  26. --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
  27. --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
  28. --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
  29. --extra-cflags="-fPIC -DANDROID" \
  30. --disable-asm \
  31. --enable-neon \
  32. --enable-armv5te \
  33. --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.6.x-google/crtbegin.o $PREBUILT/lib/gcc/arm-linux-androideabi/4.6.x-google/crtend.o -lc -lm -ldl"
export NDKRROOT=/backup/software/android/android-ndk-r8b
export PREBUILT=$NDKRROOT/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86
export PLATFORM=$NDKRROOT/platforms/android-14/arch-arm
export PATH=$PATH:$PREBUILT/bin
export TMPDIR=/tmp
./configure --target-os=linux \
	--arch=arm \
	--enable-version3 \
	--enable-gpl \
	--enable-nonfree \
	--disable-stripping \
	--disable-ffmpeg \
	--disable-ffplay \
	--disable-ffserver \
	--disable-ffprobe \
	--disable-encoders \
	--disable-muxers \
	--disable-devices \
	--disable-protocols \
	--enable-protocol=file \
	--enable-avfilter \
	--disable-network \
	--disable-mpegaudio-hp \
	--disable-avdevice \
	--enable-cross-compile \
	--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
	--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
	--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
	--extra-cflags="-fPIC -DANDROID" \
	--disable-asm \
	--enable-neon \
	--enable-armv5te \
	--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.6.x-google/crtbegin.o $PREBUILT/lib/gcc/arm-linux-androideabi/4.6.x-google/crtend.o -lc -lm -ldl"
配置时出错的概率很高,需要注意一下问题: 

1、NDKRROOT 需要设定成你自己的NDK所在路径

2、根据NDK版本不同,PREBUILT、PLATFORM路径里面的名字可能不一样,请确认是你正在使用的版本

3、根据NDK版本不同,交叉编译的工具名称可能不同,请确认

        --cc=$PREBUILT/bin/arm-linux-androideabi-gcc 

--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- 
--nm=$PREBUILT/bin/arm-linux-androideabi-nm 

    是否设置正确

4、根据NDK版本不同,编译是需要的静态链接文件可能不一样,armelf_linux_eabi.x 可能名字不一样,找到ldscripts下对应的.x文件即可,crtbegin.o、crtend.o

      可能路径不一样,请确认是正确的

5、出错提示:

  a)找不到交叉编译工具

       类似Unknown C compiler /toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/ arm-linux-androideabi-gcc,请确认路径设置均正常

  b)出现不能创建执行文件

      类似 arm-linux-androideabi-gcc is unable to create an executable file,请确认export TMPDIR=/tmp 中设定的路径存在且可以访问

6、自定义配置

      如果需要对ffmpeg进行裁剪获取有其他需求,请自行配在config选项

      运行config.sh开始configure

  1. include $(LOCAL_PATH)/../config.mak  
  2.   
  3. OBJS :=  
  4. OBJS-yes :=  
  5. MMX-OBJS-yes :=  
  6. include $(LOCAL_PATH)/Makefile  
  7.   
  8. # collect objects  
  9. OBJS-$(HAVE_MMX) += $(MMX-OBJS-yes)  
  10. OBJS += $(OBJS-yes)  
  11.   
  12. FFNAME := lib$(NAME)  
  13. FFLIBS := $(foreach,NAME,$(FFLIBS),lib$(NAME))  
  14. FFCFLAGS  = -DHAVE_AV_CONFIG_H -Wno-sign-compare -Wno-switch -Wno-pointer-sign  
  15. FFCFLAGS += -DTARGET_CONFIG=\"config-$(TARGET_ARCH).h\"  
  16.   
  17. ALL_S_FILES := $(wildcard $(LOCAL_PATH)/$(TARGET_ARCH)/*.S)  
  18. ALL_S_FILES := $(addprefix $(TARGET_ARCH)/, $(notdir $(ALL_S_FILES)))  
  19.   
  20. ifneq ($(ALL_S_FILES),)  
  21. ALL_S_OBJS := $(patsubst %.S,%.o,$(ALL_S_FILES))  
  22. C_OBJS := $(filter-out $(ALL_S_OBJS),$(OBJS))  
  23. S_OBJS := $(filter $(ALL_S_OBJS),$(OBJS))  
  24. else  
  25. C_OBJS := $(OBJS)  
  26. S_OBJS :=  
  27. endif  
  28.   
  29. C_FILES := $(patsubst %.o,%.c,$(C_OBJS))  
  30. S_FILES := $(patsubst %.o,%.S,$(S_OBJS))  
  31.   
  32. FFFILES := $(sort $(S_FILES)) $(sort $(C_FILES))  
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))
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))

2、库文件通用makefile,  取名Android.mk,分别放置在libavcodec、ibavdevice、libavfilter、libavformat、libavutil、libpostproc、libswscale目录下
  1. LOCAL_PATH := $(call my-dir)  
  2. include $(CLEAR_VARS)  
  3. include $(LOCAL_PATH)/../av.mk  
  4. LOCAL_SRC_FILES := $(FFFILES)  
  5. LOCAL_C_INCLUDES :=     \  
  6.     $(LOCAL_PATH)       \  
  7.     $(LOCAL_PATH)/..  
  8. LOCAL_CFLAGS += $(FFCFLAGS)  
  9. LOCAL_STATIC_LIBRARIES := $(FFLIBS)  
  10. LOCAL_MODULE := $(FFNAME)  
  11. include $(BUILD_STATIC_LIBRARY)  
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)

同时对libavcodec、ibavdevice、libavfilter、libavformat、libavutil、libpostproc、libswscale目录下的Makefile文件,注释掉其中的
  1. include $(SUBDIR)../subdir.mak  
  2. include $(SUBDIR)../config.mak  
include $(SUBDIR)../subdir.mak
include $(SUBDIR)../config.mak

这两行不在一起,找找都注释掉

3、应用程序makefile, 取名为Android.mk,放置在ffmpeg-0.6目录下

  1. <SPAN style="COLOR: #333333">LOCAL_PATH := $(call my-dir)  
  2. include $(CLEAR_VARS)  
  3. LOCAL_STATIC_LIBRARIES := libavformat libavcodec libavutil libpostproc libswscale libavfilter libavdevice  
  4. LOCAL_MODULE := ffmpeg  
  5. LOCAL_C_INCLUDES :=     \  
  6.     $(LOCAL_PATH)       \  
  7.     $(LOCAL_PATH)/libavcodec \  
  8.     $(LOCAL_PATH)/libavdevice \  
  9.     $(LOCAL_PATH)/libavfilter \  
  10.     $(LOCAL_PATH)/libavformat \  
  11.     $(LOCAL_PATH)/libavutil \  
  12.     $(LOCAL_PATH)/libpostproc \  
  13.     $(LOCAL_PATH)/libswscale \  
  14.   
  15. LOCAL_SRC_FILES := \  
  16.     ffmpeg.c\  
  17.     cmdutils.c  
  18.   
  19. include $(BUILD_EXECUTABLE)  
  20. include $(call all-makefiles-under,$(LOCAL_PATH))</SPAN>  
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := libavformat libavcodec libavutil libpostproc libswscale libavfilter libavdevice
LOCAL_MODULE := ffmpeg
LOCAL_C_INCLUDES :=		\
	$(LOCAL_PATH)		\
	$(LOCAL_PATH)/libavcodec \
	$(LOCAL_PATH)/libavdevice \
	$(LOCAL_PATH)/libavfilter \
	$(LOCAL_PATH)/libavformat \
	$(LOCAL_PATH)/libavutil \
	$(LOCAL_PATH)/libpostproc \
	$(LOCAL_PATH)/libswscale \
LOCAL_SRC_FILES := \
	ffmpeg.c\
	cmdutils.c
include $(BUILD_EXECUTABLE)
include $(call all-makefiles-under,$(LOCAL_PATH))
如果只要做库文件的,参考文档1里面有介绍

五、编译及相关问题解决

 1、 运行NDK开始编译,命令如:

  1. /backup/software/android/android-ndk-r8b/ndk-build  
/backup/software/android/android-ndk-r8b/ndk-build

2、错误解决
  1. /works/workspace/android-console/jni/libavutil/libm.h:62:43: error: static declaration of 'lrint' follows non-static declaration  
  2. /works/workspace/android-console/jni/libavutil/libm.h:69:43: error: static declaration of 'lrintf' follows non-static declaration  
  3. /works/workspace/android-console/jni/libavutil/libm.h:76:41: error: static declaration of 'round' follows non-static declaration  
  4. /works/workspace/android-console/jni/libavutil/libm.h:83:40: error: static declaration of 'roundf' follows non-static declaration  
  5. /works/workspace/android-console/jni/libavutil/libm.h:90:40: error: static declaration of 'truncf' follows non-static declaration  
/works/workspace/android-console/jni/libavutil/libm.h:62:43: error: static declaration of 'lrint' follows non-static declaration
/works/workspace/android-console/jni/libavutil/libm.h:69:43: error: static declaration of 'lrintf' follows non-static declaration
/works/workspace/android-console/jni/libavutil/libm.h:76:41: error: static declaration of 'round' follows non-static declaration
/works/workspace/android-console/jni/libavutil/libm.h:83:40: error: static declaration of 'roundf' follows non-static declaration
/works/workspace/android-console/jni/libavutil/libm.h:90:40: error: static declaration of 'truncf' follows non-static declaration

删除libavutil/libm.h相关的static函数定义
  1. /works/workspace/android-console/jni/ffmpeg.c:3636:19: error: storage size of 'rusage' isn't known  
  2. /works/workspace/android-console/jni/ffmpeg.c:3638:15: error: 'RUSAGE_SELF' undeclared (first use in this function)  
/works/workspace/android-console/jni/ffmpeg.c:3636:19: error: storage size of 'rusage' isn't known
/works/workspace/android-console/jni/ffmpeg.c:3638:15: error: 'RUSAGE_SELF' undeclared (first use in this function)

将config.h 中
  1. /works/workspace/android-console/jni/cmdutils.c:41:21: fatal error: version.h: No such file or directory  
/works/workspace/android-console/jni/cmdutils.c:41:21: fatal error: version.h: No such file or directory

在ffmpeg-0.6目录下运行
  1. /works/workspace/android-console/jni/cmdutils.c:270:19: error: storage size of 'rl' isn't known  
  2. /works/workspace/android-console/jni/cmdutils.c:271:19: error: 'RLIMIT_CPU' undeclared (first use in this function)  
/works/workspace/android-console/jni/cmdutils.c:270:19: error: storage size of 'rl' isn't known
/works/workspace/android-console/jni/cmdutils.c:271:19: error: 'RLIMIT_CPU' undeclared (first use in this function)
将config.h 中
  1. In file included from /works/workspace/android-console/jni/libavformat/../libavcodec/mpegaudio.h:31:0,  
  2.                  from /works/workspace/android-console/jni/libavformat/asfdec.c:26:  
  3. /works/workspace/android-console/jni/libavformat/../libavcodec/dsputil.h:448:47: error: expected ';'',' or ')' before 'v1'  
  4. /works/workspace/android-console/jni/libavformat/asfdec.c: In function 'asf_read_header':  
  5. /works/workspace/android-console/jni/libavformat/asfdec.c:380:21: warning: 'AVPaletteControl' is deprecated (declared at /works/workspace/android-console/jni/libavformat/../libavcodec/avcodec.h:2808) [-Wdeprecated-declarations]  
  6. make: *** [/works/workspace/android-console/obj/local/armeabi/objs/avformat/asfdec.o] Error 1  
In file included from /works/workspace/android-console/jni/libavformat/../libavcodec/mpegaudio.h:31:0,
                 from /works/workspace/android-console/jni/libavformat/asfdec.c:26:
/works/workspace/android-console/jni/libavformat/../libavcodec/dsputil.h:448:47: error: expected ';', ',' or ')' before 'v1'
/works/workspace/android-console/jni/libavformat/asfdec.c: In function 'asf_read_header':
/works/workspace/android-console/jni/libavformat/asfdec.c:380:21: warning: 'AVPaletteControl' is deprecated (declared at /works/workspace/android-console/jni/libavformat/../libavcodec/avcodec.h:2808) [-Wdeprecated-declarations]
make: *** [/works/workspace/android-console/obj/local/armeabi/objs/avformat/asfdec.o] Error 1

将config.h 中

看着文档集成,居然一次次的报错,所以最后还是对比着官方的Demo来写一个Demo。 集成其实很简单,但是千万不要用模拟器测试,它不支持模拟器!!!!!!!最后用真机试了才发现自己已经成功了!!!! 新建一个项目 下载官方Demo包,终端是其中的superplayerkit库(这个是播放器的UI库,方便你我他,不需要自己写界面) 先把superplayerkit模块导入到新建的项目中 修改superplayerkit模块的build.gradle的原有配置(版本应该和新建的项目一致,
少不得交叉编译环境Cygwin的安装,版本我的是1.7.6,不要低于或等于1.5就行,因为我的NDK里面(docs\INSTALL.TXT)有说: Note thatrunning it under MSys or Cygwin 1.5 is not supported. 还说明要安装Cygwin时还要GNU Make 3.81(make –v)可以查看,所以为了安全起见在安装Cyg conany007: 你好,看到你当时发帖,询问 bash: ../../third_party/libvpx/copy_obj.sh: /bin/bash: bad interpreter: No such file or directory 问题,想问你这个问题最后解决了么?