最近要做 ffmpeg + opencv, 這一篇 ffmpeg 安裝收藏
必需要參考的文章:
http://blog.chinaunix.net/uid-23069658-id-4018842.html
準備工作:
安裝git
yum install git -y
安裝svn
yum install svn
Centos 準備安裝刪除已安裝包
yum erase ffmpeg x264 x264-devel
Centos 安裝各種依賴包
yum install gcc gcc-c++ make nasm pkgconfig wget curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64 pcre.i386 pcre.x86_64 pcre-devel.i386 pcre-devel.x86_64 -y
安裝nasm編譯器支持彙編優化(lame庫需要)
防止因爲時間不對,修改一下爲北京時間
1.如果提示command not found,那說明ntp沒有安裝,使用如下命令進行安裝
yum -y install ntpdate ntp
2、ntpdate us.pool.ntp.org
3、設置硬件時間和軟件時間的一致並校準
/sbin/hwclock --systoh
wget http://www.nasm.us/pub/nasm/releasebuilds/2.11.05/nasm-2.11.05.tar.bz2 tar xvf nasm-2.11.05.tar.bz2 cd nasm-2.11.05 配置安裝目錄爲/usr/bin: ./configure --prefix=/usr 編譯並安裝: make && make install
安裝yasm編譯器支持彙編優化(ffmpeg庫需要) wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz 解壓: tar xvf yasm-1.2.0.tar.gz cd yasm-1.2.0 配置安裝目錄爲/usr/bin: ./configure --prefix=/usr 編譯並安裝: make && make install
安裝x264庫支持h.264視頻轉碼
安裝x264庫支持h.264視頻轉碼 執行以下命令獲取x264的最新源代碼 git clone git://git.videolan.org/x264.git cd x264 ./configure --enable-shared make && make install
安裝 LibNut
安裝libnut,該軟件需要用svn獲取源代碼,svn可以直接用yum install svn來裝。先下載: # svn co svn://svn.mplayerhq.hu/nut/src/trunk libnut 下載後代碼保存在新建立的libnut目錄下,對於64位Linux需要修改配置文件: # cd libnut # vi config.mak 在最後一個CFLAGS下一行增加: CFLAGS += -fPIC 然後編譯安裝: # make # make install
====================================================================================================================================================
安裝libogg
yum install libogg-devel
安裝libtheora (svn獲取)
# svn co http://svn.xiph.org/trunk/theora theora # cd theora # ./autogen.sh # ./configure # make # make install
安裝libvorbis # wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.0.tar.gz # tar xvfz libvorbis-1.2.0.tar.gz # cd libvorbis-1.2.0 # ./configure # make # make install
安裝libvpx
++++++++libvpx+++++++++++ git clone http://git.chromium.org/webm/libvpx.git (本次獲取後打包爲libvpx-v1.2.0.tar.gz) 其它獲取方式#wget http://webm.googlecode.com/files/libvpx-v1.1.0.tar.bz2 cd libvpx ./configure --enable-shared make && make install
++++++++Xvid+++++++++++ #wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz tar zxf xvidcore-1.3.2.tar.gz cd xvidcore/build/generic ./configure make && make install
上面的媒體支持庫安裝完後,可以設置下環境準備編譯ffmpeg了。不過在此之前必須修改環境變量 vim /etc/ld.so.conf 在文件末增加一行: /usr/local/lib 然後生效之: ldconfig -v
編譯ffmpeg 執行以下命令獲取ffmpeg源代碼 git clone git://source.ffmpeg.org/ffmpeg.git cd ffmpeg ./configure --enable-version3 --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libxvid --enable-shared --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --enable-libnut --enable-libtheora ***需要保證 --enable-libx264能執行 make && make install ldconfig -v TS流分割器segmenter的安裝與使用 git clone https://github.com/johnf/m3u8-segmenter
cd m3u8-segmenter
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat -lavcodec -lavutil cp segmenter /usr/bin/
直接轉成ts
ffmpeg -i vp5.flv -acodec copy -vcodec libx264 vp5.ts
150MB的一個MPG文件,大約轉換時間:4分零7秒。
切割
segmenter -i vp5.ts -d 10 -p segmenter_test -m vp5.m3u8 -u http://127.0.0.1:8080/Video/ 這樣就可以切片出m3u8文件 直接使用hls
來源: http://www.cnblogs.com/littlehb/p/3914437.html