1. 程式人生 > >Linux編譯安裝ffmpeg redhat /cenos

Linux編譯安裝ffmpeg redhat /cenos

一、安裝yasm

# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
# tar -zxvf yasm-1.3.0.tar.gz
# cd yasm-1.3.0
# ./configure
# make && make install

二、首先是安裝各種解碼器

1、lame

wget https://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -zxvf lame-3.99.5.tar.gz
cd lame-3.99.5 
./configure --enable-shared
make 
make install

2、libogg

wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar -zxvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --enable-shared
make 
make install

3、a52

wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
tar -zxvf a52dec-0.7.4.tar.gz
cd a52dec-0.7.4
./configure --enable-shared
make 
make install

4、libvorbis

#libvorbis依賴於libogg, 所以libogg必須先於libvorbis安裝
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
tar -zxvf libvorbis-1.3.5.tar.gz
cd  libvorbis-1.3.5
./configure --enable-shared
make 
make install

5、xvidcore

wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar -zxvf xvidcore-1.3.2.tar.gz 
cd xvidcore/build/generic
./configure --enable-shared
make 
make install

6、x264

last_x264.tar.bz2包
因為沒有找到好的資源,給一個ftp資源,下載最新版本之後上傳到linux上
ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
tar -jxvf last_x264.tar.bz2
cd x264-snapshot-20170330-2245
./configure --enable-shared
make 
make install

7、libdts

wget http://down1.chinaunix.net/distfiles/ffmpeg-0.5.tar.bz2
tar -jxvf libdca-0.0.5.tar.bz2
cd libdca-0.0.5
./configure --enable-shared
make 
make install

8、faad2

wget https://jaist.dl.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
tar -zxvf faad2-2.7.tar.gz
cd faad2-2.7
./configure --enable-shared
make 
make install

9、faac

wget https://jaist.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
tar -zxvf faac-1.28.tar.gz
cd faac-1.28
./configure --enable-shared
make 
make install

編譯FAAC-1.28時遇到錯誤
[mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’]
找到mpeg4ip.h並修改修改
解決方法:
從123行開始修改此檔案mpeg4ip.h,到129行結束。
修改前:
#ifdef __cplusplus
extern "C" {
#endif
char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

修改後:
#ifdef __cplusplus
extern "C++" {
#endif
const char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

10、amr-nb

wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-10.0.0.0.tar.bz2
tar -jxvf amrnb-10.0.0.0.tar.bz2
cd amrnb-11.0.0.0
./configure --enable-shared
make 
make install

111、amr-wb

wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-11.0.0.0.tar.bz2
tar -jxvf amrwb-11.0.0.0.tar.bz2
cd amrwb-11.0.0.0
./configure --enable-shared
make 
make install

三、安裝ffmpeg

wget http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
tar -jxvf http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
cd ffmpeg-3.2.4
#其中–enable-shared表示生成動態連結庫,可以供以後程式設計使用,同時生成的可執行程式也依賴這些動態庫。如果不加上–enable-shared選項則使用靜態連結的方式編譯,此時不會生成動態庫,同時生成的ffmpeg等的可執行檔案也比較大,但他們不需要動態庫就可以直接執行
./configure --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads  --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libxvid --enable-postproc --enable-ffplay
#可根據提示自行優化
#安裝完成後
vi /etc/ld.so.conf/
把/usr/local/ffmpeg/lib填寫到該檔案中(我這裡安裝的所有解碼器都注入到/usr/local/lib中了,故此,我這裡寫的是/usr/local/lib)
再執行ldconfig,使修改生效

vi /etc/profile
加入以下內容:

FFMPEG=/usr/local/ffmpeg
PATH加入:$FFMPEG/bin
#使修改立即生效
source /etc/profile

#測試安裝是否成功
cd /usr/local/ffmpeg/bin
#執行
./ffmpeg
#出現如下內容說明安裝成功
ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
  configuration: --enable-shared --prefix=/usr/local/ffmpeg
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.100 / 57. 64.100
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

四、使用ffmpeg

//轉碼
/usr/ffmpeg-3.1/ffmpeg-3.1/bin/./ffmpeg -i /usr/video-test/1.mp4  /usr/video-test/2.flv  
/usr/local/ffmpeg/bin/./ffmpeg -i /usr/video-test/tt.mp4  -vcodec libx264 -b:v 500000 -r 25 -acodec libmp3lame -b:a 64000 -ar 22050  /usr/video-test/tt.flv

//截圖
/usr/ffmpeg-3.1/ffmpeg-3.1/bin/./ffmpeg -i /usr/video-test/1.mp4 -ss 5 -s 880x496 -f image2 -vframes 1  /usr/video-test/2.jpg