脚本分析:
#! /usr/bin/env bash
# B站托管与github的ffmpeg分支的下载地址
# IJK_FFMPEG_UPSTREAM=git://git.videolan.org/ffmpeg.git
IJK_FFMPEG_UPSTREAM=https://github.com/Bilibili/FFmpeg.git
IJK_FFMPEG_FORK=https://github.com/Bilibili/FFmpeg.git
# ffmpeg版本
IJK_FFMPEG_COMMIT=ff3.4--ijk0.8.7--20180103--001
# ffmpeg下载目录
IJK_FFMPEG_LOCAL_REPO=extra/ffmpeg
# gas-preprocessor是用于编译FFmpeg的perl预处理脚本
IJK_GASP_UPSTREAM=https://github.com/Bilibili/gas-preprocessor.git
# gas-preprocessor backup
# https://github.com/Bilibili/gas-preprocessor.git
if [ "$IJK_FFMPEG_REPO_URL" != "" ]; then
IJK_FFMPEG_UPSTREAM=$IJK_FFMPEG_REPO_URL
IJK_FFMPEG_FORK=$IJK_FFMPEG_REPO_URL
fi
if [ "$IJK_GASP_REPO_URL" != "" ]; then
IJK_GASP_UPSTREAM=$IJK_GASP_REPO_URL
fi
# 每个脚本都应该在文件开头加上set -e
set -e
# 定义文件目录
TOOLS=tools
# iOS6架构 iOS7架构 iOS8架构
FF_ALL_ARCHS_IOS6_SDK="armv7 armv7s i386"
FF_ALL_ARCHS_IOS7_SDK="armv7 armv7s arm64 i386 x86_64"
FF_ALL_ARCHS_IOS8_SDK="arm64"
# 所有架构 = iOS8架构
FF_ALL_ARCHS=$FF_ALL_ARCHS_IOS8_SDK
# 获取脚本第一个参数
FF_TARGET=$1
# 定义函数【echo_ffmpeg_version】
function echo_ffmpeg_version() {
# 输出 ffmpeg版本号
echo $IJK_FFMPEG_COMMIT
}
# 定义函数【pull_common】
function pull_common() {
# 查看git版本
git --version
# 输出 "== pull gas-preprocessor base =="
echo "== pull gas-preprocessor base =="
# 执行当前文件夹下tools文件夹中的pull-repo-base.sh 并且传入两个参数(https://github.com/Bilibili/gas-preprocessor.git,extra/gas-preprocessor)下载gas-preprocessor
sh $TOOLS/pull-repo-base.sh $IJK_GASP_UPSTREAM extra/gas-preprocessor
echo "== pull ffmpeg base =="
# 执行当前文件夹下tools文件夹中的pull-repo-base.sh 并且传入两个参数(https://github.com/Bilibili/FFmpeg.git,extra/ffmpeg),下载FFmpeg
sh $TOOLS/pull-repo-base.sh $IJK_FFMPEG_UPSTREAM $IJK_FFMPEG_LOCAL_REPO
}
# 定义函数【pull_fork】
function pull_fork() {
# 输出 平台架构
echo "== pull ffmpeg fork $1 =="
# 执行tools文件夹下的pull-repo-ref.sh脚本 并且传入3个参数 (https://github.com/Bilibili/FFmpeg.git , ios/ffmpeg-平台架构 ,extra/ffmpeg)
sh $TOOLS/pull-repo-ref.sh $IJK_FFMPEG_FORK ios/ffmpeg-$1 ${IJK_FFMPEG_LOCAL_REPO}
# 进入 ffmpeg-平台架构文件
cd ios/ffmpeg-$1
# 切换到ffmpeg版本分支,并且强制创建新的分支ijkplayer
git checkout ${IJK_FFMPEG_COMMIT} -B ijkplayer
# 回到上一级目录
cd -
}
# 定义函数【pull_fork_all】
function pull_fork_all() {
# 遍历FF_ALL_ARCHS,依次调用pull_fork函数
for ARCH in $FF_ALL_ARCHS
do
pull_fork $ARCH
done
}
function sync_ff_version() {
sed -i '' "s/static const char \*kIJKFFRequiredFFmpegVersion\ \=\ .*/static const char *kIJKFFRequiredFFmpegVersion = \"${IJK_FFMPEG_COMMIT}\";/g" ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.m
}
#----------
# 逻辑分支语句
# FF_TARGET => $1
# 执行脚本的时候,没有传任何参数,因此$1 = 空
# case "$FF_TARGET" in => case "$1" in => case "" in
# 不满足任何条件,执行 *) 后面的语句(执行pull_common,pull_fork_all函数)
case "$FF_TARGET" in
ffmpeg-version)
echo_ffmpeg_version
;;
armv7|armv7s|arm64|i386|x86_64)
pull_common
pull_fork $FF_TARGET
;;
all|*)
pull_common
pull_fork_all
;;
esac
sync_ff_version
网友评论