赞
踩
本篇介绍的是Mac安装FFmpeg的教程,该教程是为进行音视频的开发学习作准备的,很多时候需要看源码调试学习,若只为了熟悉使用ffmpeg
、ffplay
、ffprobe
等命令,建议直接使用brew install ffmpeg
安装稳定版本。
Homebrew是MacOS(或 Linux)的软件包管理器,可以说是神器了。用于软件包的安装、更新、卸载、搜索等等。
#需要梯子
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
没有梯子的使用国内,可以参考一下其他博客的方法,由于要编译ffmpeg
会装比较多的库,推荐用国内镜像
#使用检验
brew -v
这里并没有直接使用brew install ffmpeg
安装是因为后续想用源码调试。
最新稳定版本
其他版本
使用git
安装源码比较方便版本切换,推荐此方法
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
查看远端的分支
cd ffmpeg && git branch -r
拉取远端分支到本地 - 将来想要切换分支比较方便
git checkout -b release/7.0 origin/release/7.0
接下来使用brew
进行安装编译需要的库,建议一个一个下
brew install automake brew install fdk-aac brew install lame brew install libass brew install libtool brew install libvorbis brew install libvpx brew install libvo-aacenc brew install opencore-amr brew install openjpeg brew install opus brew install speex brew install texi2html brew install x264 brew install x265 brew install xvid brew install yasm brew install freetype brew install pkg-config brew install shtool brew install theora brew install sdl2 brew install aom brew install aribb24 brew install dav1d brew install fontconfig brew install libbluray brew install libgsm brew install openh264 brew install libmodplug brew install snappy brew install libsoxr brew install two-lame brew install libvidstab brew install zimg brew install zmq
配置编译信息 - 可以参考官网这部分的编译
./configure --prefix=/usr/local/ffmpeg --extra-cflags="-I/opt/homebrew/include" --extra-ldflags="-L/opt/homebrew/lib" --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --enable-avisynth --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --disable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-static --enable-shared --enable-fontconfig --enable-libaom --enable-libbluray --enable-libdav1d --enable-libgsm --enable-libharfbuzz --enable-libmodplug --enable-libmysofa --enable-libopenh264 --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libwebp --enable-libx265 --enable-libxavs --enable-libxml2 --enable-libzimg --enable-libzmq --enable-libzvbi --enable-openssl
-------------------------------------------------------------------------------------------
--prefix=/usr/local/ffmpeg: 这部分指定编译的时候指定程序存放路径,这个路径根据自己
以下在编译过程中传递给编译器和链接器的选项,确保编译器和链接器能找到必要的库和头文件
homebrew安装的会存放在这个地方,M芯片的库放在/opt/homebrew/lib
--extra-cflags="-I/opt/homebrew/include"
--extra-ldflags="-L/opt/homebrew/lib"
--extra-cflags="-I/usr/local/include"
--extra-ldflags="-L/usr/local/lib"
遇到的问题:
ERROR: avisynth/avisynth_c.h avisynth/avs/version.h not found
安装地址:https://github.com/AviSynth/AviSynthPlus/releases
ERROR: libxavs not found
下载文件: https://sourceforge.net/p/xavs/code/HEAD/tree/
解压后:cd ./xavs-code-r55-trunk
Intel结构运行: ./configure --prefix=/usr/local --host=x86_64-darwin --disable-asm
arm架构运行: ./configure --prefix=/usr/local --host=arm-darwin --disable-asm
# 编译失败不管什么情况运行先运行清除
make clean
make && sudo make install
ERROR: lib_amrwbenc not found
安装地址: https://sourceforge.net/projects/opencore-amr/files/vo-amrwbenc/vo-amrwbenc-0.1.3.tar.gz/download
解压后: cd ./vo-amrwbenc-0.1.3
./configure --prefix=/usr/local --disable-shared
make && sudo make install
ERROR: libtwolame not found
brew install two-lame
ERROR: libmysofa not found
git clone https://github.com/hoene/libmysofa.git
cd ./libmysofa/build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF ..
make && sudo make install
ERROR: shine not found using pkg-config
git clone https://github.com/toots/shine.git
cd ./shine
./bootstrap
./configure --prefix=/usr/local --disable-shared
make && sudo make install
ERROR: zvbi-0.2 not found using pkg-config
下载地址: https://sourceforge.net/projects/zapping/files/zvbi/
解压后: cd ./zvbi-0.2.35
./configure --prefix=/usr/local --disable-shared
make && sudo make install
#回到克隆下来的ffmpeg的目录
cd ./ffmpeg
# 根据自己的电脑最大逻辑CPU编译,比如我电脑最大是8
make -j8
sudo make install
# 此时运行成功后,前面配置--prefix=/usr/local/ffmpeg 编译成功后会在/usr/local/ffmpeg找到,剩下全局配置
vim ~/.zshrc
export PATH=${PATH}:/usr/local/ffmpeg/bin
source ~/.zshrc
ffmpeg -version
ffplay xxx.mp4
参考文档: https://segmentfault.com/a/1190000043925577
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。