簡介
? ? 1.FFmpeg是一套可以用來記錄、轉換數字音頻、視頻,并能將其轉化為流的開源計算機程序。采用LGPL或GPL許可證。它提供了錄制、轉換以及流化音視頻的完整解決方案。它包含了非常先進的音頻/視頻編解碼庫libavcodec,為了保證高可移植性和編解碼質量,libavcodec里很多code都是從頭開發的。
官網:https://ffmpeg.org
功能
????多媒體視頻處理工具FFmpeg有非常強大的功能包括視頻采集功能、視頻格式轉換、視頻抓圖、給視頻加水印等。
下載
????兩種方式
? ? 1. 官網下載
? ? ? ? 下載地址:http://www.ffmpeg.org/download.html
? ? 2. 通過shell腳本下載
? ??????#!/bin/bash
? ? ? ? source="ffmpeg-3.4"
????????if [ ! -r $source ]
????????then
? ? ? ? ? ?????echo "沒有FFmpeg庫,我們需要下載….."
? ? ? ? ????????curl http://ffmpeg.org/releases/${source}.tar.bz2 | tar xj || exit 1
????????fi
將上面的腳本復制保存為xxx.sh在Linux或Mac OS系統上通????.xxx.sh運行腳本即可下載
解釋一下腳本
?#!/bin/bash 定義文件聲明
source="ffmpeg-3.4" 定義下載的ffmpeg版本是3.4
分解 ?
? ?????if [ ! -r $source ]
????????then
? ? ? ? ? ?????echo "沒有FFmpeg庫,我們需要下載….."
? ? ? ? ????????curl http://ffmpeg.org/releases/${source}.tar.bz2 | tar xj || exit 1
????????fi
#if判斷語句 如果條件成立那么執行then和fi之間的語句
??if [ 條件 ]
? then
? ?fi
# -r 檢測文件是否可讀,如果是,那么返回true
上面的if判讀的意思是如果$source不可讀就執行then下面的語句
#echo 就是向控制臺輸出文本內容
#"curl"命令表示:它可以通過Http\ftp等等這樣的網絡方式下載和上傳文件(它是一個強大網絡工具)
#基本格式:curl 地址
# 了解了curl命令后來理解一下這句話? curl http://ffmpeg.org/releases/${source}.tar.bz2 | tar xj || exit 1?
“|”是Linux的管道命令 作用是將前面的結果作為后面命令的輸入,在上面的例子就是將curl下載好的bz2文件作為 tar xj || exit 1的輸
#"tar"命令:表示解壓和壓縮(打包)
????基本語法:tar options
????例如:tar xj
????options選項分為很多中類型
????#-x 表示:解壓文件選項
????#-j 表示:是否需要解壓bz2壓縮包(壓縮包格式類型有很多:zip、bz2等等…)
# exit 1 表示退出腳本
# || 邏輯或運算
上面的命令完整的意思是 下載成功便解壓壓縮包否則退出腳本
編譯
先上腳本
#!/bin/bash
source="ffmpeg-3.4"
cache="cache"
staticdir='pwd'/"tyf1946-ffmpeg-iOS"
configure_flags="--enable-cross-compile --disable-debug --disable-programs --disable-doc --enable-pic"
archs="arm64 armv7 x86_x64 i386"
targetversion="7.0"
if [ "$*" ]
then
archs="$*"
fi
if [ ! `which yasm` ]
then
if [ ! 'which brew' ]
then
echo '安裝brew'
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || exit 1
fi
echo "安裝brew"
brew install yasm || exit 1
fi
echo "循環編譯"
currentdir='pwd'
for arch in $archs
do
echo "開始編譯"
mkdir -p "$cache/$arch"
cd "$cache/$arch"
archflags="-arch $arch"
if [ "$arch" = "i386" -o "$arch" = "x86_64" ]
then
platform="iPhoneSimulator"
archflags="$archflags -mios-simulator-version-min=$targetversion"
else
platform="iPhoneOS"
archflags="$archflags -mios-version-min=$targetversion -fembed-bitcode"
if [ "$arch" = "arm64" ]
then
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi
XCRUN_SDK=`echo $platform | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
if [ "arch" = "arm64" ]
then
AS="gas-preprocessor.pl -arch aarch64 -- $CC"
else
AS="$CC"
fi
echo "執行到了1"
TMPDIR=${TMPDIR/%\/} $currentdir/$source/configure \
--target-os=darwin \
--arch=$arch \
--cc="$CC" \
--as="$AS" \
$configure_flags \
--extra-cflags="$archflags" \
--extra-ldflags="$archflags" \
--prefix="$staticdir/$arch" \
|| exit 1
echo "執行了"
make -j3 install $EXPORT || exit 1
cd $currentdir
done
下載gas-preprocessor? 【 https://github.com/yuvi/gas-preprocessor 】
并復制到?/usr/local/bin/ 目錄? 添加執行權限 chmod +x?gas-preprocessor?
這個腳本編譯的是iOS用的.a靜態庫?
執行成功后就可以看到編譯好的庫了
在執行過程中遇到了一個錯誤?C compiler test failed
查看ffbuild/config.log"日志文件
發現有這么一行xcrun: error: SDK "iphoneos" cannot be located
在終端中執行?
xcrun --sdk iphoneos --show-sdk-path
xcrun: error: SDK "iphoneos" cannot be located
查找原因
xcode-select --print-path
/Library/Developer/CommandLineTools
發現是這個Xcode路徑判斷錯誤。
xcodebuild -showsdks
xcode-select: error: tool'xcodebuild'requires Xcode, but active developer directory'/Library/Developer/CommandLineTools'is a command line tools instance
解決方法:給Xcode命令行工具指定路徑
sudoxcode-select--switch /Applications/Xcode.app/Contents/Developer/