Red Hat (Centos7) 下安装最新 FFmpeg

Red Hat (Centos7) 下安装最新 ffmpeg

FFmpeg既是一款音视频编解码工具,同时也是一组音视频编解码开发套件,作为编解码开发套件,它为开发者提供了丰富的音视频处理的调用接口。
FFmpeg提供了多种媒体格式的封装和解封装,包括多种音视频编码、多种协议的流媒体、多种色彩格式的转换、多种采样率的转换、多种码率转换等;FFmpeg框架提供了多种丰富的插件模块,包含封装与解封装的插件、编码与解码的插件等。
[root@ip-172-31-32-39 ec2-user]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.3 (Ootpa)

1、Red Hat 下安装最新 ffmpeg

wget http://www.ffmpeg.org/releases/ffmpeg-4.3.2.tar.gz
tar -zxvf ffmpeg-4.3.2.tar.gz
cd ffmpeg-4.3.2
[root@ip-172-31-32-39 ffmpeg-4.3.2]# ./configure --prefix=/usr/local/ffmpeg
gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

报错缺少gcc,安装一下

yum install gcc*
装完之后再执行编译前检查:
意料之中出现未安装 yasm 汇编编译器的报错
[root@ip-172-31-32-39 ffmpeg-4.3.2]# ./configure --prefix=/usr/local/ffmpeg
nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

2、安装 yasm 汇编编译器
yasm

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzf yasm-1.3.0.tar.gz 
cd yasm-1.3.0
./configure --prefix=/usr/local/
make
make install
cd /usr/local/bin/
[root@ip-172-31-32-39 bin]# ./yasm --version
yasm 1.3.0
Compiled on Sep  2 2021.
Copyright (c) 2001-2014 Peter Johnson and other Yasm developers.
Run yasm --license for licensing overview and summary.

3、加环境配置文件后再次编译ffmpeg

# tail -3 /etc/profile
##
export PATH=/usr/local/bin:$PATH
# source /etc/profile

#验证yasm命令

[root@ip-172-31-32-39 ffmpeg-4.3.2]# yasm 
yasm: No input files specified

#重新编译

./configure --prefix=/usr/local/ffmpeg
make
make install

#验证ffmpeg

# cd /usr/local/
# ls
bin  etc  ffmpeg  games  include  lib  lib64  libexec  sbin  share  src
# cd ffmpeg/
# ls
bin  include  lib  share
# cd bin/
# ls
ffmpeg  ffprobe
[root@ip-172-31-32-39 bin]# ./ffmpeg -version
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/usr/local/ffmpeg
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

4、拓展
上面只是简单的安装,FFmpeg本身支持一些音视频编码格式、文件封装格式与流媒体传输协议,但是支持的数量有限,FFmpeg所做的只是提供一套基础的框架,所有的编码格式、文件封装格式与流媒体协议均可以作为FFmpeg的一个模块挂载在FFmpeg框架中。这些模块以第三方的外部库的方式提供支持,可以通过FFmpeg源码的configure命令查看FFmpeg所支持的音视频编码格式、文件封装格式与流媒体传输协议,对于FFmpeg不支持的格式,可以通过configure --help查看的第三方外部库,然后通过增加对应的编译参数选项进行支持。

例如需要自己配置FFmpeg支持哪些格式,比如仅支持H.264视频与AAC音频编码,可以调整配置项将其简化如下:

./configure --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree --prefix=/usr/local/ffmpeg

报错:

ERROR: libfdk_aac not found

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

fdk-acc下载

wget https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.2.tar.gz
tar xzf  fdk-aac-2.0.2.tar.gz
cd fdk-aac-2.0.2
./configure  --prefix=/usr/local/
make
make install

再次编译检查./configure --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree --prefix=/usr/local/ffmpeg
报错:

ERROR: libx264 not found

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

libx264 下载:
x264

# https://code.videolan.org/videolan/x264
 
# 建议下载稳定版
# https://code.videolan.org/videolan/x264/-/tree/stable
 
# 其他版本
# https://ftp.videolan.org/pub/x264/snapshots/
#git clone https://code.videolan.org/videolan/x264.git

wget http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20191217-2245-stable.tar.bz2
tar xjf x264-snapshot-20191217-2245-stable.tar.bz2
cd x264-snapshot-20191217-2245-stable
./configure --prefix=/usr/local --enable-shared --enable-static --disable-asm
make
make install

vim /etc/profile //文件末尾加入下面内容

export PATH=/usr/local/x264/bin:$PATH
export PATH=/usr/local/x264/include:$PATH
export PATH=/usr/local/x264/lib:$PATH

vim /etc/ld.so.conf //增加以下内容
/usr/local/x264/lib //添加x264库路径,添加完保存退出

# ldconfig //使配置生效

vim /etc/ld.so.conf //增加以下内容
/usr/local/ffmpeg/lib //添加ffmpeg库路径,添加完保存退出
ldconfig //使配置生效

使用方法:在./configure之前输入
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH //(此路径为.pc文件所在路径),可使用
echo $PKG_CONFIG_PATH //查看有没设置生效

再次执行编译检查

./configure --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree --prefix=/usr/local/ffmpeg
make
make install

验证

[root@ip-172-31-32-39 bin]# ./ffmpeg --version
./ffmpeg: error while loading shared libraries: libfdk-aac.so.2: cannot open shared object file: No such file or directory

报错了,但是这个文件是有的

[root@ip-172-31-32-39 bin]# find / -name libfdk-aac.so*
/usr/local/lib/libfdk-aac.so.2.0.2
/usr/local/lib/libfdk-aac.so.2
/usr/local/lib/libfdk-aac.so
/data/fdk-aac-2.0.2/.libs/libfdk-aac.so.2.0.2
/data/fdk-aac-2.0.2/.libs/libfdk-aac.so.2
/data/fdk-aac-2.0.2/.libs/libfdk-aac.so
在/etc/profile添加一行,整体如下(包含上面添加的)
##
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/lib/:$PATH
export PATH=/usr/local/x264/bin:$PATH
export PATH=/usr/local/x264/include:$PATH
export PATH=/usr/local/x264/lib:$PATH
source /etc/profile

在/etc/ld.so.conf添加一行,整体如下(包含上面添加的)

vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/x264/lib
/usr/local/ffmpeg/lib
/usr/local/lib
# ldconfig   # 加载/etc/ld.so.conf
[root@ip-172-31-32-39 bin]# ./ffmpeg -version
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree --prefix=/usr/local/ffmpeg
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

可以阅读下如下几篇:
https://www.jianshu.com/p/3641c2ade359
https://blog.csdn.net/sunxiaopengsun/article/details/53925647
https://blog.csdn.net/qq_41678939/article/details/106611111
https://blog.csdn.net/smily77369/article/details/114926723?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_title~default-0.control&spm=1001.2101.3001.4242
https://blog.csdn.net/weixin_42499899/article/details/116727219?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_title~default-1.control&spm=1001.2101.3001.4242
可以按照以下网址联网下载最新版本或者使用安装包里面的软件

yasm
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

x264
wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2

fdk-acc
wget http://sourceforge.net/projects/opencore-amr/files/fdk-aac/

ame
wget http://ufpr.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz

opus
wget http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz

ogg
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz

vorbis
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz

libvpx
wget git clone https://github.com/webmproject/libvpx.git

xvidcore
wget http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.gz

libtheora
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值