1.背景
因为通过brew install ffmpeg安装的ffmpeg不包含libsdk_aac 的编解码器,而我需要通过ffmpeg来进行libsdk_aac 的编解码,所以我需要自己手动编译ffmpeg
homebrew 安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
ffmpeg brew 方式安装
brew install ffmpeg
如果需要安装最新的版本的话
brew install ffmpeg --HEAD
更新ffmpeg
brew update && brew upgrade ffmpeg
2.实现目标
- 编译出常用的三个命令行ffmpeg,ffprobe,ffplay
- 只产生动态库,不产生静态库
- 将fdk-aac、x264、x265功能集成到FFmpeg
源码下载
目前最新版本是ffmpeg-4.3.2.tar.xz,这里我们就是用这个版本来进行操作
3.自己手动编译ffmpeg
3.1 依赖安装
Xcode 安装(Mac 平台)
Xcode 下载链接
安装xcode之后,安装components
xcode-select --install
安装ffmpeg编译的依赖项
brew install automake fdk-aac git lame libass libtool libvorbis libvpx \
opus sdl shtool texi2html theora wget x264 x265 xvid nasm
可以通过brew list 查看是否安装过相关依赖,如果已经安装过,可以不需要执行brew install
···
brew list | grep fdk
brew list | grep x26
brew list | grep -E 'fdk|x26'
···
-
x264 encodes H.264 video. Use
--enable-gpl --enable-libx264
. -
fdk-aac encodes AAC audio. Use
--enable-libfdk-aac
. -
libvpx is a VP8 and VP9 encoder. Use
--enable-libvpx
. -
libvorbis encodes Vorbis audio . Requires libogg. Use
--enable-libvorbis
. - libopus encodes Opus audio.
-
LAME encodes MP3 audio. Use
--enable-libmp3lame
. -
libass is a subtitle renderer. Use
--enable-libass
.
3.2 编译Compilling
- configure
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --prefix=/usr/local/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265
参数解释
- --prefix:用以指定编译好的FFmpeg安装到哪个目录,一般放到/usr/local/ffmpeg中
- --enable-shared,生成动态库
- --disable-static 不生成静态库
- --enable-libfdk-aac 将fdk-aac内置到FFmpeg中
- --enable-libx264 将x264内置到FFmpeg中
- --enable-libx265
- --enable-gpl x264、x265要求开启GPL License
- --enable-nonfree fdk-aac与GPL不兼容,需要通过开启nonfree进行配置
可以通过configure --help命令查看每一个配置项的作用。
- make
make -j8
Makefile描述了整个项目的编译和链接等规则
比如哪些文件需要编译?哪些文件不需要编译?哪些文件需要先编译?哪些文件需要后编译?等等
Makefile可以使项目的编译变得自动化,不需要每次都手动输入一堆源文件和参数
比如原来需要这么写:gcc test1.c test2.c test3.c -o test
- install
make install
将编译好的库安装到指定的位置:/usr/local/ffmpeg。
3.3 配置环境变量
songlin@feng-sl ~ master ±✚ cat .bashrc
alias sed=gsed
alias list="size -l -m -x"
export PATH=/usr/local/ffmpeg/bin:$PATH
3.4 测试验证
未生效环境变量
songlin@feng-sl ~ master ±✚ ffmpeg -version
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
生效环境变量
✘ songlin@feng-sl ~ master ±✚ ffmpeg -version
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
songlin@feng-sl ~/audio/aac master ±✚ ffmpeg -codecs | grep aac
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
DEAIL. aac AAC (Advanced Audio Coding) (decoders: aac aac_fixed aac_at libfdk_aac ) (encoders: aac aac_at libfdk_aac )
D.AIL. aac_latm AAC LATM (Advanced Audio Coding LATM syntax)
从终端来看,可以看到结果是成功的了
网友评论