作者:莫不静了_660 | 来源:互联网 | 2023-07-11 16:32
本文将从零开始详细讲述怎么在ijkplayer中添加使用librtmp库编译环境:ubuntu16.101.安装必要的软件sudoapt-getinstallgitmakey
本文将从零开始详细讲述怎么在ijkplayer中添加使用librtmp库
编译环境:
ubuntu 16.10
1.安装必要的软件
sudo apt-get install git make yasm
2.下载并编译ijkplayer,确保源码无错
git clone https:
cd ijkplayer-android
git checkout -B latest k0.7.5
./init-android.shcd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh allcd ..
./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:
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")
endifinclude $(subdirs)
AndroidManifest.xml:
<manifest xmlns:android&#61;"http://schemas.android.com/apk/res/android"android:versionCode&#61;"1"android:versionName&#61;"0.1" ><uses-sdk android:minSdkVersion&#61;"9" />manifest>
jni/Application.mk:
NDK_TOOLCHAIN_VERSION :&#61; 4.9
APP_ABI :&#61; armeabi-v7a armeabi arm64-v8a x86 x86_64
APP_PROJECT_PATH :&#61; $(shell pwd)
APP_BUILD_SCRIPT :&#61; $(APP_PROJECT_PATH)/Android.mk
librtmp/Android.mk:
LOCAL_PATH:&#61; $(call my-dir)
include $(CLEAR_VARS)LOCAL_C_INCLUDES &#43;&#61; $(NDK_PROJECT_PATH)/librtmp \$(SSL)/includeLOCAL_SRC_FILES:&#61; \amf.c \hashswf.c \log.c \parseurl.c \rtmp.cLOCAL_CFLAGS &#43;&#61; -I$(SSL)/include -DUSE_OPENSSL
LOCAL_LDLIBS &#43;&#61; -L$(SSL)/lib
LOCAL_LDLIBS &#43;&#61; -lssl -lcrypto -lz
LOCAL_DISABLE_FATAL_LINKER_WARNINGS :&#61; trueLOCAL_MODULE :&#61; librtmp
include $(BUILD_STATIC_LIBRARY)
在rtmp目录下执行编译:
ndk-build
成功后会看到目录下多了obj这个文件夹,里面有对应版本的rtmp静态库
5.将librtmp编译到ffmpeg里
A.修改/android/contrib/tools/do-compile-ffmpeg.sh文件
找到
FF_BUILD_ROOT&#61;&#96;pwd&#96;
在其后面添加
RTMP_ROOT&#61;"$FF_BUILD_ROOT/rtmpdump"
RTMP_ARCH&#61;
依次在其中添加RTMP_ARCH&#61;”xxx”
if [ "$FF_ARCH" &#61; "armv7a" ]; then...RTMP_ARCH&#61;"armeabi-v7a"elif [ "$FF_ARCH" &#61; "armv5" ]; then...RTMP_ARCH&#61;"armeabi"elif [ "$FF_ARCH" &#61; "x86" ]; then...RTMP_ARCH&#61;"x86"elif [ "$FF_ARCH" &#61; "x86_64" ]; then...RTMP_ARCH&#61;"x86_64"elif [ "$FF_ARCH" &#61; "arm64" ]; then...RTMP_ARCH&#61;"arm64-v8a"elseecho "unknown architecture $FF_ARCH";exit 1
fi
//找到
FF_CFLAGS&#61;"-O3 -Wall -pipe \-std&#61;c99 \-ffast-math \-fstrict-aliasing -Werror&#61;strict-aliasing \-Wno-psabi -Wa,--noexecstack \-DANDROID -DNDEBUG"
//在其后面添加
FF_CFG_FLAGS&#61;"$FF_CFG_FLAGS --enable-protocol&#61;librtmp*"
FF_CFG_FLAGS&#61;"$FF_CFG_FLAGS --enable-librtmp"
FF_CFLAGS&#61;"$FF_CFLAGS -I${RTMP_ROOT}"
FF_DEP_LIBS&#61;"-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
C.在/config/module-lite.sh里面查找或插入下面2个值
export COMMON_FF_CFG_FLAGS&#61;"$COMMON_FF_CFG_FLAGS --enable-protocol&#61;librtmp*"
export COMMON_FF_CFG_FLAGS&#61;"$COMMON_FF_CFG_FLAGS --enable-librtmp"
6.最后编译
cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
cd ..
./compile-ijk.sh all
这是编译ijk所支持的全部cpu架构的例子,只编译其中一个的话,按需修改一下就ok了
参考文章:
http://blog.csdn.net/lyqaizhy/article/details/49077027
http://zhengxiaoyong.me/2016/11/13/%E5%88%9D%E8%AF%86FFmpeg%E7%BC%96%E8%AF%91%E9%82%A3%E4%BA%9B%E4%BA%8B
http://zhengxiaoyong.me/2016/11/20/%E7%AE%80%E8%BF%B0RTMPDump%E4%B8%8E%E7%BC%96%E8%AF%91%E7%A7%BB%E6%A4%8D/
https://github.com/yixia/librtmp