ffmpeg是业界强大的视频转码工具,本文介绍了两种在CentOS7.5操作系统下安装ffmpeg的方法。
一、编译安装(复杂,但是功能更全)
0、准备好C编译器等依赖
yum install -y gcc g++ cmake gcc-c++
1、去http://www.tortall.net/projects/yasm/releases下载ffmpeg依赖的yasm并安装
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxvf yasm-1.3.0.tar.gz
./configure
make && make install
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
2、下载和编译x264
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar jxvf x264-master.tar.bz2
cd ./x264-master
make clean && make uninstall
./configure --enable-shared --disable-asm
make -j4
make install
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar jxvf x264-master.tar.bz2
cd ./x264-master
make clean && make uninstall
3、下载和编译x265
复制代码
wget https://bitbucket.org/multicoreware/x265/downloads/x265_3.4.tar.gz
tar zxvf x265_3.4.tar.gz
cd x265_3.4/source
make clean && make uninstall
cmake CMakeLists.txt
make -j4
make install
wget https://bitbucket.org/multicoreware/x265/downloads/x265_3.4.tar.gz
tar zxvf x265_3.4.tar.gz
cd x265_3.4/source
4、下载安装ffmpeg
wget https://ffmpeg.org/releases/ffmpeg-4.2.3.tar.bz2
tar jxvf ffmpeg-4.2.3.tar.bz2
cd ffmpeg-4.2.3
make clean && make uninstall
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ ./configure --enable-libx264 --enable-libx265 --disable-w32threads --disable-debug --enable-pthreads --enable-gpl
make -j4
make install
5、编辑ld.so.config
vi /etc/ld.so.conf
#增加/usr/local/lib
#完成后文件内容示例如下
include ld.so.conf.d/*.conf
/usr/local/lib
#再执行刷新命令
ldconfig
二、yum源安装(易安装,但是功能不全,比如封装格式转换可能会报错)
1、安装第三方yum源——Nux Dextop Yum
yum install -y epel
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
yum install -y epel
、安装FFmpeg 和 FFmpeg开发包
sudo yum install ffmpeg ffmpeg-devel -y
三、使用示例
1、查看版本
ffmpeg -version
2、将TS转码为MP4(全转)
ffmpeg -y -i 01.TS -threads 1 -c:v libx264 -c:a copy -bsf:a aac_adtstoasc 01.mp4
3、切片
ffmpeg -i output.ts -c copy -map 0 -f segment -segment_list playlist.m3u8 -segment_time 10 output%03d.ts
4、修改封装格式
ffmpeg -i 01.TS -map 0 -c copy 01.mp4
附:
常见文件格式、封装格式、编码格式对照表:
三种格式简单介绍:
文件格式只是一个名称,告诉播放器这是哪种封装格式,封装格式好比容器,编码格式则是真正的内容
参考: