本文将从零开始详细讲述怎么在ijkplayer中添加使用librtmp库.
编译环境:
ubuntu 16.10
1.安装必要的软件
sudo apt-get install git make yasm
2.下载并编译ijkplayer,确保源码无错
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.7.5
./init-android.sh
cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
cd ..
./compile-ijk.sh all
3.添加openssl支持
cd ../..
./init-android-openssl.sh
./android/contrib/compile-openssl.sh all
编译成功后,在ijkplayer-Android/android/contrib/build/目录下会有对应cpu架构的ssl静态库
4.编译librtmp生成对应静态库
cd android/contrib
git clone git://git.ffmpeg.org/rtmpdump
cd rtmpdump
进入rtmpdump目录内,新建4个文件:
Android.mk
AndroidManifest.xml
jni/Application.mk
librtmp/Android.mk
其中Android.mk:
LOCAL_PATH := $(call my-dir)
subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
librtmp \
))
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
openssl=openssl-armv7a
endif
ifeq ($(TARGET_ARCH_ABI),armeabi)
openssl=openssl-armv5
endif
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
openssl=openssl-arm64
endif
ifeq ($(TARGET_ARCH_ABI),x86)
openssl=openssl-x86
endif
ifeq ($(TARGET_ARCH_ABI),x86_64)
openssl=openssl-x86_64
endif
SSL :=$(LOCAL_PATH)/../build/$(openssl)/output
ifndef SSL
$(error "You must define SSL before starting")
endif
include $(subdirs)
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="0.1" >
<uses-sdk android:minSdkVersion="9" />
</manifest>
jni/Application.mk:
NDK_TOOLCHAIN_VERSION := 4.9
APP_ABI := armeabi-v7a armeabi arm64-v8a x86 x86_64
APP_PROJECT_PATH := $(shell pwd)
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
librtmp/Android.mk:
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_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_MODULE := librtmp
#include $(BUILD_SHARED_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
在rtmp目录下执行编译:
ndk-build
成功后会看到目录下多了obj这个文件夹,里面有对应版本的rtmp静态库
5.将librtmp编译到ffmpeg里
A.修改/android/contrib/tools/do-compile-ffmpeg.sh文件
找到
FF_BUILD_ROOT=`pwd`
在其后面添加
RTMP_ROOT="$FF_BUILD_ROOT/rtmpdump"
RTMP_ARCH=
依次在其中添加RTMP_ARCH=”xxx”
if [ "$FF_ARCH" = "armv7a" ]; then
...
RTMP_ARCH="armeabi-v7a"
elif [ "$FF_ARCH" = "armv5" ]; then
...
RTMP_ARCH="armeabi"
elif [ "$FF_ARCH" = "x86" ]; then
...
RTMP_ARCH="x86"
elif [ "$FF_ARCH" = "x86_64" ]; then
...
RTMP_ARCH="x86_64"
elif [ "$FF_ARCH" = "arm64" ]; then
...
RTMP_ARCH="arm64-v8a"
else
echo "unknown architecture $FF_ARCH";
exit 1
fi
//找到
FF_CFLAGS="-O3 -Wall -pipe \
-std=c99 \
-ffast-math \
-fstrict-aliasing -Werror=strict-aliasing \
-Wno-psabi -Wa,--noexecstack \
-DANDROID -DNDEBUG"
//在其后面添加
FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-protocol=librtmp*"
FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-librtmp"
FF_CFLAGS="$FF_CFLAGS -I${RTMP_ROOT}"
FF_DEP_LIBS="-L${RTMP_ROOT}/obj/local/${RTMP_ARCH} -lrtmp"
B.分别在下面的文件中
/android/contrib/ffmpeg-arm64/configure
/android/contrib/ffmpeg-armv5/configure
/android/contrib/ffmpeg-armv7a/configure
/android/contrib/ffmpeg-x86/configure
/android/contrib/ffmpeg-x86_64/configure
找到并注释掉这行
#enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
6.最后编译
cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
cd ..
./compile-ijk.sh all
这是编译ijk所支持的全部cpu架构的例子,只编译其中一个的话,按需修改一下就ok了.