最近剛接觸ffmpeg,找了很多相關(guān)的編譯資料驶乾,都沒有編譯成功,前幾天在 github上找到一個(gè)腳本(https://github.com/kewlbear/FFmpeg-iOS-build-script)针贬,就可完美編譯
準(zhǔn)備條件
先下載文件:https://github.com/libav/gas-preprocessor昆禽,
復(fù)制gas-preprocessor.pl到/usr/sbin下,
修改文件權(quán)限:chmod 777 /usr/local/bin/gas-preprocessor.pl
安裝yasm
具體步驟如下:
1. 下載腳本:https://github.com/kewlbear/FFmpeg-iOS-build-script
2. 解壓著角,找到文件 build-ffmpeg.sh
3. 執(zhí)行服本文件:./build-ffmpeg.sh, 由于本人沒有事先安裝Yasm 執(zhí)行腳本文件會(huì)出錯(cuò)事富,
如下:
MAC:FFmpeg-iOS-build-script-master-2 jinsonglnan$ ./build-ffmpeg.sh
Yasm not found
Homebrew not found. Trying to install...
Whoops, the Homebrew installer has moved! Please instead run:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Also, please ask wherever you got this link from to update it to the above.
Trying to install Yasm...
./build-ffmpeg.sh: line 67: brew: command not found
意思就是說技俐,沒有yasm, 看到提示執(zhí)行 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"安裝
4.編譯完成后,終端進(jìn)入FFmpeg-iOS-build-script目錄统台,然后輸入./build-ffmpeg.sh lipo雕擂,這個(gè)命令是講.a文件合并成一個(gè)
5.把ffmpeg-iOS文件加入到工程中
6.添加一個(gè)頭文件引用 #include "avformat.h"
添加一個(gè)api語句:av_register_all();給一個(gè)類文件.m后綴改為.mm,開啟混編模式贱勃。
運(yùn)行工程井赌,如果沒有報(bào)錯(cuò),則表明編譯成功
7.其他注意細(xì)節(jié)
編譯的時(shí)候報(bào)錯(cuò): 'libavcodec/avcodec.h' file not found 贵扰,修改Header search paths 里的路徑:$(PROJECT_DIR)/FFmpeg-iOS/include
加入External libraries:
libz.dylib
libbz2.dylib
libiconv.dylib