一、安装nasm
- 下载nasm软件包
wget https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.gz
- 解压并安装
tar -xvf nasm-2.13.03.tar.gz
cd nasm-2.13.03/
./configure
make && sudo make install
- 若make报如下错误,可能是gcc版本过高导致
./include/nasmlib.h:194:1: error: ‘pure’ attribute on function returning ‘void’ [-Werror=attributes] 194 | void pure_func seg_init(void);
解决方案:
修改“./include/nasmlib.h”文件
vim ./include/nasmlib.h (大概193行,找到语句)
注释掉该行:void pure_func seg_init(void);
- 验证是否已安装
nasm -version
[root@x nasm-2.13.03]# nasm -version
NASM version 2.13.03 compiled on Aug 30 2022
二、安装yasm
- 下载yasm软件包
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
- 解压并安装
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make && sudo make install
- 验证是否已安装
[root@xyasm-1.3.0]# yasm --version
yasm 1.3.0
Compiled on Aug 30 2022.
Copyright (c) 2001-2014 Peter Johnson and other Yasm developers.
Run yasm --license for licensing overview and summary.
三、安装x264
-
下载x264
通过git:
git clone https://code.videolan.org/videolan/x264.git
(或)访问官网:
https://www.videolan.org/developers/x264.html
-
安装
cd x264/
./configure --enable-shared --enable-static
make && sudo make install
- 验证是否已安装
[root@x x264]# x264 --version
x264 0.164.3095 baee400
built on Aug 30 2022, gcc: 4.8.5 20150623 (Red Hat 4.8.5-44)
x264 configuration: --chroma-format=all
libx264 configuration: --chroma-format=all
x264 license: GPL version 2 or later
四、安装pkg
- 先检查是否已安装pkg,已安装则跳过
[root@x home]# pkg-config --version
0.27.1
- 下载pkg软件包
wet https://pkg-config.freedesktop.org/releases/pkg-config-0.27.1.tar.gz
tar -zxvf pkg-config-0.27.1.tar.gz
cd pkg-config-0.27.1
- 编译
./configure
make
make check
make install
- 验证是否已安装 (同最初命令)
pkg-config --version
0.27.1
五、安装ffmpeg
- 安装gcc编译器等组件
yum -y install gcc automake autoconf libtool make openssl openssl-devel
-
下载ffmpeg
5.0.1版本,快速下载
wget http://ffmpeg.org/releases/ffmpeg-5.0.1.tar.xz
(或)访问官网选择任意版本
http://ffmpeg.org/download.html#releases
-
解压
tar -xvJf ffmpeg-5.0.1.tar.xz
mv ffmpeg-5.0.1/ /usr/local/ffmpeg/
- 配置ffmpeg(遇到无法下载https链接时,新增 --enable-openssl --enable-nonfree)
若openssl version存在但提示 ERROR: openssl not found
继续安装 yum install openssl openssl-devel -y
cd /usr/local/ffmpeg
支持http使用:
./configure --enable-gpl --enable-libx264 --enable-static --disable-shared --enable-encoder=libx264 --extra-libs=-ldl
同时支持https则使用:
./configure –enable-openssl --enable-gpl --enable-libx264 --enable-static --disable-shared --enable-encoder=libx264 --extra-libs=-ldl –enable-nonfree
- 编译执行
make && sudo make install
- 查询ffmpeg
[root@x ffmpeg]# ffmpeg
ffmpeg: error while loading shared libraries: libx264.so.164: cannot open shared object file: No such file or directory
如果报错没找到文件,则:
# 先找到缺失文件的位置,例如执行
find / -name ‘libx264.so.164’
# 得到
/home/soft/x264/libx264.so.164
/usr/local/lib/libx264.so.164
# 修改ld.so.conf
vim /etc/ld.so.conf
最后一行添加:/usr/local/lib/
[root@x home]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib/
# 加载改动
ldconfig
- 检测是否安装成功
[root@x home]# ffmpeg
ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --enable-gpl --enable-libx264 --enable-static --disable-shared --enable-encoder=libx264 --extra-libs=-ldl
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
- 配置环境变量
vim /etc/profile
# 新增
PATH=$PATH:/usr/local/ffmpeg/bin
export PATH
# 加载配置
source /etc/profile
六、测试
选择网络视频连接,进行下载测试,成功即全流程结束。
ffmpeg -i http://xxx.com/video.m3u8 -c:v libx264 -y -t 60 -timeout 100000 /home/test.ts
over.