这篇文章是转载自开源中国,作者huntking
今天找了很久,其他的博客有的是太旧了,要求NDK降级之r5,有的又出现问题,没有解决方案,良久才发现这篇文章按照步骤,终于生成了libffmpeg.so,转载过来,希望帮到更多的人
原文地址:http://my.oschina.net/wangqin/blog/80345
Android NDK r8b和FFmpeg 0.11.2移植
1、 准备Ubuntu 12.04虚拟机,推荐使用VirtualBox
2、 Ubuntu中安装相应的编译开发软件,如:build-essential之类的东西
3、 下载Android NDK r8b和Android SDK, all for linux,注意这个文档中使用的是Android NDK r8b和Android SDK 20
4、 下载FFmpeg,这个文档中使用的是:FFmpeg 0.11.2版本
5、 详细编译步骤:
5.1、创建工作目录:当前目录为:~/
(1)、
1 |
mkdir lpayer |
(2)、
1 |
mkdir jni |
5.2、进入目录jni,当前目录为:~/lplayer/jni,解压ffmpeg源码包
(1)、
1 |
tar zxvf filename |
(2)、解压后,重命名ffmpeg源码文件为:
1 |
mv ffmpeg_original ffmpeg |
(3)、得到目录为:~/lpayer/jni/ffmpeg
5.3、创建相应NDK配置文件:
(1)~/lplayer/jni/Android.mk
1 |
include $(all-subdir-makefiles) |
(2)~/lplayer/jni/ffmpeg/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
LOCAL_WHOLE_STATIC_LIBRARIES := libavformat libavcodec libavutil libpostproc libswscale |
06 |
07 |
LOCAL_MODULE := ffmpeg |
08 |
09 |
include $(BUILD_SHARED_LIBRARY) |
10 |
11 |
include $(call all-makefiles-under,$(LOCAL_PATH)) |
(3)~/lplayer/jni/ffmpeg/av.mk
01 |
# LOCAL_PATH is one of libavutil, libavcodec, libavformat, or libswscale |
02 |
03 |
#include $(LOCAL_PATH)/../config-$(TARGET_ARCH).mak |
04 |
05 |
include $(LOCAL_PATH)/../config.mak |
06 |
07 |
OBJS := |
08 |
09 |
OBJS- yes := |
10 |
11 |
MMX-OBJS- yes := |
12 |
13 |
include $(LOCAL_PATH)/Makefile |
14 |
15 |
# collect objects |
16 |
17 |
OBJS-$(HAVE_MMX) += $(MMX-OBJS- yes ) |
18 |
19 |
OBJS += $(OBJS- yes ) |
20 |
21 |
FFNAME := lib$(NAME) |
22 |
23 |
FFLIBS := $(foreach,NAME,$(FFLIBS),lib$(NAME)) |
24 |
25 |
FFCFLAGS = -DHAVE_AV_CONFIG_H -Wno-sign-compare -Wno-switch -Wno-pointer-sign |
26 |
27 |
FFCFLAGS += -DTARGET_CONFIG=\"config-$(TARGET_ARCH).h\" |
28 |
29 |
ALL_S_FILES := $(wildcard $(LOCAL_PATH)/$(TARGET_ARCH)/*.S) |
30 |
31 |
ALL_S_FILES := $(addprefix $(TARGET_ARCH)/, $(notdir $(ALL_S_FILES))) |
32 |
33 |
ifneq ($(ALL_S_FILES),) |
34 |
35 |
ALL_S_OBJS := $(patsubst %.S,%.o,$(ALL_S_FILES)) |
36 |
37 |
C_OBJS := $(filter-out $(ALL_S_OBJS),$(OBJS)) |
38 |
39 |
S_OBJS := $(filter $(ALL_S_OBJS),$(OBJS)) |
40 |
41 |
else |
42 |
43 |
C_OBJS := $(OBJS) |
44 |
45 |
S_OBJS := |
46 |
47 |
endif |
48 |
49 |
C_FILES := $(patsubst %.o,%.c,$(C_OBJS)) |
50 |
51 |
S_FILES := $(patsubst %.o,%.S,$(S_OBJS)) |
52 |
53 |
FFFILES := $( sort $(S_FILES)) $( sort $(C_FILES)) |
(4)~/lplayer/jni/ffmpeg/libavcodec/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
include $(LOCAL_PATH)/../av.mk |
06 |
07 |
LOCAL_SRC_FILES := $(FFFILES) |
08 |
09 |
LOCAL_C_INCLUDES := \ |
10 |
11 |
$(LOCAL_PATH) \ |
12 |
13 |
$(LOCAL_PATH)/.. |
14 |
15 |
LOCAL_CFLAGS += $(FFCFLAGS) |
16 |
17 |
LOCAL_LDLIBS := -lz |
18 |
19 |
LOCAL_STATIC_LIBRARIES := $(FFLIBS) |
20 |
21 |
LOCAL_MODULE := $(FFNAME) |
22 |
23 |
include $(BUILD_STATIC_LIBRARY) |
(5)~/lplayer/jni/ffmpeg/libavformat/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
include $(LOCAL_PATH)/../av.mk |
06 |
07 |
LOCAL_SRC_FILES := $(FFFILES) |
08 |
09 |
LOCAL_C_INCLUDES := \ |
10 |
11 |
$(LOCAL_PATH) \ |
12 |
13 |
$(LOCAL_PATH)/.. |
14 |
15 |
LOCAL_CFLAGS += $(FFCFLAGS) |
16 |
17 |
LOCAL_CFLAGS += -include "string.h" -Dipv6mr_interface=ipv6mr_ifindex |
18 |
19 |
LOCAL_LDLIBS := -lz |
20 |
21 |
LOCAL_STATIC_LIBRARIES := $(FFLIBS) |
22 |
23 |
LOCAL_MODULE := $(FFNAME) |
24 |
25 |
include $(BUILD_STATIC_LIBRARY) |
(6)~/lplayer/jni/ffmpeg/libavfilter/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
include $(LOCAL_PATH)/../av.mk |
06 |
07 |
LOCAL_SRC_FILES := $(FFFILES) |
08 |
09 |
LOCAL_C_INCLUDES := \ |
10 |
11 |
$(LOCAL_PATH) \ |
12 |
13 |
$(LOCAL_PATH)/.. |
14 |
15 |
LOCAL_CFLAGS += $(FFCFLAGS) |
16 |
17 |
LOCAL_STATIC_LIBRARIES := $(FFLIBS) |
18 |
19 |
LOCAL_MODULE := $(FFNAME) |
20 |
21 |
include $(BUILD_STATIC_LIBRARY) |
(7)~/lplayer/jni/ffmpeg/libavutil/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
include $(LOCAL_PATH)/../av.mk |
06 |
07 |
LOCAL_SRC_FILES := $(FFFILES) |
08 |
09 |
LOCAL_C_INCLUDES := \ |
10 |
11 |
$(LOCAL_PATH) \ |
12 |
13 |
$(LOCAL_PATH)/.. |
14 |
15 |
LOCAL_CFLAGS += $(FFCFLAGS) |
16 |
17 |
LOCAL_STATIC_LIBRARIES := $(FFLIBS) |
18 |
19 |
LOCAL_MODULE := $(FFNAME) |
20 |
21 |
include $(BUILD_STATIC_LIBRARY) |
(8)、~/lplayer/jni/ffmpeg/libpostproc/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
include $(LOCAL_PATH)/../av.mk |
06 |
07 |
LOCAL_SRC_FILES := $(FFFILES) |
08 |
09 |
LOCAL_C_INCLUDES := \ |
10 |
11 |
$(LOCAL_PATH) \ |
12 |
13 |
$(LOCAL_PATH)/.. |
14 |
15 |
LOCAL_CFLAGS += $(FFCFLAGS) |
16 |
17 |
LOCAL_STATIC_LIBRARIES := $(FFLIBS) |
18 |
19 |
LOCAL_MODULE := $(FFNAME) |
20 |
21 |
include $(BUILD_STATIC_LIBRARY) |
(9)、~/lplayer/jni/ffmpeg/libswscale/Android.mk
01 |
LOCAL_PATH := $(call my- dir ) |
02 |
03 |
include $(CLEAR_VARS) |
04 |
05 |
include $(LOCAL_PATH)/../av.mk |
06 |
07 |
LOCAL_SRC_FILES := $(FFFILES) |
08 |
09 |
LOCAL_C_INCLUDES := \ |
10 |
11 |
$(LOCAL_PATH) \ |
12 |
13 |
$(LOCAL_PATH)/.. |
14 |
15 |
LOCAL_CFLAGS += $(FFCFLAGS) |
16 |
17 |
LOCAL_STATIC_LIBRARIES := $(FFLIBS) |
18 |
19 |
LOCAL_MODULE := $(FFNAME) |
20 |
21 |
include $(BUILD_STATIC_LIBRARY) |
5.4、配置ffmpeg
(1)编写配置脚本:~/lpayer/jni/ffmpeg/config.sh
注意其中的NDK路径,请修改成你系统中对应的安装路径
01 |
#!/bin/bash |
02 |
03 |
|
04 |
05 |
PREBUILT=/home/long/androiddev/android-ndk-r8b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 |
06 |
07 |
PLATFORM=/home/long/androiddev/android-ndk-r8b/platforms/android-9/arch-arm |
08 |
09 |
|
10 |
11 |
./configure --target-os=linux \ |
12 |
13 |
--arch=arm \ |
14 |
15 |
-- enable -version3 \ |
16 |
17 |
-- enable -gpl \ |
18 |
19 |
-- enable -nonfree \ |
20 |
21 |
--disable-stripping \ |
22 |
23 |
--disable-ffmpeg \ |
24 |
25 |
--disable-ffplay \ |
26 |
27 |
--disable-ffserver \ |
28 |
29 |
--disable-ffprobe \ |
30 |
31 |
--disable-encoders \ |
32 |
33 |
--disable-muxers \ |
34 |
35 |
--disable-devices \ |
36 |
37 |
--disable-protocols \ |
38 |
39 |
-- enable -protocol= |