前言
筆者也是剛開始學習FFMpeg,對于FFMpeg在iOS上的環(huán)境搭建在網(wǎng)上找了很多文章瀑罗,發(fā)現(xiàn)大多都是copy冗酿,而且有些是不可用的;有些可用但是版本比較老仇冯,對于有強迫癥的我來說是接受不了的之宿;為此筆者在這里繞了很久,寫下這篇文章用來記錄怎么在iOS搭建可以使用的FFMpeg庫苛坚,以及給后來者一些借鑒比被,如有異議請指出。
概念
FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.
總的來說FFMpeg是一個跨平臺的解碼泼舱、編碼等缀、轉碼、復用娇昙、解復用尺迂、流式傳輸、過濾和播放的庫
環(huán)境搭建
1.下載ffmpeg
冒掌,打開終端執(zhí)行下面的命令
brew install ffmpeg
如果未安裝homebrew終端會提示
-bash: brew: command not found
使用下面的命令安裝homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝完homebrew之后噪裕,再下載ffmpeg,此時有可能提示Xcode需要更新等股毫,按照提示完成相關操作即可膳音。
2.下載shell腳本FFmpeg-iOS-build-script
下載完腳本后,解壓會看到三個文件铃诬,我們只需要編譯iOS庫所以只需要build-ffmpeg.sh
即可祭陷;在終端cd到該文件的目錄,執(zhí)行下面命令
./build-ffmpeg.sh arm64 x86_64
解釋下上面命令趣席,arm64
指的是ARM CPU
的指令集兵志,不同的芯片對應不同的指令集,指令集是向下兼容的宣肚,所以用arm64
即可
x86_64
是Mac處理器的指令集想罕,即用于模擬器
執(zhí)行上面命令提示如下報錯xcrun -sdk iphoneos clang is unable to create an executable file.
解決方案,在終端執(zhí)行下面命令即可
sudo xcode-select --switch /Applications/Xcode.app
接下來再次執(zhí)行build-ffmpeg.sh
腳本霉涨,經(jīng)過漫長的等待弧呐,在build-ffmpeg.sh
腳本目錄下會多出幾個文件夾ffmpeg-4.1
、FFmpeg-iOS
嵌纲、scratch
、thin
腥沽。
3.打開Xcode逮走,新建項目
將FFmpeg-iOS
拖入工程,添加
- libz.tbd
- libbz2.tbd
- libiconv.tbd
- AudioToolBox.framework
- VideoToolBox.framework
至此FFMpeg環(huán)境搭建告一段落今阳。