ffmpeg을 사용할 일이 있어 ndk로 빌드환경 구성을 알아보았다. ffmpeg을 언젠가 만져보긴 했는데,
아마도 다이렉트쇼 필터 만들때였던것 같은데.. 이미 까막눈이 되어 있어서, 구글링~
우선 참조할 만한 블로그 들.
1. 소스코드 다운로드
ffmpeg : http://www.ffmpeg.org/download.html
$ sudo apt-get install git-core
$ git clone git://git.videolan.org/ffmpeg
2. 참조 사이트 : static 빌드로 라이브러리를 생성을 위한 작업설명
* 음.. 리눅스용 ndk r5c 에는 툴체인 경로가 포스트의 내용과 차이가 있음.
http://androidcore.com/android-programming-tutorials/641-how-to-compile-ffmpeg-on-android.html
Create a new project, make jni folder, then download and extract ffmpeg, rename ffmpeg folder to ffmpeg.
Make a new config.sh in ffmpeg, notice a bout PREBUILT path and PLATFORM:
#!/bin/bash
PREBUILT=/home/abitno/Android/android-ndk-r4/build/prebuilt/linux-x86/arm-eabi-4.4.0
PLATFORM=/home/abitno/Android/android-ndk-r4/build/platforms/android-8/arch-arm
./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-eabi-gcc
\
--cross-prefix=$PREBUILT/bin/arm-eabi-
\
--nm=$PREBUILT/bin/arm-eabi-nm
\
--extra-cflags="-fPIC
-DANDROID"
\
--disable-asm
\
--enable-neon
\
--enable-armv5te \
--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"
Then change mode config.sh and run
chmod +x
config.sh
./config.sh
When config is completed, open config.h, find:
#define restrict restrict
replace by
#define restrict
Open libavutil/libm.h, remove static keyword in all function declaration.
Open Makefile in libavcodec, libavfilter, libavformat, libavutil, libpostproc and libswscale and remove two lines:
include
$(SUBDIR)../subdir.mak
include $(SUBDIR)../config.mak
add new av.mk file in ffmpeg folder:
# 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))
Create Android.mk in jni folder:
include $(all-subdir-makefiles)
Create Android.mk in ffmpeg folder:
LOCAL_PATH := $(call
my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := libavformat libavcodec libavutil libpostproc
libswscale
LOCAL_MODULE := ffmpeg
include $(BUILD_SHARED_LIBRARY)
include $(call all-makefiles-under,$(LOCAL_PATH))
libavformat/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)
libavcodec/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, libavutil, libpostproc and libswscale / 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)
3. 참조사이트 2 : http://www.cnblogs.com/scottwong/archive/2010/12/17/1909455.html
이곳은 shared 라이브러리.
ffmpeg 의 confgure 스크립트를 실행시키면 config.h 가 생성되는데, 이를 사용해 빌드할 소스를 적용하는 방법을 사용하고 있다.
4. 기타 참조할만한 사이트
http://bambuser.com/opensource : ffmpeg 소스코드 제공
음.. bambuser.com의 소스는 ndk 빌드가 아닌 ndk 툴체인만 이용해서 빌드.
라이브러리단의 변경 없이 배포하고, shared 인 경우는 이 방법이 가장 간편.
대강 설치용 스크립트를 살펴보면 아래와 같다.
환경변수 설정
NDK=~/android-ndk-r5c
SYSROOT=$NDK/platforms/android-3/arch-arm
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
DEST=../out/ffmpeg/armeabi
export PATH=$TOOLCHAIN/bin:$PATH
빌드 옵션 설정
--target-os=linux \
--arch=arm \
--cross-prefix=arm-linux-androideabi- \
--sysroot= $SYSROOT \
--enable-shared \
--disable-symver \
--enable-small \
--optimization-flags=-O2
--disable-everything
--prefix=$DEST
플래그
default
--extra-cflags=
--extra-ldflags=
armv7a
--extra-cflags="-march=armv7-a -mfloat-abi=softfp"
--extra-ldflags=
neon
--extra-cflags="-march=armv7-a -mfloat-abi=softfp -mfpu=neon"
--extra-ldflags="-Wl,--fix-cortex-a8"
FFMPEG configure
cd ffmpeg
./configure 빌드옵션 --extra-cflags= --extra-ldflags=
make clean
make -j4
make install
'프로그래밍 > Android' 카테고리의 다른 글
터치 이벤트 처리순서 (0) | 2011.09.01 |
---|---|
천천히 로딩되는 리스트 아이템 (0) | 2011.08.22 |
이미지 클리핑 기초 (0) | 2011.08.18 |
ffmpeg 빌드 #3 (0) | 2011.07.07 |
ffmpeg 빌드 #2 ffmpeg 옵션별 빌드 (0) | 2011.07.06 |
Drag&drop listview (0) | 2010.10.06 |
뷰 전환시 3차원 에니메이션 적용하기 (0) | 2010.09.17 |
안드로이드 위젯 배경 이미지, 나인패치 (0) | 2010.08.17 |
옵션메뉴 배경 변경 (0) | 2010.08.10 |
갤러리, 커버플로우 구현 (0) | 2010.07.27 |