1、编写 mk 文件
1.1 在/home/yinjk/FFMPEG/ffmpegDir/jni目录中创建一个 Android.mk 文件,内容如下
include $(all-subdir-makefiles)
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_WHOLE_STATIC_LIBRARIES := libavutil libavcodec libpostproc libswscale libavformat libswresample libavfilter LOCAL_ARM_MODE := arm LOCAL_MODULE := ffmpeg include $(BUILD_SHARED_LIBRARY) include $(call all-makefiles-under,$(LOCAL_PATH))1.3、在 /home/yinjk/FFMPEG/ffmpegDir/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))1.4、在 /home/yinjk/FFMPEG/ffmpegDir/jni/ffmpeg/libavcodec 目录中创建一个 Android.mk 文件,内容如下
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include $(LOCAL_PATH)/../av.mk LOCAL_ARM_MODE := arm 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)1.5、在 /home/yinjk/FFMPEG/ffmpegDir/jni/ffmpeg/libavformat 目录中创建一个 Android.mk 文件,内容如下
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) include $(LOCAL_PATH)/../av.mk LOCAL_ARM_MODE := arm 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_SHARED_LIBRARIES := $(FFLIBS) LOCAL_MODULE:= $(FFNAME) include $(BUILD_STATIC_LIBRARY)1.6、在 libavfilter、libavutil、libpostproc、libswscale和libswresample 目录中各创建一个 Android.mk 文件,内容如下
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include $(LOCAL_PATH)/../av.mk LOCAL_ARM_MODE := arm 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)2、修改 libm.h 文件和 Makefile 文件
2.1、编辑/home/yinjk/FFMPEG/ffmpegDir/jni/ffmpeg/libavutil 目录中的 libm.h 文件,删除所有static 方法
2.2、编辑 libavcodec、libavfilter、libavformat、libavutil、libpostproc 、libswresample 和 libswscale 目录中的 Makefile 文件,删除
include $(SUBDIR)../subdir.mak 和 include $(SUBDIR)../config.mak 两行3、生成 config.h 文件
3.1、在/home/yinjk/FFMPEG/ffmpegDir/jni/ffmpeg目录中创建一个 config.sh 文件,使用 Android NDK r7b 编译时内容如下:
#!/bin/bash PREBUILT=/home/yinjk/FFMPEG/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 PLATFORM=/home/yinjk/FFMPEG/android-ndk-r7b/platforms/android-14/arch-arm ./configure --target-os=linux \ --arch=arm \ --enable-version3 \ --enable-gpl \ --enable-nonfree \ --enable-small \ --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-avdevice \ --enable-cross-compile \ --cc=$PREBUILT/bin/arm-linux-androideabi-gcc-4.4.3 \ --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.4.3/crtbegin.o $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtend.o -lc -lm -ldl"3.2、打开终端,进入 /home/yinjk/FFMPEG/ffmpegDir/jni/ffmpeg目录,运行下面的命令
chmod +x config.sh ./config.sh
3.3、编辑/home/yinjk/FFMPEG/ffmpegDir/jni/ffmpeg目录中的 config.h 文件,将
#define restrict restrict
#define restrict
执行命令 /home/yinjk/FFMPEG/android-ndk-r7b/ndk-build NDK_PROJECT_PATH=/home/yinjk/FFMPEG/ffmpegDir
编译完成后显示如下信息:
StaticLibrary : libavfilter.a SharedLibrary : libffmpeg.so Install : libffmpeg.so => libs/armeabi/libffmpeg.so