CentOS编译FFmpeg

前言

        FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的。下面编译安装对应几个重要类库。

一、编译安装

安装依赖项

yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make pkgconfig zlib-devel

NASM

一些库使用的汇编程序。强烈推荐或者您的结果构建可能非常慢

wget --no-check-certificate https://www.nasm.us/pub/nasm/releasebuilds/2.15/nasm-2.15.tar.gz
tar -xvf nasm-2.15.tar.gz
cd nasm-2.15/
./configure
make && sudo make install

Yasm

一些库使用的汇编程序。强烈推荐或者您的结果构建可能非常慢。

wegt http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make && sudo make install

libx264

H. 264视频编码器。有关更多信息和使用示例,请参阅H. 264编码指南

要求将 ffmpeg 配置为 --enable-gpl --enable-libx264.

git clone --branch stable --depth 1 https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-shared --enable-static
make && make install

libx265

H. 265/HEVC 视频编码器。有关更多信息和使用示例,请参阅H.265编码指南

要求将 ffmpeg 配置为 --enable-gpl --enable-libx265.

git clone --branch stable --depth 2 https://bitbucket.org/multicoreware/x265_git
cd x265
./configure --enable-shared --enable-static
make
make install

libfdk_aac

AAC 音频编码器。有关更多信息和使用示例,请参阅AAC 音频编码指南

要求将 ffmpeg 配置为 --enable-libfdk_aac (and --enable-nonfree if you also included --enable-gpl).

git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --disable-shared
make
make install

libmp3lame

MP3音频编码器。

要求将 ffmpeg 配置为 --enable-libmp3lame.

curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure --disable-shared
make
make install

libopus

Opus音频解码器和编码器。

要求将 ffmpeg 配置为 --enable-libopus.

curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure --disable-shared
make
make install

libvpx

VP8/VP9视频编码器和解码器。更多信息和使用实例,请参见VP9视频编码指南

 要求将 ffmpeg 配置为 --enable-libvpx.

git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make
make install

FFmpeg

wget http://www.ffmpeg.org/releases/ffmpeg-5.1.tar.gz
tar -zxvf ffmpeg-5.1.tar.gz
cd ffmpeg
./configure \
--prefix="/usr/local/ffmpeg" \
--pkg-config-flags="--static" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--enable-gpl \
--enable-libfdk_aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree
make
make install

参数详解:

用法:配置[选项] 选项:[描述后括号中的默认值]

--prefix="/usr/local/ffmpeg"  安装程序到指定目录 [/usr/local]

--pkg-config-flags="--static"  将附加标志传递给pkgconf []

--extra-cflags="-I/usr/local/include"  将"-I/usr/local/include" 添加到CFLAGS []

--extra-ldflags="-L/usr/local/lib"  将"-I/usr/local/include" 添加到LDFLAGS []

--extra-libs=-lpthread   添加 ELIBS []

--extra-libs=-lm  添加 ELIBS []

--enable-gpl  允许使用GPL代码,生成的库和二进制文件将在GPL下 [no]

--enable-libfreetype  启用libfreetype,drawtext过滤器需要 [no]

--enable-libx264  通过x264启用H.264编码 [no]

--enable-libx265  通过x265启用HEVC编码 [no]

--enable-nonfree  允许使用非自由代码,生成的库和二进制文件将是不可分发的 [no]

--extra-libs=-ldl  添加 ELIBS []

--enable-pic 构建与位置无关的代码

配置系统变量

# 新增动态库地址
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig # 刷新动态库

# 在最后PATH添加环境变量
vi /etc/profile
export PATH=$PATH:/usr/local/ffmpeg/bin

# 设置生效
source /etc/profile

备注:ldconfig是一个动态链接库管理命令,此命令可以让动态链接库为系统所共享。 主要用途是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件(/etc/ld.so.conf)内所列的目录下,搜索出可共享的动态链接库(格式lib*.so*),并创建出动态装入程序(ld.so)所需的连接和缓存文件。

查看版本

[root@localhost ~]# ffmpeg -version
ffmpeg version 5.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --prefix=/usr/local/ffmpeg --pkg-config-flags=--static --extra-libs=-lpthread --extra-libs=-lm --enable-gpl --enable-libfreetype --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil      57. 28.100 / 57. 28.100
libavcodec     59. 37.100 / 59. 37.100
libavformat    59. 27.100 / 59. 27.100
libavdevice    59.  7.100 / 59.  7.100
libavfilter     8. 44.100 /  8. 44.100
libswscale      6.  7.100 /  6.  7.100
libswresample   4.  7.100 /  4.  7.100
libpostproc    56.  6.100 / 56.  6.100
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值