基本都是照着https://github.com/yixia/FFmpeg-Vitamio写的。但是有些地方不一样了。
因为librtmp需要openssl的支持,所以使用ijk的init-android-openssl.sh和Android/contrib/compile-openssl.sh就可以编译成功,
在build/openssl-armv7a/output/lib下会生成两个.a静态库文件libcrypto.a和libssl.a。
接下来,编译librtmp
在android/contrib目录下
git clone git://git.ffmpeg.org/rtmpdump
下载librtmp。
在文件下建4个文件
Android.mk
AndroidManifest.xml
jni/Application.mk
librtmp/Android.mk
Android.mk中
--------------------------------------------------------------------
- <strong>LOCAL_PATH := $(call my-dir)
- subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
- librtmp \
- ))
- ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
- openssl=openssl-armv7a
- else ifeq ($(TARGET_ARCH_ABI),x86)
- openssl=openssl-x86
- else ifeq ($(TARGET_ARCH_ABI),armeabi)
- openssl=openssl-armv5
- endif
- SSL :=$(LOCAL_PATH)/../build/$(openssl)/output
- ifndef SSL
- $(error "You must define SSL before starting")
- endif
- include $(subdirs)</strong>
AndroidManifest.xml随便拷贝一个
jni/Application.mk中,支持3中平台
--------------------------------------------------------------------
- NDK_TOOLCHAIN_VERSION := 4.8
- APP_ABI := armeabi armeabi-v7a x86
- APP_PROJECT_PATH := $(shell pwd)
- APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
--------------------------------------------------------------------
librtmp/Android.mk中
--------------------------------------------------------------------
- <strong>LOCAL_PATH:= $(call my-dir)
- include $(CLEAR_VARS)
- LOCAL_C_INCLUDES += $(NDK_PROJECT_PATH)/librtmp \
- $(SSL)/include
- LOCAL_SRC_FILES:= \
- amf.c \
- hashswf.c \
- log.c \
- parseurl.c \
- rtmp.c
- LOCAL_CFLAGS += -I$(SSL)/include -DUSE_OPENSSL
- LOCAL_LDLIBS += -L$(SSL)/lib
- LOCAL_LDLIBS += -lssl -lcrypto -lz
- LOCAL_MODULE := librtmp
- include $(BUILD_SHARED_LIBRARY)</strong>
--------------------------------------------------------------------
执行ndk-build命令,进行编译。然后就是要编译ffmpeg了。
修改tools下的do-compile-ffmpeg.sh文件
定义RTMPDUMP=$FF_BUILD_ROOT/librtmp
注意把FF_BUILD_ROOT=`pwd`放到他前面
在if [ "$FF_ARCH" = "armv7a" ]; then,elif [ "$FF_ARCH" = "armv5" ]; then,elif [ "$FF_ARCH" = "x86" ]; then里
修改FF_EXTRA_LDFLAGS="$FF_EXTRA_LDFLAGS -Wl,--fix-cortex-a8 -L$RTMPDUMP/libs/armeabi-v7a"
增加
- RTMP_OBJS=`find $RTMPDUMP/obj/local/armeabi-v7a/objs/rtmp -type f -name "*.o"`
- FF_ASM_OBJ_DIR="libavutil/arm/*.o libavcodec/arm/*.o libswresample/arm/*.o $RTMP_OBJS"
- <pre name="code" class="plain">FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-protocol=librtmp*"
- FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-librtmp"
在FF_CFLAGS="-O3 -Wall -pipe \里增加
-I$RTMPDUMP -lrtmp"
FF_CFG_FLAGS增加
修改ffmpeg-*/configure
- enabled librtmp && require librtmp librtmp/rtmp.h RTMP_Init -L$RTMPDUMP/libs/armeabi-v7a -lrtmp || die "ERROR: librtmp not found"; }
然后使用compile-ffmpeg.sh就可以编译了。