1、安裝yasm編譯器
官方下載地址:http://yasm.tortall.net/Download.html
依次執行以下命令:
tar -xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make && make install
yasm --version
2、安裝H264編碼器
官方下載地址:http://www.videolan.org/developers/x264.htm
依次執行以下命令:
tar -xvf x264-master.tar.bz2
cd x264-master
./configure --prefix=/usr/local/ffmpeg/x264static --enable-shared --enable-static --disable-asm
make && make install
3、安裝ffmpeg
官方下載地址:http://ffmpeg.org/download.html
依次執行以下命令:
tar jxvf ffmpeg-4.2.tar.bz2 #解壓bz2需要先安裝: yum -y install bzip2
cd ffmpeg-4.2/
./configure --prefix=/usr/local/ffmpeg/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/ffmpeg/x264static/include --extra-ldflags=-L/usr/local/ffmpeg/x264static/lib
make && make install #編譯和安裝;耗時比較久
異常解決方案:error while loading shared libraries: libavdevice.so.58: cannot open shared
vim /etc/ld.so.conf.d/ffmpeg.conf
#寫入內容“/usr/local/ffmpeg/ffmpeg/lib”後保存退出
異常解決方案:error while loading shared libraries: libx264.so.159: cannot open shared object file: No such file or directory
vi /etc/ld.so.conf
#在最後面寫入內容“/usr/local/ffmpeg/x264static/lib”後保存退出
ldconfig #更新環境變量
./ffmpeg -version 查看安裝版本/是否安裝成功【可選】
./ffmpeg -encoders |grep 264 檢查是否安裝H264成功
操作一下試試:/usr/local/ffmpeg/ffmpeg/bin/ffmpeg -i test3gp.3gp -vcodec h264 -ac 1 -ar 11025 -y -hide_banner test3gp1.mp4