紅帽Linux安裝ffmpeg

紅帽Linux安裝ffmpeg

學習opencv爲什麼安裝ffmpeg

  如果需要視頻處理和攝像頭方面的支持,則需要安裝ffmpeg,如果只是用opencv對靜態圖像進行處理,則可以不安裝ffmpeg。
  注意:opencv 3.1 調用了 ffmpeg 低版本的接口,所以如果是 opencv 中需要識別 ffmpeg,則應安裝低版本的 ffmpeg,如 ffmpeg-2.2.16.tar.bz2 版本。

1. 安裝 yasm

  ffmpeg編譯中爲了提高編譯速度,使用了彙編指令,於是需要使用 yasm 這個工具。
  當然,如果實在不想要這個功能,可以在下一步的配置中使用./configure –disable-yasm選項。

(1)下載

  http://yasm.tortall.net/Download.html

(2)安裝
[root@localhost opencv]# tar zxvf yasm-1.3.0.tar.gz 
[root@localhost yasm-1.3.0]# ./configure
[root@localhost yasm-1.3.0]# make && make install

2. 下載 ffmpeg 安裝包

  http://ffmpeg.org/download.html#build-linux
  因爲通過添加yum源方式下載的rpm包版本較低,故使用 到官網自行下載最新版rpm包的方式安裝。

3. 解壓 ffmpeg 安裝包

[root@localhost opencv]# tar -jxvf ffmpeg-3.2.4.tar.bz2 

4. ffmpeg 配置必要選項

  這一步根據自己需要開啓或關閉某些選項,具體可以使用./configure –help查看,或者直接查看configure文件。本文使用如下簡單配置。

[root@localhost opencv]# cd ffmpeg-3.2.4
[root@localhost ffmpeg-3.2.4]# ./configure --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/usr/local/ffmpeg  --enable-version3 --enable-postproc --enable-pthreads --enable-x11grab --enable-avisynth

  –enable-shared 表示生成動態鏈接庫,可以供以後編程使用,同時生成的可執行程序也依賴這些動態庫。如果不加上 –enable-shared 選項則使用靜態鏈接的方式編譯,此時不會生成動態庫,同時生成的ffmpeg等的可執行文件也比較大,但他們不需要動態庫就可以直接運行。
  –prefix 表示程序安裝的目錄,這裏設爲/usr/local/ffmpeg。
  opencv會使用到libswscale,所以要在編譯的時候把swscale這個庫也編譯出來;而libswscale是遵守gpl的,不enable gpl的話就無法編譯。

5. 編譯安裝

  編譯,需要較長時間,10分鐘左右:

[root@localhost ffmpeg-3.2.4]# make

  安裝,很快完成:

[root@localhost ffmpeg-3.2.4]# make install

6. 路徑處理

[root@localhost ffmpeg-3.2.4]# cd /usr/local/ffmpeg/
[root@localhost ffmpeg]# ls
bin  include  lib  share

  安裝完成後在/usr/local/ffmpeg出現三個目錄:
   ● bin:可執行文件目錄
   ● lib:動態鏈接庫目錄
   ● include:編程用到的頭文件目錄

(1)添加動態庫路徑

  不管是編程還是可執行程序的執行都需要依賴lib下面的動態庫,可以把裏面的so文件拷貝到/usr/lib下,但可以直接修改配置文件。
  通過查看/etc/ld.so.conf文件,發現裏面只有一句話:

include ld.so.conf.d/*.conf

  表明其包含了ld.so.conf.d下所有的conf文件,於是可以在/etc/ld.so.conf.d/創建一個新的文件ffmpeg.conf,其中包含一句話,即爲ffmpeg的lib目錄:

[root@localhost ld.so.conf.d]# pwd
/etc/ld.so.conf.d
[root@localhost ld.so.conf.d]# vim ffmpeg.conf

  添加:

/usr/local/ffmpeg/lib

  執行ldconfig -v,更新ld.so.cache,使修改生效:

[root@localhost ld.so.conf.d]# ldconfig -v
(2)創建軟鏈接

  爲了在任何地方能夠直接用ffmpeg運行,而不用使用如./ffmpeg或者 /usr/local/ffmpeg/bin/ffmpeg的方式運行程序,可以把可執行程序複製到bin目錄下,這裏選擇在bin目錄下創建軟鏈接。軟鏈接類似於Windows下的快捷方式,如果原可執行程序被刪除了,軟鏈接也不能繼續使用,而硬鏈接則可以繼續使用。創建軟連接如下:

[root@localhost ld.so.conf.d]# ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/
[root@localhost ld.so.conf.d]# ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/
[root@localhost ld.so.conf.d]# ln -s /usr/local/ffmpeg/bin/ffserver /usr/local/bin/

  bin目錄中可執行文件使用指南:
    http://blog.csdn.net/stone_wzf/article/details/45378759
    http://blog.csdn.net/oldmtn/article/details/20830301
    http://www.cnblogs.com/tianma3798/p/6285550.html

(3)頭文件拷貝到 /usr/include/

  /usr/local/ffmpeg/include 路徑下會有如下目錄:

[root@localhost include]# ls
libavcodec   libavfilter  libavutil    libswresample
libavdevice  libavformat  libpostproc  libswscale
[root@localhost include]# pwd
/usr/local/ffmpeg/include

  /usr/local/ffmpeg/include 目錄下創建 ffmpeg 目錄:

[root@localhost include]# mkdir ffmpeg

  將 /usr/local/ffmpeg/include 路徑下所有目錄中文件複製到 ffmpeg 目錄中。
  將 /usr/local/ffmpeg/include 路徑下 ffmpeg/ 目錄複製到 /usr/include/ :

[root@localhost include]# pwd
/usr/local/ffmpeg/include
[root@localhost include]# cp -r ffmpeg/ /usr/include/

  這麼做是因爲opencv編譯的時候會去尋找ffmpeg/avcodec.h和ffmpeg/swscale.h等一些文件,ffmpeg以前的做法是把所有的頭文件都放在ffmepg目錄下面,但是現在新的版本已經改成放置到不同目錄下,(如果不做這一步的話,在configure配置opencv的時候就會提示沒有找到ffmpeg,同時編譯opencv的時候需要更改 opencv下的一個cpp文件(忘了名字了,編譯的時候出來的),那裏面是ffmepg/avcodec.h ffmpeg/avformat.h ffmpeg/swscale.h,然後分別改正到正確的頭文件所在就可以了)。

7. PKG_CONFIG_PATH 變量設置

  ffmpeg 安裝程序會在 /usr/local/ffmpeg/lib/pkgconfig 目錄下提供 libavcodec.pc libswscale.pc 等5個.pc文件,分別對應安裝的五個庫文件。

[root@localhost pkgconfig]# pwd
/usr/local/ffmpeg/lib/pkgconfig
[root@localhost pkgconfig]# ls
libavcodec.pc   libavfilter.pc  libavutil.pc    libswresample.pc
libavdevice.pc  libavformat.pc  libpostproc.pc  libswscale.pc

  必須要讓pkg-config能找到ffmpeg的*.pc文件,通過PKG_CONFIG_PATH 來設置pkg-config來更新:

[root@localhost pkgconfig]# vim /etc/profile

  添加:

export  PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/ffmpeg/lib/pkgconfig

  再添加:

export FFMPEG_HOME=/usr/local/ffmpeg
export PATH=$PATH</span>:<span class="hljs-variable">$FFMPEG_HOME

  使配置立即生效:

[root@localhost pkgconfig]# source /etc/profile

8. 測試

[root@localhost include]# ffmpeg
ffmpeg version 3.2.4 Copyright (c) 2000-2017 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.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  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'

備註:configure參數說明

ffmpeg ./configure參數說明
root@web ffmpeg]# ./configure --help
Usage: configure [options]
Options: [defaults in brackets after descriptions]
Standard options: 基本選項參數
--help                   顯示此幫助信息|print this message
--log[=FILE|yes|no]      記錄測試並輸出到config.err文件|log tests and output to FILE [config.err]
--prefix=PREFIX          安裝程序到指定目錄(默認/usr/local)|install in PREFIX [/usr/local]
--libdir=DIR             安裝庫到指定目錄(默認prefix/lib)|install libs in DIR [PREFIX/lib]
--shlibdir=DIR           指定共享庫路徑(默認prefix/lib)|install shared libs in DIR [PREFIX/lib]
--incdir=DIR             指定includes路徑(默認prefix/include/ffmpeg)|install includes in DIR[PREFIX/include/ffmpeg]
--mandir=DIR             指定man page路徑(默認prefix/man)install man page in DIR [PREFIX/man]
--enable-mp3lame         啓用mp3編碼libmp3lame(默認關閉)enable MP3 encoding via libmp3lame[default=no]
--enable-libogg          啓用ogg支持libogg(默認關閉)enable Ogg support via libogg [default=no]
--enable-vorbis          啓用Vorbis支持libvorbis(默認關閉)enable Vorbis support via libvorbis [default=no]
--enable-faad            啓用faad支持libfaad(默認關閉)enable FAAD support via libfaad [default=no]
--enable-faadbin         啓用faad運行時鏈接支持(默認關閉)build FAAD support with runtime linking[default=no]
--enable-faac            啓用faac支持libfaac(默認關閉)enable FAAC support via libfaac [default=no]
--enable-libgsm          啓用GSM支持libgsm(默認關閉)enable GSM support via libgsm [default=no]
--enable-xvid            啓用xvid支持xvidcore(默認關閉)enable XviD support via xvidcore [default=no]
--enable-libx264            啓用H.264編碼(默認關閉)enable H.264 encoding via x264 [default=no]
--enable-mingw32         啓用MinGW本地/交叉win環境編譯|enable MinGW native/cross Windows compile
--enable-mingwce         啓用MinGW本地/交叉winCE環境編譯enable MinGW native/cross WinCE compile
--enable-a52             啓用A52支持(默認關閉)enable GPLed A52 support [default=no]
--enable-a52bin          啓用運行時打開liba52.so.0(默認關閉)open liba52.so.0 at runtime [default=no]
--enable-dts             啓用DTS支持(默認關閉)enable GPLed DTS support [default=no]
--enable-pp              啓用後加工支持(默認關閉)enable GPLed postprocessing support [default=no]
--enable-static          構建靜態庫(默認啓用)build static libraries [default=yes]
--disable-static         禁止構建靜態庫(默認關閉)do not build static libraries [default=no]
--enable-shared          構建共享庫(默認關閉)build shared libraries [default=no]
--disable-shared         禁止構建共享庫(默認啓用)do not build shared libraries [default=yes]
--enable-amr_nb          啓用amr_nb float音頻編解碼器|enable amr_nb float audio codec
--enable-amr_nb-fixed    啓用fixed amr_nb codec | use fixed point for amr-nb codec
--enable-amr_wb          啓用amr_wb float音頻編解碼器|enable amr_wb float audio codec
--enable-amr_if2         啓用amr_wb IF2音頻編解碼器|enable amr_wb IF2 audio codec
--enable-sunmlib         啓用Sun medialib(默認關閉) | use Sun medialib [default=no]
--enable-pthreads        啓用pthreads(多線程)(默認關閉)use pthreads [default=no]
--enable-dc1394          啓用libdc1394、libraw1394抓取IIDC-1394(默認關閉)enable IIDC-1394 grabbing using libdc1394 and libraw1394 [default=no]
--enable-swscaler        啓用計數器支持?(默認關閉)software scaler support [default=no]
--enable-avisynth        允許讀取AVISynth腳本本件(默認關閉)allow reading AVISynth script files [default=no]
--enable-gpl             允許使用GPL(默認關閉)allow use of GPL code, the resulting libav* and ffmpeg will be under GPL [default=no]
Advanced options (experts only): 高級選項參數(供專業人員使用)
--source-path=PATH       源碼的路徑(當前爲/root/flv/ffmpeg)| path to source code [/root/flv/ffmpeg]
--cross-prefix=PREFIX    爲編譯工具指定路徑 | use PREFIX for compilation tools []
--cross-compile          假定使用了交叉編譯 | assume a cross-compiler is used
--cc=CC                  指定使用何種C編譯器(默認gcc)use C compiler CC [gcc]
--make=MAKE              使用特定的make | use specified make [make]
--extra-cflags=ECFLAGS   添加ECFLAGSCFLAGS | add ECFLAGS to CFLAGS []
--extra-ldflags=ELDFLAGS 添加ELDFLAGSLDFLAGS(默認-Wl,--as-needed)| add ELDFLAGS to LDFLAGS [ -Wl,--as-needed]
--extra-libs=ELIBS       添加ELIBS | add ELIBS []
--build-suffix=SUFFIX    爲專用程序添加後綴 | suffix for application specific build []
--arch=ARCH              選擇機器架構(默認x86)select architecture [x86]
--cpu=CPU                選用最低的cpu(影響指令的選擇,可以在老CPU上出錯) | selects the minimum cpu required (affects instruction selection, may crash on older CPUs)
--powerpc-perf-enable    啓用PPC上面的性能報告(需要啓用PMC)enable performance report on PPC
                           (requires enabling PMC)
--disable-mmx            禁用MMX | disable MMX usage
--disable-armv5te        禁用armv5te | disable armv5te usage
--disable-iwmmxt         禁用iwmmxt | disable iwmmxt usage
--disable-altivec        禁用AltiVec | disable AltiVec usage
--disable-audio-oss      禁用OSS音頻支持(默認啓用)disable OSS audio support [default=no]
--disable-audio-beos     禁用BeOS音頻支持(默認啓用)disable BeOS audio support [default=no]
--disable-v4l            禁用video4linux提取(默認啓用)disable video4linux grabbing [default=no]
--disable-v4l2           禁用video4linux2提取(默認啓用)disable video4linux2 grabbing [default=no]
--disable-bktr           禁用bktr視頻提取(默認啓用)disable bktr video grabbing [default=no]
--disable-dv1394         禁用DV1394提取(默認啓用)disable DV1394 grabbing [default=no]
--disable-network        禁用網絡支持(默認支持)disable network support [default=no]
--disable-ipv6           禁用ipv6支持(默認支持)disable ipv6 support [default=no]
--disable-zlib           禁用zlib(默認支持)disable zlib [default=no]
--disable-simple_idct    禁用simple IDCT例程(默認啓用)disable simple IDCT routines [default=no]
--disable-vhook          禁用video hooking支持 | disable video hooking support
--enable-gprof           enable profiling with gprof [no]
--disable-debug          禁用調試符號 | disable debugging symbols
--disable-opts           禁用編譯器最優化 | disable compiler optimizations
--disable-mpegaudio-hp   啓用更快的解碼MPEG音頻(但精確度較低)(默認禁用)faster (but less accurate) MPEG audio decoding [default=no]
--disable-protocols      禁用 I/O 協議支持(默認啓用)disable I/O protocols support [default=no]
--disable-ffserver       禁用生成ffserver | disable ffserver build
--disable-ffplay         禁用生成ffplay | disable ffplay build
--enable-small           啓用優化文件尺寸大小(犧牲速度)optimize for size instead of speed
--enable-memalign-hack   啓用模擬內存排列,由內存調試器干涉? | emulate memalign, interferes with memory debuggers
--disable-strip          禁用剝離可執行程序和共享庫 | disable stripping of executables and shared libraries
--disable-encoder=NAME   禁用XX編碼器 | disables encoder NAME
--enable-encoder=NAME    啓用XX編碼器 | enables encoder NAME
--disable-decoder=NAME   禁用XX解碼器 | disables decoder NAME
--enable-decoder=NAME    啓用XX解碼器 | enables decoder NAME
--disable-encoders       禁用所有編碼器 | disables all encoders
--disable-decoders       禁用所有解碼器 | disables all decoders
--disable-muxer=NAME     禁用XX混音器 | disables muxer NAME
--enable-muxer=NAME      啓用XX混音器 | enables muxer NAME
--disable-muxers         禁用所有混音器 | disables all muxers
--disable-demuxer=NAME   禁用XX解軌器 | disables demuxer NAME
--enable-demuxer=NAME    啓用XX解軌器 | enables demuxer NAME
--disable-demuxers       禁用所有解軌器 | disables all demuxers
--enable-parser=NAME     啓用XX剖析器 | enables parser NAME
--disable-parser=NAME    禁用XX剖析器 | disables parser NAME
--disable-parsers        禁用所有剖析器 | disables all parsers

參考:

http://www.2cto.com/os/201603/494063.html
http://blog.csdn.net/u012793120/article/details/51494828
http://blog.sina.com.cn/s/blog_684f1c2701016ib8.html
http://blog.csdn.net/aoshilang2249/article/details/48736369
http://www.opencv.org.cn/forum.php?mod=viewthread&tid=81
http://www.centoscn.com/image-text/install/2015/0523/5512.html
http://blog.csdn.net/henry121212/article/details/43489067
http://blog.csdn.net/david_xtd/article/details/8645306
https://my.oschina.net/zhangjie830621/blog/469909
http://www.cnblogs.com/wanghetao/p/3386311.html
http://www.cnblogs.com/lidabo/p/3987378.html
http://blog.csdn.net/sbdx/article/details/46670401
http://www.cnblogs.com/azraelly/archive/2012/12/31/2840541.html

原文出處:
http://blog.csdn.net/yangdiao127/article/details/64134508

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章