【FFmpeg】在 Mac OS 中编译 FFmpeg 源码 ② ( 下载 FFmpeg 源码 | 源码编
在上一篇博客 【FFmpeg】在 Mac OS 中编译 FFmpeg 源码 ① ( homebrew 安装 | 通过 gitee 源安装 homebrew | 安装 FFmpeg 编译所需的软件包 ) 中 , 安装了 homebrew , 并利用 homebrew 安装了 编译 FFmpeg 源码需要安装的软件包 , 本篇博客开始下载 FFmpeg 源码并进行编译 ;别的可参考的 FFmpeg 源码编译相关的博客 :
[*]【Android FFMPEG 开发】音视频底子 和 FFMPEG 编译 ( 音视频底子 | MPEG-4 标准 | Android 开发环境 | FFMPEG 交叉编译 | 安卓项目导入设置 )
[*]【Android FFMPEG 开发】FFMPEG 交叉编译设置 ( 下载 | 设置脚本 | 输出路径 | 函数库设置 | 程序设置 | 组件设置 | 编码解码设置 | 交叉编译设置 | 最终脚本 )
编译 FFmpeg 命令总结 :
[*]下载 FFmpeg 代码 : 将代码下载到实行该命令的目次位置下的 ffmpeg4.2 文件中 ;
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg4.2
[*]切换分支 : 进入上述下载后的源码目次 , 切换 remotes/origin/release/4.2 分支 ;
cd ffmpeg4.2
git checkout remotes/origin/release/4.2
[*]编译设置 : 实行 ffmpeg4.2 目次下的源码中的 ./configure 可实行程序 ,
./configure --prefix=/usr/local/ffmpeg4.2 --enable-shared --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --samples=fate-suite --enable-opencl --enable-videotoolbox --enable-ffplay --disable-optimizations --disable-stripping --enable-debug=3 --extra-cflags="-I/opt/homebrew/include" --extra-ldflags="-L/opt/homebrew/lib"
[*]正式编译 : 下面的命令是开启 8 线程编译源码 , 根据自己的 CPU 核数设置 , 4 或者 8 ;
make -j8
[*]安装库文件 : 将源码编译后天生的 可实行程序 和 库文件 安装到本地文件中 ;
sudo make install
[*]设置环境变量 : 利用 vim ~/.bash_profile
命令设置 export PATH="$PATH:/usr/local/ffmpeg4.2/bin" 环境变量 , 然后实行 source ~/.bash_profile
命令 , 更新环境变量 ;
[*]也可以利用 Command + Shift + . 快捷键 , 显示隐藏的文件 , 直接右键打开文本目次进行编辑 ;
一、下载 FFmpeg 源码
1、目次准备
创建一个 ffmpeg 目次 /Users/hsl/001_Project/005_compile/ffmpeg , 在 命令行终端 进入该目次中 , 之后将源码下载到该目次中 ;
https://img-blog.csdnimg.cn/direct/d07e001193a242a3bfbce6fad2f9acdc.png
在该目次中 将会编译 各个版本的 ffmpeg 源码 , 下面的命令都是在该目次中实行的 ;
2、克隆远程代码
实行
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg4.2
命令 , 复制 https://git.ffmpeg.org/ffmpeg.git 地点的 Git 存储库 到 本地的 ffmpeg4.2 目次 ;
https://img-blog.csdnimg.cn/direct/cd3090694fa54a93976775d3fe7ac1fc.png
下载后的 FFmpeg 源码如下图所示 :
https://img-blog.csdnimg.cn/direct/da7ee17451b74d3eafb34a91c78e153a.png
3、查看源码目次
实行
cd ffmpeg4.2
命令 , 进入到上述下载的源码目次中 , 在我的电脑上进入的目次是 /Users/hsl/001_Project/005_compile/ffmpeg/ffmpeg4.2 目次 , 之前的命令都是在 /Users/hsl/001_Project/005_compile/ffmpeg/ 目次中实行的 ;
https://img-blog.csdnimg.cn/direct/5e6153136a1e4148b2ff38acd16c9e20.png
4、切换代码分支
然后 , 切换代码分支 , 实行
git checkout remotes/origin/release/4.2
命令 , 完成分支切换操作 ;
该命令的作用是 切换到名为 release/4.2 的远程分支 , 该分支在 origin 远程堆栈中 ;
https://img-blog.csdnimg.cn/direct/ec8c9fc56450433293a1a2047917152b.png
二、FFmpeg 源码编译设置
1、编译设置命令 ./configure
设置编译设置 , 实行如下命令 , 即可完成 FFmpeg 源码编译设置 ;
./configure --prefix=/usr/local/ffmpeg4.2 --enable-shared --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --samples=fate-suite --enable-opencl --enable-videotoolbox --enable-ffplay --disable-optimizations --disable-stripping --enable-debug=3 --extra-cflags="-I/opt/homebrew/include" --extra-ldflags="-L/opt/homebrew/lib"
输出如下内容 , 说明 源码编译设置乐成 ;
编译设置命令实行详情 , 代码量很多 , 非必要不要展开 ; 该设置命令输出了利用的设置 , 开启了哪些功能 , 哪些编解码器是可用的 , 支持哪些协议 , 支持哪些过滤器 ;
hsl@hanshuliangdeMacBook-Air ffmpeg4.2 % ./configure --prefix=/usr/local/ffmpeg4.2 --enable-shared --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --samples=fate-suite --enable-opencl --enable-videotoolbox --enable-ffplay --disable-optimizations --disable-stripping --enable-debug=3 --extra-cflags="-I/opt/homebrew/include" --extra-ldflags="-L/opt/homebrew/lib"
install prefix /usr/local/ffmpeg4.2source path .C compiler gccC library ARCH aarch64 (generic)big-endian noruntime cpu detection yesNEON enabled yesVFP enabled yesdebug symbols yesstrip symbols nooptimize for size nooptimizations nostatic yesshared yespostprocessing support yesnetwork support yesthreading support pthreadssafe bitstream reader yestexi2html enabled yesperl enabled yespod2man enabled yesmakeinfo enabled nomakeinfo supports HTML noExternal libraries:appkit libass libtheora libxcb lzmaavfoundation libfdk_aac libvorbis libxcb_shape sdl2bzlib libfreetype libvpx libxcb_shm securetransportcoreimage libmp3lame libx264 libxcb_xfixes zlibiconv libopus libx265 libxvidExternal libraries providing hardware acceleration:audiotoolbox opencl videotoolboxLibraries:avcodec avfilter avutil swresampleavdevice avformat postproc swscalePrograms:ffmpeg ffplay ffprobeLicense: nonfree and unredistributablehsl@hanshuliangdeMacBook-Air ffmpeg4.2 %
2、编译设置分析
./configure编译设置 参数分析 :
[*]--prefix=/usr/local/ffmpeg4.2设置 编译后的 库文件 和 可实行程序 , 安装到哪个目次中 ;
[*]--enable-shared 设置 允许动态库编译 , 在 FFmpeg 开发时 ,
[*]优先选择动态库链接 ,
[*]静态库链接很复杂 , 需要手动指定很多库文件 , 和 额外设置 ;
[*]编译后的动态库 , 可以直接在 QT 或者 Visual Studio 中引用 , 进行音视频应用开发 ;
[*]--enable-gpl 设置 启用 GPL ( GNU General Public License ) 许可证支持 , 允许 FFmpeg 利用 GPL 许可证的代码或者库进行编译和链接 ;
[*]--enable-nonfree 设置 启用非自由代码的支持 , 非自由代码 是 受到专利 版权 限制的代码 , 不能自由利用分发 , 启用该选项会利用这些代码进行编译和链接 ;
[*]--samples=fate-suite 设置 指定 编译过程中利用的样例集 , fate-suite 是 FFmpeg 源码中的测试套件 , 包含了音频和视频文件测试功能 , 可测试相关音视频编解码等功能是否精确 ;
[*]--enable-opencl 设置 启用 OpenCL 加速支持 , OpenCL 全称 Open Computing Language , 是一种开放标准 , 允许利用各种不同类型的计算设备 CPU / GPU / FPGA 进行并行计算 , 此处利用该技能进行 视频编解码 / 滤镜处理 运算 , 能明显提高视频处理服从 ;
[*]--enable-videotoolbox 设置 启用 VideoToolbox 加速支持 , 这是 macOS 和 iOS 体系提供的一个框架 , 用于硬件加速视频编解码和处理 , 该参数仅在 Mac 和 iOS 中生效 ;
[*]--disable-optimizations 设置 禁止了优化 , 这样 debug 源码比力方面 , 正式版本 打包时 , 利用优化后的编译版本 , 贸易应用中需要设置一系列的优化参数 ;
[*]--disable-stripping 设置 禁止 在安装时对天生的可实行文件进行剥离 ; 编译时剥离操作会去除可实行文件中的调试符号和其他不必要的信息 , 可减小文件大小并提高实行速度 ; 禁止剥离操作会增加文件大小和降低实行速度 ;
[*]--enable-debug=3设置 启用 最高级别的调试信息 ;
[*]--extra-cflags="-I/opt/homebrew/include" 设置 用于指定 依赖的第三方库的头文件目次 ;
[*]--extra-ldflags="-L/opt/homebrew/lib" 设置 用于指定依赖的第三方库的库文件目次 ;
./configure
--prefix=/usr/local/ffmpeg4.2 // 配置编译后的程序和库安装的目录
--enable-shared // 允许动态库编译
--enable-gpl // 启用 GPL 协议
--enable-nonfree // 启用非自由代码
--enable-libass // 启用 libass 字幕渲染
--enable-libfdk-aac // 启用 libfdk-aac AAC 编解码
--enable-libfreetype // 启用 libfreetype 字体渲染
--enable-libmp3lame // 启用 libmp3lame MP3 编解码
--enable-libtheora // 启用 libtheora Theora 编解码
--enable-libvorbis // 启用 libvorbis Vorbis 编解码
--enable-libvpx // 启用 libvpx VP8/VP9 编解码
--enable-libx264 // 启用 libx264 H.264 编解码
--enable-libx265 // 启用 libx265 H.265 编解码
--enable-libopus // 启用 libopus Opus 编解码
--enable-libxvid // 启用 libxvid Xvid 编解码
--samples=fate-suite // 设置样例为 fate-suite
--enable-opencl // 启用 OpenCL 加速
--enable-videotoolbox // 启用 VideoToolbox 加速支持
--enable-ffplay // 启用 ffplay 播放器
--disable-optimizations // 禁用 优化
--disable-stripping // 禁用 剥离
--enable-debug=3 // 启用最高级别的调试信息
--extra-cflags="-I/opt/homebrew/include" // 指定依赖的第三方库的头文件目录
--extra-ldflags="-L/opt/homebrew/lib" // 指定依赖的第三方库的库文件目录
三、FFmpeg 源码编译
1、编译源码
实行
make -j4
命令 , 开始进行编译 ; -j4 参数指的是开启 4 个线程进行编译 ;
https://img-blog.csdnimg.cn/direct/5605b009a40449689796e4d417685132.png
输出如下内容 , 编译完成 ;
https://img-blog.csdnimg.cn/direct/979343da9119472a9338d2b1821d9b92.png
2、安装编译后的 FFmpeg 程序
实行
sudo make install
命令 , 安装 FFmpeg 到本地体系中 ;
https://img-blog.csdnimg.cn/direct/9e0493a9d52b400caeafd77b98386f49.png
3、设置环境变量
实行
vim ~/.bash_profile
命令 , 利用 vim 编辑器 编辑 ~/.bash_profile 环境变量文件 , 上述编译的 FFmpeg 源码的编译后的命令行工具 , 函数库 , 安装到了 /usr/local/ffmpeg4.2/bin 目次中 , 将该目次设置到 环境变量 中 ;
https://img-blog.csdnimg.cn/direct/154e605f8de843b89aa554add4838d14.png
查看环境变量文件 ;
https://img-blog.csdnimg.cn/direct/b90460891d084e1ca76eb5b77e18769f.png
实行
source ~/.bash_profile
命令 , 更新 环境变量文件 ;
https://img-blog.csdnimg.cn/direct/14b0603637d247e6b0eed15554465800.png
4、验证 FFmpeg 版本号
此时在 Mac 中 , 可以实行
ffmpeg -version
命令 , 可查看当前 FFmpeg 命令 ;
https://img-blog.csdnimg.cn/direct/bb209e9be4d3439b948324f523fa0f9b.png
四、编译结果查看
1、安装 tree 命令行工具
实行
brew install tree
命令 , 安装 tree 命令行工具 ;
https://img-blog.csdnimg.cn/direct/c8343abcef69428d916d49d05138c27e.png
2、FFmpeg 编译输出内容 - 可实行程序 / 共享库 / 头文件
FFmpeg 编译后 , 会输出 可实行文件 , 共享库 , 头文件 三种内容 ;
[*]编译后的 输出目次 为 /usr/local/ffmpeg4.2/ ;
[*]可实行文件 在输出目次的 bin 目次下 , /usr/local/ffmpeg4.2/bin ;
[*]共享库 在输出目次的 lib 目次下 , /usr/local/ffmpeg4.2/lib ;
[*]头文件 在输出目次的 include 目次下 , /usr/local/ffmpeg4.2/include ;
3、查看编译结果目次
之前编译时设置了 --prefix=/usr/local/ffmpeg4.2设置 , 编译结果 库文件 和 可实行程序 输出目次为 /usr/local/ffmpeg4.2 ;
实行
tree /usr/local/ffmpeg4.2
命令 , 可查看 /usr/local/ffmpeg4.2 目次中的 文件和目次布局 ;
命令行输入结果如下 : 代码较多 , 这是 mac 编译 FFmpeg 后的完整输出代码 ;
hsl@hanshuliangdeMacBook-Air ffmpeg4.2 % pwd/usr/local/ffmpeg4.2hsl@hanshuliangdeMacBook-Air ffmpeg4.2 % tree /usr/local/ffmpeg4.2
/usr/local/ffmpeg4.2├── bin│ ├── ffmpeg│ ├── ffplay│ └── ffprobe├── include│ ├── libavcodec│ │ ├── ac3_parser.h│ │ ├── adts_parser.h│ │ ├── avcodec.h│ │ ├── avdct.h│ │ ├── avfft.h│ │ ├── d3d11va.h│ │ ├── dirac.h│ │ ├── dv_profile.h│ │ ├── dxva2.h│ │ ├── jni.h│ │ ├── mediacodec.h│ │ ├── qsv.h│ │ ├── vaapi.h│ │ ├── vdpau.h│ │ ├── version.h│ │ ├── videotoolbox.h│ │ ├── vorbis_parser.h│ │ └── xvmc.h│ ├── libavdevice│ │ ├── avdevice.h│ │ └── version.h│ ├── libavfilter│ │ ├── avfilter.h│ │ ├── buffersink.h│ │ ├── buffersrc.h│ │ └── version.h│ ├── libavformat│ │ ├── avformat.h│ │ ├── avio.h│ │ └── version.h│ ├── libavutil│ │ ├── adler32.h│ │ ├── aes.h│ │ ├── aes_ctr.h│ │ ├── attributes.h│ │ ├── audio_fifo.h│ │ ├── avassert.h│ │ ├── avconfig.h│ │ ├── avstring.h│ │ ├── avutil.h│ │ ├── base64.h│ │ ├── blowfish.h│ │ ├── bprint.h│ │ ├── bswap.h│ │ ├── buffer.h│ │ ├── camellia.h│ │ ├── cast5.h│ │ ├── channel_layout.h│ │ ├── common.h│ │ ├── cpu.h│ │ ├── crc.h│ │ ├── des.h│ │ ├── dict.h│ │ ├── display.h│ │ ├── downmix_info.h│ │ ├── encryption_info.h│ │ ├── error.h│ │ ├── eval.h│ │ ├── ffversion.h│ │ ├── fifo.h│ │ ├── file.h│ │ ├── frame.h│ │ ├── hash.h│ │ ├── hdr_dynamic_metadata.h│ │ ├── hmac.h│ │ ├── hwcontext.h│ │ ├── hwcontext_cuda.h│ │ ├── hwcontext_d3d11va.h│ │ ├── hwcontext_drm.h│ │ ├── hwcontext_dxva2.h│ │ ├── hwcontext_mediacodec.h│ │ ├── hwcontext_qsv.h│ │ ├── hwcontext_vaapi.h│ │ ├── hwcontext_vdpau.h│ │ ├── hwcontext_videotoolbox.h│ │ ├── imgutils.h│ │ ├── intfloat.h│ │ ├── intreadwrite.h│ │ ├── lfg.h│ │ ├── log.h│ │ ├── lzo.h│ │ ├── macros.h│ │ ├── mastering_display_metadata.h│ │ ├── mathematics.h│ │ ├── md5.h│ │ ├── mem.h│ │ ├── motion_vector.h│ │ ├── murmur3.h│ │ ├── opt.h│ │ ├── parseutils.h│ │ ├── pixdesc.h│ │ ├── pixelutils.h│ │ ├── pixfmt.h│ │ ├── random_seed.h│ │ ├── rational.h│ │ ├── rc4.h│ │ ├── replaygain.h│ │ ├── ripemd.h│ │ ├── samplefmt.h│ │ ├── sha.h│ │ ├── sha512.h│ │ ├── spherical.h│ │ ├── stereo3d.h│ │ ├── tea.h│ │ ├── threadmessage.h│ │ ├── time.h│ │ ├── timecode.h│ │ ├── timestamp.h│ │ ├── tree.h│ │ ├── twofish.h│ │ ├── tx.h│ │ ├── version.h│ │ └── xtea.h│ ├── libpostproc│ │ ├── postprocess.h│ │ └── version.h│ ├── libswresample│ │ ├── swresample.h│ │ └── version.h│ └── libswscale│ ├── swscale.h│ └── version.h├── lib│ ├── libavcodec.58.54.100.dylib│ ├── libavcodec.58.dylib -> libavcodec.58.54.100.dylib│ ├── libavcodec.a│ ├── libavcodec.dylib -> libavcodec.58.54.100.dylib│ ├── libavdevice.58.8.100.dylib│ ├── libavdevice.58.dylib -> libavdevice.58.8.100.dylib│ ├── libavdevice.a│ ├── libavdevice.dylib -> libavdevice.58.8.100.dylib│ ├── libavfilter.7.57.100.dylib│ ├── libavfilter.7.dylib -> libavfilter.7.57.100.dylib│ ├── libavfilter.a│ ├── libavfilter.dylib -> libavfilter.7.57.100.dylib│ ├── libavformat.58.29.100.dylib│ ├── libavformat.58.dylib -> libavformat.58.29.100.dylib│ ├── libavformat.a│ ├── libavformat.dylib -> libavformat.58.29.100.dylib│ ├── libavutil.56.31.100.dylib│ ├── libavutil.56.dylib -> libavutil.56.31.100.dylib│ ├── libavutil.a│ ├── libavutil.dylib -> libavutil.56.31.100.dylib│ ├── libpostproc.55.5.100.dylib│ ├── libpostproc.55.dylib -> libpostproc.55.5.100.dylib│ ├── libpostproc.a│ ├── libpostproc.dylib -> libpostproc.55.5.100.dylib│ ├── libswresample.3.5.100.dylib│ ├── libswresample.3.dylib -> libswresample.3.5.100.dylib│ ├── libswresample.a│ ├── libswresample.dylib -> libswresample.3.5.100.dylib│ ├── libswscale.5.5.100.dylib│ ├── libswscale.5.dylib -> libswscale.5.5.100.dylib│ ├── libswscale.a│ ├── libswscale.dylib -> libswscale.5.5.100.dylib│ └── pkgconfig│ ├── libavcodec.pc│ ├── libavdevice.pc│ ├── libavfilter.pc│ ├── libavformat.pc│ ├── libavutil.pc│ ├── libpostproc.pc│ ├── libswresample.pc│ └── libswscale.pc└── share ├── doc │ └── ffmpeg │ ├── developer.html │ ├── faq.html │ ├── fate.html │ ├── ffmpeg-all.html │ ├── ffmpeg-bitstream-filters.html │ ├── ffmpeg-codecs.html │ ├── ffmpeg-devices.html │ ├── ffmpeg-filters.html │ ├── ffmpeg-formats.html │ ├── ffmpeg-protocols.html │ ├── ffmpeg-resampler.html │ ├── ffmpeg-scaler.html │ ├── ffmpeg-utils.html │ ├── ffmpeg.html │ ├── ffplay-all.html │ ├── ffplay.html │ ├── ffprobe-all.html │ ├── ffprobe.html │ ├── general.html │ ├── git-howto.html │ ├── libavcodec.html │ ├── libavdevice.html │ ├── libavfilter.html │ ├── libavformat.html │ ├── libavutil.html │ ├── libswresample.html │ ├── libswscale.html │ ├── mailing-list-faq.html │ ├── nut.html │ └── platform.html ├── ffmpeg │ ├── examples │ │ ├── Makefile │ │ ├── README │ │ ├── avio_dir_cmd.c │ │ ├── avio_reading.c │ │ ├── decode_audio.c │ │ ├── decode_video.c │ │ ├── demuxing_decoding.c │ │ ├── encode_audio.c │ │ ├── encode_video.c │ │ ├── extract_mvs.c │ │ ├── filter_audio.c │ │ ├── filtering_audio.c │ │ ├── filtering_video.c │ │ ├── http_multiclient.c │ │ ├── hw_decode.c │ │ ├── metadata.c │ │ ├── muxing.c │ │ ├── qsvdec.c │ │ ├── remuxing.c │ │ ├── resampling_audio.c │ │ ├── scaling_video.c │ │ ├── transcode_aac.c │ │ ├── transcoding.c │ │ ├── vaapi_encode.c │ │ └── vaapi_transcode.c │ ├── ffprobe.xsd │ ├── libvpx-1080p.ffpreset │ ├── libvpx-1080p50_60.ffpreset │ ├── libvpx-360p.ffpreset │ ├── libvpx-720p.ffpreset │ └── libvpx-720p50_60.ffpreset └── man ├── man1 │ ├── ffmpeg-all.1 │ ├── ffmpeg-bitstream-filters.1 │ ├── ffmpeg-codecs.1 │ ├── ffmpeg-devices.1 │ ├── ffmpeg-filters.1 │ ├── ffmpeg-formats.1 │ ├── ffmpeg-protocols.1 │ ├── ffmpeg-resampler.1 │ ├── ffmpeg-scaler.1 │ ├── ffmpeg-utils.1 │ ├── ffmpeg.1 │ ├── ffplay-all.1 │ ├── ffplay.1 │ ├── ffprobe-all.1 │ └── ffprobe.1 └── man3 ├── libavcodec.3 ├── libavdevice.3 ├── libavfilter.3 ├── libavformat.3 ├── libavutil.3 ├── libswresample.3 └── libswscale.321 directories, 241 fileshsl@hanshuliangdeMacBook-Air ffmpeg4.2 %
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]