iOS 開(kāi)發(fā)之編譯ffmpeg 及報(bào)錯(cuò)解析
一蚁趁、腳本編譯
1. 編譯Mac下可用 FFmpeg
編譯Mac下可用 FFmpeg圣猎,主要是可以在mac中爆惧,使用 FFmpeg 進(jìn)行操作視頻等寥袭。
Homebrew介紹
簡(jiǎn)稱brew,是Mac OSX上的軟件包管理工具淹真,能在Mac中方便的安裝軟件或者卸載軟件讶迁。
Homebrew安裝
打開(kāi)終端執(zhí)行
```
?ruby -e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)”)"
```
Homebrew命令使用
搜索軟件:brew search 軟件名, 如brew search wget
安裝軟件:brew install 軟件名核蘸, 如brew install wget
卸載軟件:brew remove 軟件名巍糯,如brew remove wget
通過(guò)Homebrew 安裝 FFmpeg
終端執(zhí)行:執(zhí)行 brew install ffmpeg --with-libvpx --with-libvorbis --with-ffplay
在終端中執(zhí)行一下命令,等待安裝完成即可:
```
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
安裝好Homebrew客扎,然后終端執(zhí)行 "brew install ffmpeg"祟峦,等待完成即可。
執(zhí)行結(jié)束徙鱼,在終端中輸入ffmpeg宅楞,驗(yàn)證是否安裝成功。
2. 編譯 iOS 下 FFmpeg
主要是用于iOS下可用的FFmpeg
手動(dòng)編譯FFmpeg網(wǎng)上有一些方法袱吆,但是稍顯復(fù)雜而陳舊, 所以現(xiàn)在大部分都是使用FFmpeg-iOS-build-script.sh這個(gè)腳本厌衙,比較方便直接
FFmpeg-iOS-build-script 是一個(gè)外國(guó)人寫的自動(dòng)編譯的腳本,腳本則會(huì)自動(dòng)從github中把ffmpeg源碼下到本地并開(kāi)始編譯出iOS可用的庫(kù)绞绒,支持各種架構(gòu)婶希。
在進(jìn)行編譯之前,需要做一些準(zhǔn)備工作安裝必備文件:
2.1 安裝 gas-preprocessor
后面運(yùn)行 FFmpeg-iOS-build-script 這個(gè)自動(dòng)編譯腳本需要 gas-preprocessor .
安裝步驟(依次執(zhí)行下面命令):
```
sudo git clone https://github.com/bigsen/gas-preprocessor.git? /usr/local/bin/gas
sudo cp /usr/local/bin/gas/gas-preprocessor.pl /usr/local/bin/gas-preprocessor.pl
sudo chmod 777 /usr/local/bin/gas-preprocessor.pl
sudo rm -rf /usr/local/bin/gas/
```
2.2 安裝 yams
yasm是匯編編譯器蓬衡,因?yàn)閒fmpeg中為了提高效率用到了匯編指令喻杈,所以編譯時(shí)需要安裝
安裝步驟(依次執(zhí)行下面命令):
```
curl http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz-o yasm-1.2.0.gz
tar-zxvf yasm-1.2.0.gz
cd yasm-1.2.0
./configure&&make-j4&&sudomakeinstall
```
2.3 配置 FFmpeg 編譯腳本
下載編譯腳本
```
git clone https://github.com/kewlbear/FFmpeg-iOS-build-script.git
```
2. 執(zhí)行?build-ffmpeg.sh
cd 到?build-ffmpeg.所在的目錄下,然后執(zhí)行:
```
./build-ffmpeg.sh
```
這個(gè)時(shí)候如果你的Mac曾經(jīng)安裝過(guò)多個(gè)版本的Xcode 狰晚,執(zhí)行./build-ffmpeg.sh 時(shí)可能會(huì)報(bào)錯(cuò):
building arm64...
xcrun -sdk iphoneos clang is unable to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git.? If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
3. 報(bào)錯(cuò)分析
這個(gè)報(bào)錯(cuò)說(shuō)的是交叉編譯時(shí)找不到?iphoneos?sdk 的可執(zhí)行文件筒饰,這是因?yàn)榘惭b多版本xcode 后造成訪問(wèn)Xcode路徑判斷錯(cuò)誤引起的。
4. 解決方法
在終端中執(zhí)行:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
執(zhí)行時(shí)需要輸入Mac 登錄密碼壁晒,輸入密碼enter即可瓷们。
說(shuō)明: 這是設(shè)置Xcode 的默認(rèn)訪問(wèn)路徑
執(zhí)行完后,再執(zhí)行:
./build-ffmpeg.sh
這個(gè)時(shí)候不會(huì)再報(bào)剛才的錯(cuò)誤了,OK完美解決换棚。