前言
现需要将一批avi格式的视频转码为mp4,以下为操作步骤。系统版本为CentOS 7。
如果不安装x264,转码后只有声音,没有视频。
编译安装nasm
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.xz tar xf nasm-2.15.05.tar.xz cd nasm-2.15.05 ./configure --prefix=/usr/local/nasm/ make make install # 自行配置PATH环境变量
编译安装libfdk-aac
wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-2.0.1.tar.gz tar zxvf fdk-aac-2.0.1.tar.gz cd fdk-aac-2.0.1 ./configure --disable-static make make install
编译安装x264
git clone https://code.videolan.org/videolan/x264.git cd x264 ./configure --prefix=/usr/local/x264/ --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared make make install # 自行配置PATH环境变量
安装yum依赖
yum install -y openssl gnutls gnutls-devel lame lame-devel faac faac-devel
安装ffmpeg
wget http://ffmpeg.org/releases/ffmpeg-4.4.tar.xz ## 解压后cd ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-pthreads --enable-shared --enable-libmp3lame --enable-libx264 --enable-pic --enable-libfdk-aac --enable-openssl --enable-nonfree make make install # 自行配置PATH环境变量
问题记录
缺少库函数
ffmpeg: error while loading shared libraries: libavdevice.so.58 # 或 ffmpeg: error while loading shared libraries: libfdk-aac.so.2
解决方法:
- 编辑
/etc/ld.so.conf
- 追加内容:
/usr/local/ffmpeg/lib/
和/usr/local/lib/
- 完整内容示例如下:
include ld.so.conf.d/*.conf /usr/local/ffmpeg/lib/ /usr/local/lib/
avi转mp4
ffmpeg -i test.avi -vcodec h264 -f mp4 test.mp4 # 限制线程数(不限制可能会吃满CPU) ffmpeg -i test.avi -vcodec h264 -threads 2 -f mp4 test.mp4