CentOS安裝ffmpeg並轉碼視訊為mp4
阿新 • • 發佈:2021-08-16
CentOS 7 編譯安裝ffmpeg,並轉碼avi格式的視訊為mp4
前言
現需要將一批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