linux下編譯安裝ffmpeg和opencv


  1、下載ffmpeg。

      在網上搜索一下,或者到官方網站下載

  

  2、解壓

     tar命令解壓


  3、配置

  ./configure --enable-shared --prefix=/usr/local/ffmpeg

  其中:--enable-shared 是允許其編譯產生動態庫,在以后的編程中要用到這個幾個動態庫。--prefix設置的安裝目錄。

  4、編譯並安裝

  make
  make install

  5、安裝之后在/usr/local/ffmpeg會看到有三個目錄

  lib 動態鏈接庫位置
  include 編程要用到頭文件
  bin 執行文件所在的目錄

  6、為了以后方便編程,我們把lib中的三個鏈接庫libavcodec.so libavformat.so libavutil.so復制到/usr/lib下。把include目錄下的ffmpeg目錄復制到/usr/include下。

  執行bin目錄下的ffplay,可以去播放音頻或者視頻文件。例如播放1.mp3

  ./ffplay 1.mp3

  另外,bin目錄下還有兩個文件:ffmpeg和ffserver

  ffmpeg是一個很好的視頻和音頻的格式轉化工具。網上有很多它的說明文檔。如果不想生成ffserver,只要在./configure的時候加--disable-ffserver即可。

  7、編程

  如果寫了一個test.c文件,要包含ffmpeg的頭文件,可以這樣寫:

  #include 

  編譯:gcc -o test test.c -lavformat -lavcodec -lavtuil (前提是有第6步的操作)

  如果沒有第6部的操作,則編譯的時候如下:

  gcc -o test test.c -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lavcodec -lavtuil

  編譯成功之后,執行的時候還是需要動態庫的支持,還是要把那三個動態庫文件復制到/usr/lib或者/lib中,不然執行的時候會說找不到動態庫鏈接。還有一個方法可以解決這個問題,就是把/usr/local/ffmpeg/lib這個目錄加入到/etc/ld.so.config中,然后執行ldconfig,或者重啟電腦,這樣執行的時候系統就可以從/usr/local/ffmpeg/lib這個目錄下去找這三個動態庫文件了。

  以上的方式是采用動態庫編譯ffmpeg的,如果在configure的時候不加上--enable-shared的,則采用靜態鏈接的方式,不會生成那三個動態庫。同時生成的ffplay、ffmpeg的執行文件也比較的大,因為他們不需要動態庫的支持,就可以執行。但是不利於再次開發,所以我采用動態鏈接的方式。configure中還有很多的選項,可以通過./configure --help查看,也可以直接查看configure文件。這在配置的時候很重要。

 

===================================================OPENCV=======================================

下載解壓ffmpeg源代碼

  1. Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries.

  2. Enter the <cmake_binary_dir> and type

    cmake [<some optional parameters>] <path to the OpenCV source directory>
    

    For example

    cd ~/opencv
    mkdir release
    cd release
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..//CMAKE_INSTALL_PREFIX表示預安裝目錄,一般在usr/local/下,實在不行就在當前目錄下cmake
    
  3. Enter the created temporary directory (<cmake_binary_dir>) and proceed with:

    make
    sudo make install
    

Note

 

If the size of the created library is a critical issue (like in case of an Android build) you can use theinstall/strip command to get the smallest size as possible. The stripped version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM