一、安装nasm
下载nasm软件包
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz
解压并安装
tar -xvf nasm-2.14.tar.gz
cd nasm-2.14/
./configure
make && sudo make install
验证是否已安装
nasm -version
[root@x nasm-2.14]# nasm -version
NASM version 2.14 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,已安装可跳过,(编译ffmpeg错误:ERROR: x264 not found using pkg-config ---重装pkg
pkg安装出现这种报错:
configure: error: pkg-config and "glib-2.0 >= 2.16" not found, please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure
使用 ./configure --with-internal-glib
)
[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 install gcc
下载ffmpeg
6.0版本,快速下载
wget http://ffmpeg.org/releases/ffmpeg-6.0.tar.xz
(或)访问官网选择任意版本
http://ffmpeg.org/download.html#releases
解压
tar -zxvf ffmpeg-6.0.tar.xz
mv ffmpeg-6.0/ /usr/local/ffmpeg/
配置ffmpeg
cd /usr/local/ffmpeg
./configure --enable-gpl --enable-libx264 --enable-static --disable-shared --enable-encoder=libx264 --extra-libs=-ldl
编译执行
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/x.m3u8 -c:v libx264 -y -t 60 -timeout 100000 /home/test.ts
这些包我好像都上传了,不知道有没有审核过,应该设置了几个积分