本篇介绍的是Mac安装FFmpeg的教程,该教程是为进行音视频的开发学习作准备的,很多时间必要看源码调试学习,若只为了认识使用ffmpeg、ffplay、ffprobe等下令,建议直接使用brew install ffmpeg安装稳定版本。
一、安装Homebrew
Homebrew是MacOS(或 Linux)的软件包管理器,可以说是神器了。用于软件包的安装、更新、卸载、搜刮等等。
- #需要梯子
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
复制代码 没有梯子的使用国内,可以参考一下其他博客的方法,由于要编译ffmpeg会装比较多的库,推荐用国内镜像
二、安装FFmpeg
这里并没有直接使用brew install ffmpeg 安装是由于后续想用源码调试。
1.官网下载
2.使用git安装
使用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
- 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
复制代码 3. 编译
- #回到克隆下来的ffmpeg的目录
- cd ./ffmpeg
- # 根据自己的电脑最大逻辑CPU编译,比如我电脑最大是8
- make -j8
- sudo make install
- # 此时运行成功后,前面配置--prefix=/usr/local/ffmpeg 编译成功后会在/usr/local/ffmpeg找到,剩下全局配置
复制代码 4.全局配置
- vim ~/.zshrc
- export PATH=${PATH}:/usr/local/ffmpeg/bin
- source ~/.zshrc
复制代码 5.检验
参考文档: https://segmentfault.com/a/1190000043925577
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |