Centos/Ubuntu安装使用FFmpeg转码为m3u8(ts)格式
一、FFmepg介绍
FFmpeg 是一个用于处理多媒体文件的免费并且开源的工具集。它包含了一系列音频和视频库,例如:libavcodec, libavformat, 和 libavutil。使用 FFmpeg,你可以在各种视频和音频格式之间进行相互转换,设置码率,剪辑音频、视频,以及放缩视频。
二、安装FFmpeg
Centos7
#升级最新 yum
sudo yum install epel-release -y
sudo yum update -y
#安装 Nux Dextop Yum 源
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
#安装开发包
sudo yum install ffmpeg ffmpeg-devel -y
#测试
ffmpeg
Centos8
FFmpeg在默认的CentOS 8 源仓库中没有提供。可以选择通过源文件编译安装FFmpeg,或者使用dnf工具从Negativo17源仓库中安装。这里使用源文件编译安装 FFmpeg。
安装GCC
yum install gcc
安装x264支持
#Yasm 编译器安装(非必须)
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar fxz yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
#libx264 需要使用nasm依赖,所以先安装nasm
wget --no-check-certificate https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.gz
tar fxz nasm-2.15.05.tar.gz
cd nasm-2.15.05
./configure
make & make install
#再安装x264
git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-shared --prefix=/usr/local/ffmpeg5.1/x264
make & make install
安装 xvid 支持
#xvidcore 编解码器
wget http://downloads.xvid.org/downloads/xvidcore-1.3.3.tar.gz
tar zxf xvidcore-1.3.3.tar.gz
cd xvidcore/build/generic/
./configure prefix=/usr/local/ffmpeg5.1/xvid
make && make install
安装ffmpeg
wget http://ffmpeg.org/releases/ffmpeg-5.1.tar.gz
tar fxz ffmpeg-5.1.tar.gz
cd ffmpeg-5.1
./configure --prefix=/usr/local/ffmpeg5.1 --enable-shared --enable-avfilter --enable-libx264 --enable-gpl --enable-pthreads --enable-swscale --enable-version3 --enable-libxvid --enable-nonfree --enable-filter=movie --enable-decoder=png --enable-encoder=png --extra-cflags=-I/usr/local/ffmpeg5.1/x264/include --extra-cflags=-I/usr/local/ffmpeg5.1/xvid/include --extra-ldflags=-L/usr/local/ffmpeg5.1/x264/lib --extra-ldflags=-L/usr/local/ffmpeg5.1/xvid/lib
make && make install
# 加载库文件
echo "/usr/local/ffmpeg5.1/lib" >> /etc/ld.so.conf
echo "/usr/local/ffmpeg5.1/xvid/lib" >> /etc/ld.so.conf
echo "/usr/local/ffmpeg5.1/x264/lib" >> /etc/ld.so.conf
ldconfig
#测试(查看版本)
ffmpeg -version
Ubuntu
#使用yum安装
sudo apt install ffmpeg
ffmpeg -version
三、常见报错
可能遇到问题共享lib,比如: Requires: libass.so.5()(64bit)
在以下库中查找:
- https://centos.pkgs.org/
- http://www.rpmfind.net/linux/rpm2html/search.php?query=libass.so.5()(64bit)
#libass.so.5()(64bit)
wget http://www.rpmfind.net/linux/epel/7/x86_64/Packages/l/libass-0.13.4-6.el7.x86_64.rpm
sudo rpm -ivh libass-0.13.4-6.el7.x86_64.rpm
#libva.so.1()(64bit)
wget http://www.rpmfind.net/linux/atrpms/f20-x86_64/atrpms/stable/libva1-1.3.1-11.fc20.x86_64.rpm
sudo rpm -ivh libva1-1.3.1-11.fc20.x86_64.rpm
#libopenjpeg.so.1()(64bit)
wget http://www.rpmfind.net/linux/opensuse/distribution/leap/15.5/repo/oss/x86_64/libopenjpeg1-1.5.2-150000.4.10.1.x86_64.rpm
sudo rpm -ivh libopenjpeg1-1.5.2-150000.4.10.1.x86_64.rpm
#libhogweed.so.2()(64bit)
wget http://www.rpmfind.net/linux/openmandriva/4.3/repository/x86_64/main/release/lib64hogweed2-2.7.1-10-omv4050.x86_64.rpm
sudo rpm -ivh lib64hogweed2-2.7.1-10-omv4050.x86_64.rpm
#libnettle.so.4()(64bit)
wget http://www.rpmfind.net/linux/openmandriva/4.3/repository/x86_64/main/release/lib64nettle4-2.7.1-10-omv4050.x86_64.rpm
sudo rpm -ivh lib64nettle4-2.7.1-10-omv4050.x86_64.rpm