2015년 1월 26일 월요일

android ffmpeg build

1. make android toolchain
$ /cygdrive/c/android-ndk-r10d/build/tools/make-standalone-toolchain.sh --platform=android-18 --install-dir=c:/my-android-toolchain-18 --arch=arm --system=windows-x86_64

2. ffmpeg configure
./configure --target-os=linux --arch=arm --enable-cross-compile --cc=/cygdrive/c/my-android-toolchain-18/bin/arm-linux-androideabi-gcc --cross-prefix=/cygdrive/c/my-android-toolchain-18/bin/arm-linux-androideabi- --extra-cflags="-marm -march=armv7-a -mfloat-abi=softfp -mfpu=neon" --extra-ldflags="-Wl,--fix-cortex-a8" --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-network --disable-devices --disable-filters --prefix=../ffmpeg-build

make
make install

// make 후 아래 에러 발생시 config.h 수정
$ make
CC      libavfilter/allfilters.o
In file included from ./libavutil/common.h:83:0,
                 from ./libavutil/avutil.h:289,
                 from libavfilter/avfilter.h:39,
                 from libavfilter/allfilters.c:22:
./config.h:9:18: warning: missing terminating " character [enabled by default]
 (GCC)"e CC_IDENT "gcc 4.8
                  ^
./config.h:10:7: warning: missing terminating " character [enabled by default]
 #define av_restrict restrict
       ^
./config.h:10:2: error: missing terminating " character
 #define av_restrict restrict
  ^
In file included from ./libavutil/intmath.h:30:0,
                 from ./libavutil/common.h:84,
                 from ./libavutil/avutil.h:289,
                 from libavfilter/avfilter.h:39,
                 from libavfilter/allfilters.c:22:
./libavutil/arm/intmath.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'static'
 static av_always_inline av_const unsigned av_clip_uint8_arm(int a)
 ^
common.mak:49: recipe for target 'libavfilter/allfilters.o' failed
make: *** [libavfilter/allfilters.o] Error 1

config.h 에서
#define CC_IDENT "gcc 4.8
 (GCC)"

#define CC_IDENT "gcc 4.8 (GCC)"
로 수정

3. modify Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES := $(LOCAL_PATH)/libs/libavcodec.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avformat
LOCAL_SRC_FILES := $(LOCAL_PATH)/libs/libavformat.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES := $(LOCAL_PATH)/libs/libswscale.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := $(LOCAL_PATH)/libs/libavutil.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swresample
LOCAL_SRC_FILES := $(LOCAL_PATH)/libs/libswresample.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := DXMediaPlayer
LOCAL_SRC_FILES := com_example_dxmediaplayertest_DXMediaPlayer.cpp \
  DXMediaPlayerCtrl.cpp

LOCAL_LDLIBS := -llog -lz -ljnigraphics -landroid

LOCAL_STATIC_LIBRARIES := avformat avcodec avutil swscale swresample    => order must be kept !!!

LOCAL_CFLAGS := -DANDROID -D__STDC_CONSTANT_MACROS
LOCAL_CPPFLAGS := -DANDROID -D__STDC_CONSTANT_MACROS

include $(BUILD_SHARED_LIBRARY)