在android下面完成 ffmpeg最新版的编译
落鹤生 发布于 2012-06-02 22:56 点击:813次 | 原文 | 来自:百度博客
--lihn1987(转载请注明作者)
其实网络上关于android编译ffmpeg的文章已经相当多了,我也尝试过很多,但是照着他们的做咋老是编不出东西呢?不是config出错就是make出错。也许是我的模仿能力太差了。。。。
于是我浏览了下网上各位达人的方法,发现基本大同小异,都是参考的一个开源项目
由于我移植搞不出来,所以无奈也去参考这个项目,在此,我对这个项目的负责人表示由衷的感谢,thk U!!!!
各位博友如果按照我的说法搞不定的话,也可以去参考下这个项目最初的做法哈。如果实在搞不定,可以加我的百度hi),我可以提供修改好的代码,直接ndk-build即可,毕竟这个也不是我第一个钻研出来的,和大家分享才是硬道理。
以下是正文
ffmpeg目录下增加Android.mk 和av.mk config.sh三个文件
>>>>>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))
>>>>>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))
>>>>>>>>>config.sh
#!/bin/sh
PREBUILT=/root/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86
PLATFORM=/root/android-ndk-r5/platforms/android-4/arch-arm
./configure --target-os=linux \
--arch=armv41 \
--enable-cross-compile \
--cc=$PREBUILT/bin/arm-eabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-eabi- \
--nm=$PREBUILT/bin/arm-eabi-nm \
--extra-cflags="-fPIC -DANDROID" \
--enable-static \
--disable-shared \
--disable-asm \
--disable-yasm \
--prefix=/home/ffmpeg-android-bin \
--extra-ldflags="-Wl,-T,$PREBUILT/arm-eabi/lib/ldscripts/armelf.x -Wl,\
-rpath-link=$PLATFORM/usr/lib \
-L$PLATFORM/usr/lib -nostdlib \
$PREBUILT/lib/gcc/arm-eabi/4.4.0/crtbegin.o \
$PREBUILT/lib/gcc/arm-eabi/4.4.0/crtend.o -lc -lm -ldl"
在libavcodec中添加Andorid.mk文件
>>>>>>>>>>>>>>>>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)
在libavfilter中添加Android.mk文件
>>>>>>>>>>>>>>>>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)
在libavformat中添加Andorid.mk文件
>>>>>>>>>>>>>>>>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)
在libavutil中添加Android.mk文件
>>>>>>>>>>>>>>>>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)
在libpostproc中添加Android.mk文件
>>>>>>>>>>>>>>>>>>>>>>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)
在libswscale中添加Android.mk文件
>>>>>>>>>>>>>>>>>>>>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)
在libavcodec,libavfilter,libavformat,libavutil,libpostproc,libswscale中找到
这行
include $(SUBDIR)../config.mak
和这行
include $(SUBDIR)../subdir.mak
然后把这两行全部删除
接下来就简单了,
进入ffmpeg目录,运行./config.sh脚本
会自动生成config.h和config.mak,如果生成过程出现错误,那么大多就是编译器配置目录的问题了。
然后修改两个文件,把config.h中的
#define restrict restrict
改为
#define restrict
把ffmpeg/libavutil/libm.h中所有static的函数删除。
然后
新建一个ffmpeg_android,着这个文件夹里在建立个jni 然后把我们的ffmpeg放到jni里,同时在jni里在创建一个Android.mk,内容如下
>>>>>>>>>>>>>>>>>>>>>Android.mk
include $(all-subdir-makefiles)
然后目录调到ffmpeg_android运行
/root/android-ndk-r5/ndk-build即可
由于我用的是最新的代码(svn上更新下来的)中间可能会出一些编译错误,比如对for(int i; i<x;i++)这种格式的不支持啊,就直接把int i提到for外面即可,别的就没啥问题了。