轉(zhuǎn)載請(qǐng)注明原地址,Clang的博客:https://chenhu1001.github.io 謝謝!
作者:Clang
鏈接:http://www.itdecent.cn/p/f96854919ed4
來源:簡(jiǎn)書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。
一、基本編譯
二、高級(jí)編譯
三、導(dǎo)入MacOS項(xiàng)目后,添加系統(tǒng)依賴庫
我們今天來說說如何編譯出適用于macOS APP的庫,包括動(dòng)態(tài)庫和靜態(tài)庫。
一、基本編譯
1、首先我們下載一個(gè)最新的ffmpeg源碼。
git clone https://git.ffmpeg.org/ffmpeg.git
2、配置./configure選項(xiàng),這個(gè)要注意需要設(shè)置對(duì)macOS最低版本的要求,否則是默認(rèn)當(dāng)前本機(jī)的最新系統(tǒng)如,這樣的話在使用庫的時(shí)候,如果是APP要運(yùn)行在10.10及之下的系統(tǒng)時(shí)候,就會(huì)報(bào)錯(cuò)。
--extra-cflags=-mmacosx-version-min=10.8 --extra-ldflags=-mmacosx-version-min=10.8
3、執(zhí)行./configure內(nèi)容如下:
./configure --target-os=darwin --enable-static --enable-swscale --enable-nonfree --enable-gpl --enable-version3 --enable-nonfree --disable-programs --libdir=/ffmpegbuild/lib --incdir=/ffmpegbuild/include --enable-shared --extra-cflags=-mmacosx-version-min=10.8 --extra-ldflags=-mmacosx-version-min=10.8
注意:
1.編譯后的MacOS版本FFmpeg庫,需要添加liblzma.tbd系統(tǒng)庫;
然后打包項(xiàng)目提交審核的時(shí)候,就悲催被拒了;
原因是調(diào)用了私有方法庫:Your app uses or references the following non-public APIs: Symbols: _lzma_end, _lzma_stream_decoder, _lzma_code The use of non-public APIs is not permitted on the App Store, because >it can lead to a poor user experience should these APIs change.2.liblzma是一個(gè)關(guān)于壓縮解壓的算法庫,編譯ffmpeg的時(shí)候,可以選擇不用這個(gè)庫;
禁用lzma庫的設(shè)置: –disable-lzma3.執(zhí)行./configure的時(shí)候,就變成了:
./configure --target-os=darwin --enable-static --enable-swscale --enable-nonfree --disable-lzma --enable-gpl --enable-version3 --enable-nonfree --disable-programs --libdir=/ffmpegbuild/lib --incdir=/ffmpegbuild/include --enable-shared --extra-cflags=-mmacosx-version-min=10.13 --extra-ldflags=-mmacosx-version-min=10.13
4、執(zhí)行編譯和安裝
make && sudo make install
5、在根目錄下的ffmpegbuild目錄中,就是編譯好的頭文件和庫文件,包括靜態(tài)庫和動(dòng)態(tài)庫。
二、高級(jí)編譯
前面的之所以說是基本編譯,主要都是ffmpeg自帶的庫的編譯,包括了幾乎全部的大部分的Decoder解碼編譯器,但是對(duì)于Encoder編碼編譯器,卻不是特別多,比如aac就只有解碼器沒有編碼器,如果想要對(duì)一個(gè)音頻轉(zhuǎn)換到aac格式,那么這時(shí)候就需要用的aac編碼器。
1、下載和編譯aac庫
git clone https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
./autogen.sh /* 執(zhí)行這個(gè)一步的需要automake,如果沒有可以直接brew install automake */
./configure —enable-shared —enable-static —prefix=/Users/forcetech/Downloads/opt/
make && sudo make install
當(dāng)然也可以直接通過brew安裝編譯后的aac庫,下面是我使用的命令
brew install fdk-aac
2、下載和編譯x264庫
git clone http://git.videolan.org/git/x264.git.
cd x264
./configure —disable-asm —enable-shared —enable-static —prefix=/Users/forcetech/Downloads/opt/
make && sudo make install
當(dāng)然也可以直接通過brew安裝編譯后的x264庫,下面是我使用的命令行
brew install x264
3、./configure配置
這里要注意,需要把a(bǔ)cc、x264的庫文件和頭文件的路徑加到配置里面,要不回出錯(cuò),提示aac not found。
./configure --target-os=darwin --enable-static --enable-swscale --enable-libfdk-aac --enable-libx264 --enable-nonfree --enable-gpl --enable-version3 --enable-nonfree --disable-programs --libdir=/ffmpegbuild/lib --incdir=/ffmpegbuild/include --enable-shared --extra-cflags=-mmacosx-version-min=10.8 --extra-ldflags=-mmacosx-version-min=10.8 --extra-cflags=-I/Users/forcetech/Downloads/opt/include --extra-ldflags=-L/Users/forcetech/Downloads/opt/lib --prefix=/Users/forcetech/Downloads/opt/
4、執(zhí)行編譯和安裝
make && sudo make install
5、在根目錄下的ffmpegbuild目錄中,就是編譯好的頭文件和庫文件,包括靜態(tài)庫和動(dòng)態(tài)庫。
三、導(dǎo)入MacOS項(xiàng)目后,添加系統(tǒng)依賴庫
