本文使用cygwin编译
1.cygwin的环境搭建
2.打开cygwin,使用git,clone源码:
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
3.打开目录并初始化,此处会下载ffpmeg源码,如果有梯子一定要使用,否则很慢
cd ijkplayer-android
git checkout -B latest k0.8.8
./init-android.sh
4.编译ffmpeg
编译ffmpeg之前,需要注意,要修改一下东西才能在win下使用,我的修改方法为:
在tools目录下的do-compile-ffmpeg.sh,修改软连接为copy操作
cp -rf $FF_PREFIX/include $FF_PREFIX/shared/include
cp -rf $FF_PREFIX/libijkffmpeg.so $FF_PREFIX/shared/lib/libijkffmpeg.so
#ln -s $FF_PREFIX/include $FF_PREFIX/shared/include
#ln -s $FF_PREFIX/libijkffmpeg.so $FF_PREFIX/shared/lib/libijkffmpeg.so
为了增加rtsp的支持,删除config目录下原有的module.sh,把module-lite.sh复制一份另存为module.sh,在文件module.sh后面增加如下代码:
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=rtp"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=tcp"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=rtsp"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=sdp"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=rtp"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-linux-perf"
然后进入文件夹编译
cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
5.编译ijkplayer源码
此处修改的东西比较多
a.修改comlie-ijk.sh中如下do_sub_cmd代码,主要也是把链接文件改为copy操作:
do_sub_cmd () {
SUB_CMD=$1
if [ -L "./android-ndk-prof" ]; then
rm android-ndk-prof
fi
if [ "$PARAM_SUB_CMD" = 'prof' ]; then
echo 'profiler build: YES';
#ln -s ../../../../../../ijkprof/android-ndk-profiler/jni android-ndk-prof
if [ ! -d "android-ndk-prof" ]; then
mkdir android-ndk-prof
fi
cp -rf ../../../../../../ijkprof/android-ndk-profiler/jni/* android-ndk-prof
else
echo 'profiler build: NO';
#ln -s ../../../../../../ijkprof/android-ndk-profiler-dummy/jni android-ndk-prof
if [ ! -d "android-ndk-prof" ]; then
mkdir android-ndk-prof
fi
cp -rf ../../../../../../ijkprof/android-ndk-profiler-dummy/jni/* android-ndk-prof
fi
case $SUB_CMD in
prof)
$ANDROID_NDK/ndk-build $FF_MAKEFLAGS
;;
clean)
$ANDROID_NDK/ndk-build clean
;;
rebuild)
$ANDROID_NDK/ndk-build clean
$ANDROID_NDK/ndk-build $FF_MAKEFLAGS
;;
*)
$ANDROID_NDK/ndk-build $FF_MAKEFLAGS
;;
esac
}
b.修改comlie-ijk.sh中do_ndk_build 对ijkmedia文件夹的copy:
do_ndk_build () {
PARAM_TARGET=$1
PARAM_SUB_CMD=$2
case "$PARAM_TARGET" in
armv5|armv7a)
rm -rf ijkplayer/ijkplayer-$PARAM_TARGET/src/main/jni/ijkmedia
cp -rf ../ijkmedia ijkplayer/ijkplayer-$PARAM_TARGET/src/main/jni/
cd "ijkplayer/ijkplayer-$PARAM_TARGET/src/main/jni"
do_sub_cmd $PARAM_SUB_CMD
cd -
;;
arm64|x86|x86_64)
rm -rf ijkplayer/ijkplayer-$PARAM_TARGET/src/main/jni/ijkmedia
cp -rf ../ijkmedia ijkplayer/ijkplayer-$PARAM_TARGET/src/main/jni/
cd "ijkplayer/ijkplayer-$PARAM_TARGET/src/main/jni"
if [ "$PARAM_SUB_CMD" = 'prof' ]; then PARAM_SUB_CMD=''; fi
do_sub_cmd $PARAM_SUB_CMD
cd -
;;
esac
}
c.手动复制android\ijkplayer\ijkplayer-armv7a\src\main\jni 下的ffmpeg文件夹和Android.mk文件,如果不复制,会出现Segmentation fault (核心已转储)$GNUMAKE -f $PROGDIR/build/core/build-local.mk
d.至此,ijkplayer就可以编译了
cd ..
./compile-ijk.sh all