美文网首页
FFmpeg学习笔记1.FFmpeg在mac上编译

FFmpeg学习笔记1.FFmpeg在mac上编译

作者: samonking | 来源:发表于2022-06-10 08:26 被阅读0次

Mac 编译 FFmpeg

编译出 ffmpeg、ffprobe、ffplay 三个命令行工具

只产生动态库,不产生静态库

将 fdk-aac、x264、x265 集成到 FFmpeg 中

2、源码下载

下载Fffmpeg-4.3.2.tar.xz源码

源码地址: https://github.com/FFmpeg/FFmpeg

3、编译

3.1 依赖项

brew install yasm

ffmpeg的编译过程依赖yasm

若未安装yasm会出现错误:nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

brew install sdl2

ffplay 依赖于 sdl2

如果缺少sdl2,就无法编译出ffplay

brew install fdk-aac

不然会出现错误:ERROR: libfdk_aac not found

brew install x264

不然会出现错误:ERROR: libx264 not found

x264 地址 有可能因为外网原因安装包错,自行下载x264源码然后进行编译

brew install x265

不然会出现错误:ERROR: libx265 not found

其实x264、x265、sdl2都在曾经执行brew install ffmpeg的时候安装过了

可以通过brew list的结果查看是否安装过

brew list | grep fdk

brew list | grep x26

brew list | grep -E 'fdk|x26'

如果已经安装过,可以不用再执行brew install

3.2 configure

首先进入源码目录

shuidianfeishuidianfeishifoushi:ffmpeg jinlei$ 

然后执行源码目录下的 configure 脚本,设置一些编译参数,做一些编译前的准备工作。

./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

将 x265 内置到 FFmpeg 中

--enable-gpl

x264、x265 要求开启GPL License

--enable-nonfree

fdk-aac与GPL不兼容,需要通过开启nonfree进行配置

你可以通过 configure --help 命令查看每一个配置项的作用。

./configure--help|grepstatic# 

结果如下所示--disable-staticdonot buildstaticlibraries[no]

3.3 编译

接下来开始解析源代码目录中的 Makefile 文件,进行编译。-j8 表示允许同时执行8个编译任务。

make-j8

3.3.1 关于Makefile

Makefile描述了整个项目的编译和链接等规则

比如哪些文件需要编译?哪些文件不需要编译?哪些文件需要先编译?哪些文件需要后编译?等等

Makefile可以使项目的编译变得自动化,不需要每次都手动输入一堆源文件和参数

比如原来需要这么写:gcc test1.c test2.c test3.c -o test

3.4 安装

将编译好的库安装到指定的位置:/usr/local/ffmpeg

makeinstall

3.5 配置 PATH

为了让 bin 目录中的 ffmpeg、ffprobe、ffplay 在任意位置都能够使用,需要先将 bin 目录配置到环境变量 PATH 中

# 编辑.bash_profile

vim ~/.bash_profile

# .bash_profile文件中写入以下内容

export PATH=/usr/local/ffmpeg/bin:$PATH

# 让.bash_profile生效

source ~/.bash_profile

3.6 验证

在命令行上输入 ffmpeg -version 进行验证

shuidianfeishuidianfeishifoushi:ffmpeg jinlei$ ffmpeg -version

ffmpeg version N-107056-g93505a9095 Copyright (c) 2000-2022 the FFmpeg developers

built with Apple LLVM version 9.0.0 (clang-900.0.39.2)

configuration: --prefix=/usr/local/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265

libavutil      57. 26.100 / 57. 26.100

libavcodec    59. 33.100 / 59. 33.100

libavformat    59. 24.100 / 59. 24.100

libavdevice    59.  6.100 / 59.  6.100

libavfilter    8. 40.100 /  8. 40.100

libswscale      6.  6.100 /  6.  6.100

libswresample  4.  6.100 /  4.  6.100

libpostproc    56.  5.100 / 56.  5.100

相关文章

网友评论

      本文标题:FFmpeg学习笔记1.FFmpeg在mac上编译

      本文链接:https://www.haomeiwen.com/subject/pgcvmrtx.html