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
- 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))
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目录下
- 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)
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文件,注释掉其中的
- include $(SUBDIR)../subdir.mak
- include $(SUBDIR)../config.mak
include $(SUBDIR)../subdir.mak
include $(SUBDIR)../config.mak
这两行不在一起,找找都注释掉
3、应用程序makefile, 取名为Android.mk,放置在ffmpeg-0.6目录下
- <SPAN style="COLOR: #333333">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))</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开始编译,命令如:
- /backup/software/android/android-ndk-r8b/ndk-build
/backup/software/android/android-ndk-r8b/ndk-build
2、错误解决
- /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
/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函数定义
- /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)
/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 中
- /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目录下运行
- /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)
/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 中
- 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
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: