FFmpeg Mac 編譯下載與安裝

下載

git clone https://git.ffmpeg.org/ffmpeg.git

幫助

cd ffmpeg
./configure --help | more

安裝必備的 yasm

brew install yasm
// 如果安裝失敗,請使用
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
// 然後再執行安裝

問題1:ERROR: libfdk_aac not found

brew install fdk-aac

ERROR: speex not found using pkg-config

brew install speex
brew install pkg-config

ERROR: libx264 not found

brew install x264

ERROR: x265 not found using pkg-config

brew install x265

安裝SDL

brew  install sdl2

如果你不安裝的話,生成出來的 ffmpeg 沒有 ffplay

進入下載好的FFmpeg目錄配置

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags=

如果是靜態庫

./configure --prefix=/usr/local/ffmpeg --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags=
// 未測試
--disable-shared --enable-static
// 因爲關聯的 libx264 這些 都默認動態,所以要刪除對應目錄文件 只留 .a <靜態庫>文件

查看文件,確認是否成功

vi Makefile 

最後的編譯

sudo make & make  install

查看是否編譯成功

/usr/local/ffmpeg/bin/ffmpeg

添加環境變量

//如果沒有權限
sudo chmod 777 ~/.bash_profile 
 vim ~/.bash_profile 
 // 加入這句
export PATH=$PATH:/usr/local/ffmpeg/bin
// 然後退出vim
wq
// 更新環境變量
source  ~/.bash_profile 
// 命令行中輸入測試
ffmpeg

No package ‘libavformat’ found

# 加入環境
export PKG_CONFIG_PATH="$PATH:/usr/local/ffmpeg/lib/pkgconfig"

備註:

~/.bash_profile (一般在這個文件中添加用戶級環境變量)
(注:Linux 裏面是 .bashrc 而 Mac 是 .bash_profile)
若bash shell是以login方式執行時,纔會讀取此文件。該文件僅僅執行一次!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章