1. 程式人生 > IOS開發 >FFmpeg學習(2) 原始碼編譯, 環境配置

FFmpeg學習(2) 原始碼編譯, 環境配置

FFmpeg學習(1)開篇

FFmpeg學習(2)原始碼編譯,環境配置

FFmpeg學習(2) 原始碼編譯,環境配置

上一篇部落格“FFmpeg學習(一)開篇” 中講解了FFmpeg的原始碼下載,以及簡單的介紹了FFmpeg是什麼,學習它的好處,本篇部落格主要是針對FFmpeg原始碼編譯,環境變數設定,常用命令進行講解。

1. 準備知識

1.1 linux基礎命令

由於FFmpeg的學習涉及到要在命令列下處理,如果連一下基本的shell命令都不會的話,後面的學習是很吃力的,所以這裡簡單介紹一下基本的shell命令

必備幾個命令如下:

  • ls 命令:列出目錄下的檔案(List files)
  • cd 命令:切換目錄(Change directory)
  • pwd 命令:以絕對路徑的方式顯示使用者當前工作目錄
  • mkdir 命令:建立目錄(Make directory )
  • cp 命令:複製檔案/目錄(Copy file)
  • rm 命令:刪除N個檔案或整個目錄
  • sudo 命令:管理員許可權執行命令
  • pkg-config命令:配置環境變數

1.1.1 cd:切換目錄

  • cd ~cd:返回使用者目錄

    cd到當前使用者目錄

  • cd .:停留在當前目錄

    停留在當前目錄

  • cd ..:返回上一級目錄:

例如我們先跳轉到development目錄,然後再返回上一級目錄

返回上一級目錄

  • cd ../..:返回上兩級目錄:

例如我們先跳轉到development/study 目錄,然後再返回上兩級目錄

返回上兩級目錄

  • cd ../目錄A:先返回進入此目錄之前所在的目錄,然後再進入指定的目錄A

下面演示一下 我們先進入development/study目錄,然後cd ../projects目錄

返回上一級目錄並進入同級另一個目錄

  • cd -:返回進入此目錄之前所在的目錄 這個命令在我們來回切換兩個目錄時非常好用

上一步中我們先跳轉到development/study然後切換到了development/projects目錄,當我們輸入cd -命令時,會切換回到development/study目錄。如下圖所示:

切換原理目錄
如果我們再輸入cd -命令時, 會切換回development/projects目錄:

來回切換目錄

  • cd 路徑:進入指定目錄:
    進入指定目錄
  • cd /:返回到根目錄:
    返回到根目錄

1.1.2 ls:列出目錄下的檔案 (List files)

ls:列出指定路徑下的所有檔名、時間及讀寫許可權(檔案詳細資訊)

  • ls -a:顯示所有檔案列表(含隱藏檔案“.”和“..”)
    顯示所有檔案列表
  • ls -A:顯示除隱藏檔案“.”和“..”以外的所有檔案列表

顯示除隱藏檔案以外的所有檔案列表

  • ls -l:以列表形式顯示檔案及資料夾的詳細資訊
    以列表形式顯示檔案及資料夾的詳細資訊
    如上圖從左至右:檔案型別、許可權、數量、屬主、屬組、大小、修改/訪問時間、檔名)

1.1.3 mv:移動/重新命名 檔案或目錄 (Move file)

語法:mv 原始檔 目標檔案

  • 目標檔案不是目錄,即重新命名
    目標檔案不是目錄,即重新命名
  • 單檔案移動(mv 移動前檔案 移動後檔案路徑)

單檔案移動

  • 多檔案移動,使用 -t(含檔案及資料夾)

多檔案移動

1.1.4 mkdir:建立目錄(Make directory )

  • 在目錄名前沒有加任何路徑名,則在當前目錄下建立

在目錄名前沒有加任何路徑名,則在當前目錄下建立

  • 在目錄名前有一個已經存在的路徑,將會在該目錄下建立

建立多級目錄

  • 建立多級目錄及多資料夾,使用 -p(資料夾之間用空格隔開) 若上層目錄沒找到,則會一併建立

若上層目錄沒找到,則會一併建立

  • 建立帶許可權的資料夾,使用 -m 如果目錄不存在,建立失敗,此時需要使用 -p-m
    在這裡插入圖片描述

1.1.5 cat:顯示檔案的內容 (Concatenate)

  • 輸出多個檔案內容
    輸出多個檔案內容
  • 將2個檔案合併新檔案
    將2個檔案合併新檔案

注:若新檔案有內容,則原資料會被清空,因此需要小心操作

  • 將file1.txt追加到file2.txt的末尾(>> 表示將文字流追加到另一個檔案的末位)
    將file1.txt追加到file2.txt的末尾

1.1.6 find:在指定目錄下查詢檔案

語法為:find 目錄 引數

  • 單檔案匹配

    單檔案匹配

  • 多檔案匹配(目錄下以.txt結尾的檔案、含字母a的檔案) : 使用 -o

    多檔案匹配

  • 查詢除XX外的: **使用 "!" or "-not" **

例如,查詢當前資料夾下檔名不含a

find ./ ! -name "*a*"
複製程式碼

查詢當前資料夾下檔名不含a

查詢當前目錄下 檔案不含a的資訊 使用 -not

find ./ -maxdepth 1 -not -name "*a*"
複製程式碼

查詢當前目錄下 檔案不含a的資訊

  • 查詢檔案,忽略大小寫 :使用 -i

查詢檔案,忽略大小寫

  • 只查詢某層目錄下含XX的檔案(夾):使用 mindepthmaxdepth “-maxdepth 1” :限制只查詢1層目錄深度,當前目錄即為1層 例如查詢當前目錄下,含test的檔案及資料夾
find ./ -maxdepth 1 -name "*test*"
複製程式碼

查詢當前目錄下,含test的檔案及資料夾

  • 查詢空檔案(-empty)

只列出當前目錄下的非隱藏空檔案

只列出當前目錄下的非隱藏空檔案

  • 查詢指定檔案型別的檔案 (-type) 查詢指定目錄下的所有目錄 -type d

查詢指定目錄下的所有目錄

1.1.7 pwd:以絕對路徑的方式顯示使用者當前工作目錄

Print working directory

以絕對路徑的方式顯示使用者當前工作目錄

1.1.8 rm -引數:刪除N個檔案或整個目錄

使用rm命令要格外小心。因為一旦刪除了一個檔案,就無法再恢復。

建議用-i選項,刪除時會有提示

刪除時會有提示

rm -r(或rm -R):刪除當前目錄下除隱含檔案外的所有檔案和子目錄 rm -(r)f:強制刪除,f 可理解為force

結合find命令刪除: find 目錄 -name "*file*" -exec rm -rf {} \; 語法解析 -exec 找到後執行命令 rm -rf {} 就是刪除檔案 \; 命令 屬於格式要求的,沒有具體含義

find /app1/ -name "*test*" -exec rm -rf {} \;
複製程式碼

1.1.9 touch:建立新的空檔案

  • 建立單個檔案

    建立新的空檔案

  • 批量建立檔案

批量建立檔案

1.1.10 cp:複製檔案/目錄(Copy file)

  • 預設情況下,cp命令不能複製目錄,如果要複製目錄,則必須使用-R選項

如果要複製目錄,則必須使用-R選項

注意點:

  1. 目標目錄存在,直接複製
  2. 目標目錄不存在,先自動建立目標目錄再複製源目錄
  • 複製檔案

複製檔案

  • 複製檔案並重新命名檔案
    複製檔案並重新命名檔案

1.1.11 vi:修改檔案內容

先按鍵盤字母I,編輯內容後,儲存(按esc鍵後輸入:wq)

VI編輯內容

1.1.12 echo:建立/覆蓋檔案

  • 若檔案不存在則建立檔案

    若檔案不存在則建立檔案

  • 若檔案存在,覆蓋檔案原內容並重新輸入內容

    覆蓋檔案原內容並重新輸入內容

  • 使用 >>,向檔案追加內容,原內容不變

    向檔案追加內容,原內容不變

1.1.13 tar:檔案打包、解壓(Tape archive)

  • 檔案打包:tar -zcvf 打包名 檔案 例如:我們先進入到當前使用者的Downloads目錄下看看
    到當前使用者的Downloads目錄下看看
    現在我們要將紅框裡面的檔案壓縮成一個tar壓縮包

將紅框裡面的檔案壓縮成一個tar壓縮包

  • 檔案解壓:tar -zxvf 檔名
    檔案解壓

1.1.13.1 zip unzip 命令

  • zip 命令 在mac上面我經常需要壓縮成zip包,命令如下:
zip -q -r -e -m -o file.zip tempFile
複製程式碼

zip後面的引數說明:

  1. -q :表示不顯示壓縮排度狀態
  2. -r:表示子目錄子檔案全部壓縮為zip;這部分比較重要,不然的話只有tempFile這個資料夾被壓縮,裡面的沒有被壓縮排去
  3. -e:表示你的壓縮檔案需要加密,終端會提示你輸入密碼的;還有種加密方法,這種是直接在命令列裡做的,比如zip -r -P Password01! modudu.zip SomeDir,就直接用Password01!來加密modudu.zip了
  4. -m:表示壓縮完刪除原檔案
  5. -o:表示設定所有被壓縮檔案的最後修改時間為當前壓縮時間

當跨目錄的時候是這麼操作的

zip -q -r -e -m -o '\user\someone\someDir\someFile.zip' '\users\someDir'
複製程式碼

下面來演示一下zip命令:

演示一下zip命令

上面的操作將env資料夾壓縮成了env_temp.zip並且壓縮完成後刪除了env資料夾。

  • unzip 命令 語法:unzip [選項] 壓縮檔名.zip

    unzip 各選項的含義分別為:

    1. -x 檔案列表 解壓縮檔案,但不包括指定的file檔案
    2. -v 檢視壓縮檔案目錄,但不解壓。
    3. -t 測試檔案有無損壞,但不解壓。
    4. -d 目錄 把壓縮檔案解到指定目錄下。
    5. -z 只顯示壓縮檔案的註解。
    6. -n 不覆蓋已經存在的檔案。
    7. -o 覆蓋已存在的檔案且不要求使用者確認。
    8. -j 不重建檔案的目錄結構,把所有檔案解壓到同一目錄下。

將壓縮檔案env_temp.zip在當前目錄下解壓縮。

unzip env_temp.zip
複製程式碼

在當前目錄下解壓縮

將壓縮檔案env_temp.zip在指定目錄/tmp下解壓縮,如果已有相同的檔案存在,要求unzip命令不覆蓋原先的檔案。

$ unzip -n env_temp.zip -d /tmp 

複製程式碼

解壓到指定目錄

此外我們還可以只檢視壓縮檔案目錄,但不解壓。

輸入命令:

$ unzip -v env_temp.zip 
複製程式碼

檢視壓縮包內容,不解壓

1.1.14 scp:遠端拷貝檔案(secure copy)

  • 將本地的檔案上傳到遠端伺服器上 相對路徑下,scp 檔名 使用者名稱@ip:伺服器絕對路徑目錄 (分號後面無空格)
scp ffmpeg.tar.gz [email protected]:/app1/tools
複製程式碼

絕對路徑:

scp /app/software/tools/text.txt [email protected]:/app1/bak
複製程式碼

若是上傳目錄,需要使用 -r

scp -r /app/software/tools [email protected]:/app1/bak
複製程式碼
  • 將遠端伺服器上的檔案/目錄拷貝到本地

scp -r 使用者名稱@ip:伺服器絕對路徑目錄 絕對路徑本地目錄

scp -r [email protected]:/app1/tools   /app/software
scp [email protected]:/app1/tools/text.txt    /app/software/tools
複製程式碼

1.1.15 sudo: 管理員許可權執行命令

  • 簡介:

sudo是linux系統管理指令,是允許系統管理員讓普通使用者執行一些或者全部的root命令的一個工具,如halt,reboot,su等等。這樣不僅減少了root使用者的登入 和管理時間,同樣也提高了安全性。sudo不是對shell的一個代替,它是面向每個命令的。

  • 特性:

(1) sudo能夠限制使用者只在某臺主機上執行某些命令。 (2)sudo提供了豐富的日誌,詳細地記錄了每個使用者幹了什麼。它能夠將日誌傳到中心主機或者日誌伺服器。 (3)sudo使用時間戳檔案來執行類似的“檢票”系統。當使用者呼叫sudo並且輸入它的密碼時,使用者獲得了一張存活期為5分鐘的票(這個值可以在編譯的時候改變)。 (4) sudo的配置檔案是sudoers檔案,它允許系統管理員集中的管理使用者的使用許可權和使用的主機。它所存放的位置預設是在/etc/sudoers,屬性必須為0440。

  • 命令原理:

sudo使一般使用者不需要知道超級使用者的密碼即可獲得許可權。首先超級使用者將普通使用者的名字、可以執行的特定命令、按照哪種使用者或使用者組的身份執行等資訊,登記在特殊的檔案中(通常是/etc/sudoers),即完成對該使用者的授權(此時該使用者稱為“sudoer”);在一般使用者需要取得特殊許可權時,其可在命令前加上“sudo”,此時sudo將會詢問該使用者自己的密碼(以確認終端機前的是該使用者本人),回答後系統即會將該命令的程式以超級使用者的許可權執行。之後的一段時間內(預設為5分鐘,可在/etc/sudoers自定義),使用sudo不需要再次輸入密碼。

  • 語法:

sudo [ -Vhl LvkKsHPSb ] │ [ -p prompt ] [ -c class│- ] [ -a auth_type ] [-u username│#uid ] command

  • 引數:
可選引數 作用
-V 顯示版本編號
-h 會顯示版本編號及指令的使用方式說明
-l 顯示出自己(執行 sudo 的使用者)的許可權
-v 因為 sudo 在第一次執行時或是在 N 分鐘內沒有執行(N 預設為五)會問密碼,這個引數是重新做一次確認,如果超過 N 分鐘,也會問密碼
-k 將會強迫使用者在下一次執行 sudo 時問密碼(不論有沒有超過 N 分鐘)
-b 將要執行的指令放在背景執行
-p prompt 可以更改問密碼的提示語,其中 %u 會代換為使用者的帳號名稱, %h 會顯示主機名稱
-u username/#uid 不加此引數,代表要以 root 的身份執行指令,而加了此引數,可以以 username 的身份執行指令(#uid 為該 username 的使用者號碼)
-s 執行環境變數中的 SHELL 所指定的 shell ,或是 /etc/passwd 裡所指定的 shell
-H 將環境變數中的 HOME (家目錄)指定為要變更身份的使用者家目錄(如不加 -u 引數就是系統管理者 root )
command 要以系統管理者身份(或以 -u 更改為其他人)執行的指令
  • sudo -i 切換使用者身份到root

1.1.16 pkg-config : 配置環境變數

  • pkgconfig有什麼用: 大家應該都知道用第三方庫,就少不了要使用到第三方的標頭檔案和庫檔案。我們在編譯、連結的時候,必須要指定這些標頭檔案和庫檔案的位置。 對於一個比較大第三方庫,其標頭檔案和庫檔案的數量是比較多的。如果我們一個個手動地寫,那將是相當麻煩的。所以,pkg-config就應運而生了。pkg-config能夠把這些標頭檔案和庫檔案的位置指出來,給編譯器使用。如果你的系統裝有gtk,可以嘗試一下下面的命令pkg-config --cflags gtk+-2.0。可以看到其輸出是gtk的標頭檔案的路徑。
      我們平常都是這樣用pkg-config的。gcc main.c pkg-config --cflags --libs gtk+-2.0 -o main 上面的編譯命令中,pkg-config --cflags --libs gtk+-2.0的作用就如前面所說的,把gtk的標頭檔案路徑和庫檔案列出來,讓編譯去獲取。--cflags和--libs分別指定標頭檔案和庫檔案。 Ps:命令中的`不是引號,而是數字1左邊那個鍵位的那個符號。 其實,pkg-config同其他命令一樣,有很多選項,不過我們一般只會用到--libs和--cflags選項。更多的選項可以在這裡檢視。

  • 配置環境變數

首先要明確一點,因為pkg-config也只是一個命令,所以不是你安裝了一個第三方的庫,pkg-config就能知道第三方庫的標頭檔案和庫檔案所在的位置。pkg-config命令是通過查詢XXX.pc檔案而知道這些的。我們所需要做的是,寫一個屬於自己的庫的.pc檔案。 但pkg-config又是如何找到所需的.pc檔案呢?這就需要用到一個環境變數PKG_CONFIG_PATH了。這環境變數寫明.pc檔案的路徑,pkg-config命令會讀取這個環境變數的內容,這樣就知道pc檔案了。 對於Ubuntu系統,可以用root許可權開啟/etc/bash.bashrc檔案。在最後輸入下面的內容。

這樣,pkg-config就會去/usr/local/lib/pkgconfig目錄下,尋找.pc檔案了。如果不是Ubuntu系統,那就沒有/etc/bash.bashrc檔案,可以參考我的一篇博文,來找到一個合適的檔案,修改這個環境變數。輸入bash命令使得配置生效。 現在pkg-config能找到我們的.pc檔案。但如果有多個.pc檔案,那麼pkg-config又怎麼能正確找到我想要的那個呢?這就需要我們在使用pkg-config命令的時候去指定。比如$gcc main.c pkg-config --cflags --libs gtk+-2.0 -o main就指定了要查詢的.pc檔案是gtk+-2.0.pc。又比如,有第三方庫OpenCV,而且其對應的pc檔案為opencv.pc,那麼我們在使用的時候,就要這樣寫pkg-config --cflags --libs opencv。這樣,pkg-config才會去找opencv.pc檔案。

  • *.pc檔案的編寫:

首先要明確一點,因為pkg-config也只是一個命令,所以不是你安裝了一個第三方的庫,pkg-config就能知道第三方庫的標頭檔案和庫檔案所在的位置。pkg-config命令是通過查詢XXX.pc檔案而知道這些的。我們所需要做的是,寫一個屬於自己的庫的.pc檔案。

如下展示hyperscan開源庫中的libhs.pc檔案的撰寫:

[root@localhost pkgconfig]# ls
libhs.pc
[root@localhost pkgconfig]# 
[root@localhost pkgconfig]# 
[root@localhost pkgconfig]# cat libhs.pc 
prefix=/usr/local
exec_prefix=/usr/local
libdir=/usr/local/lib
includedir=/usr/local/include

Name: libhs
Description: Intel(R) Hyperscan Library
Version: 4.5.0
Libs: -L${libdir} -lhs
Libs.private:  -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
Cflags: -I${includedir}/hs
[root@localhost pkgconfig]#
複製程式碼
  • 設定pkg-config的環境變數:

pkg-config又是如何找到所需的.pc檔案呢?這就需要用到一個環境變數PKG_CONFIG_PATH了。這環境變數寫明.pc檔案的路徑,pkg-config命令會讀取這個環境變數的內容,這樣就知道pc檔案了。

 export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
複製程式碼

將環境變數增加到.bashrc指令碼檔案中:

 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig
export PKG_CONFIG_PATH
 source .bashrc
複製程式碼
  • pkg-config的查詢結果:
[root@localhost pkgconfig]# pkg-config --cflags --libs libhs
 -I/usr/local/include/hs  -L/usr/local/lib -lhs  
 [root@localhost pkgconfig]# 
複製程式碼
  • 在指令碼和編譯的命令列中使用pkg-config的查詢結果:
[root@localhost examples]# g++ -o simplegrep simplegrep.c $(pkg-config --cflags --libs libhs)     
[root@localhost examples]# 
[root@localhost examples]# echo $(pkg-config --cflags --libs libhs)
-I/usr/local/include/hs -L/usr/local/lib -lhs
[root@localhost examples]# ls
CMakeFiles           CMakeLists.txt  patbench.cc  README.md   simplegrep.c
cmake_install.cmake  Makefile        pcapscan.cc  simplegrep
[root@localhost examples]#
複製程式碼

1.2 Vim編輯器

Vim是從 vi 發展出來的一個文字編輯器。程式碼補完、編譯及錯誤跳轉等方便程式設計的功能特別豐富,在程式設計師中被廣泛使用。 簡單的來說, vi 是老式的字處理器,不過功能已經很齊全了,但是還是有可以進步的地方。 vim 則可以說是程式開發者的一項很好用的工具。 連 vim 的官方網站 (www.vim.org) 自己也說 vim 是一個程式開發工具而不是文書處理軟體。

如果你熟練了Vim後,你的工作效率會大大提高,就像你學會了五筆去打漢字一樣。

下面有一種業界廣為流傳的vim鍵盤圖:

vim鍵盤圖

基本上 vi/vim 共分為三種模式,分別是命令模式(Command mode),輸入模式(Insert mode)和底線命令模式(Last line mode)。 這三種模式的作用分別是:

  1. esc:切換到到命令模式
  2. i : 切換到輸入模式/編輯模式
  3. : :切換到底線命令模式 q 退出程式 w 儲存檔案 qi 強制退出

這三種模式之間的關係如下圖:

三種模式之間的關係

2. FFmpeg原始碼下載

FFmpeg原始碼下載肯定是優先去官網下載:官網 ffmpeg.org/download.ht…

開啟官網如下:

官網下載原始碼

可以選擇直接下載,或者git命令直接克隆一份,作為開發人員一般都喜歡選擇git克隆的方式,這樣方便後續更新。

3. FFmpeg編譯,安裝

3.1 在Mac下編譯安裝FFmpeg

3.1.1 brew 方式安裝

在mac下面可以很方便的使用brew install ffmpeg命令直接安裝ffmpeg,如果是新手這樣安裝比較方便快捷,但是這麼安裝有個弊端就是不能定製化,如果隨著你對FFmpeg的深入,你需要使用一些其他的工具,就需要手動編譯安裝了,通過原始碼編譯的方式,我們可以自己選擇定製化。

我們可以先輸入brew search ffmpeg

搜尋ffmpeg

3.1.2 原始碼編譯 方式安裝

首先需要下載ffmpeg,從官網http://ffmpeg.org/download.html下載

然後是編譯ffmpeg 只需要執行下面3條命令即可:

  1. ./configure -prefix=/usr/local/ffmpeg -enable-debug=3
  2. make -j 4
  3. make install

接下來我們分別執行這3條語句:

  • 執行./configure --prefix=/usr/local/ffmpeg --enable-debug=3 一般我們預設安裝在/usr/local/ffmpeg路徑下,這個路徑可以自由設定,這裡我們需要開啟debug功能,後面要用到

我們下看看我們下載好的原始碼目錄

看看我們下載好的原始碼目錄
你也可以使用./configure --help 來檢視怎麼配置

會列印如下所有選項:

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Help options:
  --help                   print this message
  --quiet                  Suppress showing informative output
  --list-decoders          show all available decoders
  --list-encoders          show all available encoders
  --list-hwaccels          show all available hardware accelerators
  --list-demuxers          show all available demuxers
  --list-muxers            show all available muxers
  --list-parsers           show all available parsers
  --list-protocols         show all available protocols
  --list-bsfs              show all available bitstream filters
  --list-indevs            show all available input devices
  --list-outdevs           show all available output devices
  --list-filters           show all available filters

Standard options:
  --logfile=FILE           log tests and output to FILE [ffbuild/config.log]
  --disable-logging        do not log configure debug information
  --fatal-warnings         fail if any configure warning is generated
  --prefix=PREFIX          install in PREFIX [/usr/local]
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
  --docdir=DIR             install documentation in DIR [PREFIX/share/doc/ffmpeg]
  --libdir=DIR             install libs in DIR [PREFIX/lib]
  --shlibdir=DIR           install shared libs in DIR [LIBDIR]
  --incdir=DIR             install includes in DIR [PREFIX/include]
  --mandir=DIR             install man page in DIR [PREFIX/share/man]
  --pkgconfigdir=DIR       install pkg-config files in DIR [LIBDIR/pkgconfig]
  --enable-rpath           use rpath to allow installing libraries in paths
                           not part of the dynamic linker search path
                           use rpath when linking programs (USE WITH CARE)
  --install-name-dir=DIR   Darwin directory name for installed targets

Licensing options:
  --enable-gpl             allow use of GPL code,the resulting libs
                           and binaries will be under GPL [no]
  --enable-version3        upgrade (L)GPL to version 3 [no]
  --enable-nonfree         allow use of nonfree code,the resulting libs
                           and binaries will be unredistributable [no]

Configuration options:
  --disable-static         do not build static libraries [no]
  --enable-shared          build shared libraries [no]
  --enable-small           optimize for size instead of speed
  --disable-runtime-cpudetect disable detecting CPU capabilities at runtime (smaller binary)
  --enable-gray            enable full grayscale support (slower color)
  --disable-swscale-alpha  disable alpha channel support in swscale
  --disable-all            disable building components,libraries and programs
  --disable-autodetect     disable automatically detected external libraries [no]

Program options:
  --disable-programs       do not build command line programs
  --disable-ffmpeg         disable ffmpeg build
  --disable-ffplay         disable ffplay build
  --disable-ffprobe        disable ffprobe build

Documentation options:
  --disable-doc            do not build documentation
  --disable-htmlpages      do not build HTML documentation pages
  --disable-manpages       do not build man documentation pages
  --disable-podpages       do not build POD documentation pages
  --disable-txtpages       do not build text documentation pages

Component options:
  --disable-avdevice       disable libavdevice build
  --disable-avcodec        disable libavcodec build
  --disable-avformat       disable libavformat build
  --disable-swresample     disable libswresample build
  --disable-swscale        disable libswscale build
  --disable-postproc       disable libpostproc build
  --disable-avfilter       disable libavfilter build
  --enable-avresample      enable libavresample build (deprecated) [no]
  --disable-pthreads       disable pthreads [autodetect]
  --disable-w32threads     disable Win32 threads [autodetect]
  --disable-os2threads     disable OS/2 threads [autodetect]
  --disable-network        disable network support [no]
  --disable-dct            disable DCT code
  --disable-dwt            disable DWT code
  --disable-error-resilience disable error resilience code
  --disable-lsp            disable LSP code
  --disable-lzo            disable LZO decoder code
  --disable-mdct           disable MDCT code
  --disable-rdft           disable RDFT code
  --disable-fft            disable FFT code
  --disable-faan           disable floating point AAN (I)DCT code
  --disable-pixelutils     disable pixel utils in libavutil

Individual component options:
  --disable-everything     disable all components listed below
  --disable-encoder=NAME   disable encoder NAME
  --enable-encoder=NAME    enable encoder NAME
  --disable-encoders       disable all encoders
  --disable-decoder=NAME   disable decoder NAME
  --enable-decoder=NAME    enable decoder NAME
  --disable-decoders       disable all decoders
  --disable-hwaccel=NAME   disable hwaccel NAME
  --enable-hwaccel=NAME    enable hwaccel NAME
  --disable-hwaccels       disable all hwaccels
  --disable-muxer=NAME     disable muxer NAME
  --enable-muxer=NAME      enable muxer NAME
  --disable-muxers         disable all muxers
  --disable-demuxer=NAME   disable demuxer NAME
  --enable-demuxer=NAME    enable demuxer NAME
  --disable-demuxers       disable all demuxers
  --enable-parser=NAME     enable parser NAME
  --disable-parser=NAME    disable parser NAME
  --disable-parsers        disable all parsers
  --enable-bsf=NAME        enable bitstream filter NAME
  --disable-bsf=NAME       disable bitstream filter NAME
  --disable-bsfs           disable all bitstream filters
  --enable-protocol=NAME   enable protocol NAME
  --disable-protocol=NAME  disable protocol NAME
  --disable-protocols      disable all protocols
  --enable-indev=NAME      enable input device NAME
  --disable-indev=NAME     disable input device NAME
  --disable-indevs         disable input devices
  --enable-outdev=NAME     enable output device NAME
  --disable-outdev=NAME    disable output device NAME
  --disable-outdevs        disable output devices
  --disable-devices        disable all devices
  --enable-filter=NAME     enable filter NAME
  --disable-filter=NAME    disable filter NAME
  --disable-filters        disable all filters

External library support:

  Using any of the following switches will allow FFmpeg to link to the
  corresponding external library. All the components depending on that library
  will become enabled,if all their other dependencies are met and they are not
  explicitly disabled. E.g. --enable-libwavpack will enable linking to
  libwavpack and allow the libwavpack encoder to be built,unless it is
  specifically disabled with --disable-encoder=libwavpack.

  Note that only the system libraries are auto-detected. All the other external
  libraries must be explicitly enabled.

  Also note that the following help text describes the purpose of the libraries
  themselves,not all their features will necessarily be usable by FFmpeg.

  --disable-alsa           disable ALSA support [autodetect]
  --disable-appkit         disable Apple AppKit framework [autodetect]
  --disable-avfoundation   disable Apple AVFoundation framework [autodetect]
  --enable-avisynth        enable reading of AviSynth script files [no]
  --disable-bzlib          disable bzlib [autodetect]
  --disable-coreimage      disable Apple CoreImage framework [autodetect]
  --enable-chromaprint     enable audio fingerprinting with chromaprint [no]
  --enable-frei0r          enable frei0r video filtering [no]
  --enable-gcrypt          enable gcrypt,needed for rtmp(t)e support
                           if openssl,librtmp or gmp is not used [no]
  --enable-gmp             enable gmp,needed for rtmp(t)e support
                           if openssl or librtmp is not used [no]
  --enable-gnutls          enable gnutls,needed for https support
                           if openssl,libtls or mbedtls is not used [no]
  --disable-iconv          disable iconv [autodetect]
  --enable-jni             enable JNI support [no]
  --enable-ladspa          enable LADSPA audio filtering [no]
  --enable-libaom          enable AV1 video encoding/decoding via libaom [no]
  --enable-libaribb24      enable ARIB text and caption decoding via libaribb24 [no]
  --enable-libass          enable libass subtitles rendering,needed for subtitles and ass filter [no]
  --enable-libbluray       enable BluRay reading using libbluray [no]
  --enable-libbs2b         enable bs2b DSP library [no]
  --enable-libcaca         enable textual display using libcaca [no]
  --enable-libcelt         enable CELT decoding via libcelt [no]
  --enable-libcdio         enable audio CD grabbing with libcdio [no]
  --enable-libcodec2       enable codec2 en/decoding using libcodec2 [no]
  --enable-libdav1d        enable AV1 decoding via libdav1d [no]
  --enable-libdavs2        enable AVS2 decoding via libdavs2 [no]
  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                           and libraw1394 [no]
  --enable-libfdk-aac      enable AAC de/encoding via libfdk-aac [no]
  --enable-libflite        enable flite (voice synthesis) support via libflite [no]
  --enable-libfontconfig   enable libfontconfig,useful for drawtext filter [no]
  --enable-libfreetype     enable libfreetype,needed for drawtext filter [no]
  --enable-libfribidi      enable libfribidi,improves drawtext filter [no]
  --enable-libglslang      enable GLSL->SPIRV compilation via libglslang [no]
  --enable-libgme          enable Game Music Emu via libgme [no]
  --enable-libgsm          enable GSM de/encoding via libgsm [no]
  --enable-libiec61883     enable iec61883 via libiec61883 [no]
  --enable-libilbc         enable iLBC de/encoding via libilbc [no]
  --enable-libjack         enable JACK audio sound server [no]
  --enable-libklvanc       enable Kernel Labs VANC processing [no]
  --enable-libkvazaar      enable HEVC encoding via libkvazaar [no]
  --enable-liblensfun      enable lensfun lens correction [no]
  --enable-libmodplug      enable ModPlug via libmodplug [no]
  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
  --enable-libopencv       enable video filtering via libopencv [no]
  --enable-libopenh264     enable H.264 encoding via OpenH264 [no]
  --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
  --enable-libopenmpt      enable decoding tracked files via libopenmpt [no]
  --enable-libopus         enable Opus de/encoding via libopus [no]
  --enable-libpulse        enable Pulseaudio input via libpulse [no]
  --enable-librabbitmq     enable RabbitMQ library [no]
  --enable-librav1e        enable AV1 encoding via rav1e [no]
  --enable-librsvg         enable SVG rasterization via librsvg [no]
  --enable-librubberband   enable rubberband needed for rubberband filter [no]
  --enable-librtmp         enable RTMP[E] support via librtmp [no]
  --enable-libshine        enable fixed-point MP3 encoding via libshine [no]
  --enable-libsmbclient    enable Samba protocol via libsmbclient [no]
  --enable-libsnappy       enable Snappy compression,needed for hap encoding [no]
  --enable-libsoxr         enable Include libsoxr resampling [no]
  --enable-libspeex        enable Speex de/encoding via libspeex [no]
  --enable-libsrt          enable Haivision SRT protocol via libsrt [no]
  --enable-libssh          enable SFTP protocol via libssh [no]
  --enable-libtensorflow   enable TensorFlow as a DNN module backend
                           for DNN based filters like sr [no]
  --enable-libtesseract    enable Tesseract,needed for ocr filter [no]
  --enable-libtheora       enable Theora encoding via libtheora [no]
  --enable-libtls          enable LibreSSL (via libtls),gnutls or mbedtls is not used [no]
  --enable-libtwolame      enable MP2 encoding via libtwolame [no]
  --enable-libv4l2         enable libv4l2/v4l-utils [no]
  --enable-libvidstab      enable video stabilization using vid.stab [no]
  --enable-libvmaf         enable vmaf filter via libvmaf [no]
  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,native implementation exists [no]
  --enable-libvpx          enable VP8 and VP9 de/encoding via libvpx [no]
  --enable-libwavpack      enable wavpack encoding via libwavpack [no]
  --enable-libwebp         enable WebP encoding via libwebp [no]
  --enable-libx264         enable H.264 encoding via x264 [no]
  --enable-libx265         enable HEVC encoding via x265 [no]
  --enable-libxavs         enable AVS encoding via xavs [no]
  --enable-libxavs2        enable AVS2 encoding via xavs2 [no]
  --enable-libxcb          enable X11 grabbing using XCB [autodetect]
  --enable-libxcb-shm      enable X11 grabbing shm communication [autodetect]
  --enable-libxcb-xfixes   enable X11 grabbing mouse rendering [autodetect]
  --enable-libxcb-shape    enable X11 grabbing shape rendering [autodetect]
  --enable-libxvid         enable Xvid encoding via xvidcore,native MPEG-4/Xvid encoder exists [no]
  --enable-libxml2         enable XML parsing using the C library libxml2,needed
                           for dash demuxing support [no]
  --enable-libzimg         enable z.lib,needed for zscale filter [no]
  --enable-libzmq          enable message passing via libzmq [no]
  --enable-libzvbi         enable teletext support via libzvbi [no]
  --enable-lv2             enable LV2 audio filtering [no]
  --disable-lzma           disable lzma [autodetect]
  --enable-decklink        enable Blackmagic DeckLink I/O support [no]
  --enable-mbedtls         enable mbedTLS,gnutls or libtls is not used [no]
  --enable-mediacodec      enable Android MediaCodec support [no]
  --enable-libmysofa       enable libmysofa,needed for sofalizer filter [no]
  --enable-openal          enable OpenAL 1.1 capture support [no]
  --enable-opencl          enable OpenCL processing [no]
  --enable-opengl          enable OpenGL rendering [no]
  --enable-openssl         enable openssl,needed for https support
                           if gnutls,libtls or mbedtls is not used [no]
  --enable-pocketsphinx    enable PocketSphinx,needed for asr filter [no]
  --disable-sndio          disable sndio support [autodetect]
  --disable-schannel       disable SChannel SSP,needed for TLS support on
                           Windows if openssl and gnutls are not used [autodetect]
  --disable-sdl2           disable sdl2 [autodetect]
  --disable-securetransport disable Secure Transport,needed for TLS support
                           on OSX if openssl and gnutls are not used [autodetect]
  --enable-vapoursynth     enable VapourSynth demuxer [no]
  --enable-vulkan          enable Vulkan code [no]
  --disable-xlib           disable xlib [autodetect]
  --disable-zlib           disable zlib [autodetect]

  The following libraries provide various hardware acceleration features:
  --disable-amf            disable AMF video encoding code [autodetect]
  --disable-audiotoolbox   disable Apple AudioToolbox code [autodetect]
  --enable-cuda-nvcc       enable Nvidia CUDA compiler [no]
  --disable-cuda-llvm      disable CUDA compilation using clang [autodetect]
  --disable-cuvid          disable Nvidia CUVID support [autodetect]
  --disable-d3d11va        disable Microsoft Direct3D 11 video acceleration code [autodetect]
  --disable-dxva2          disable Microsoft DirectX 9 video acceleration code [autodetect]
  --disable-ffnvcodec      disable dynamically linked Nvidia code [autodetect]
  --enable-libdrm          enable DRM code (Linux) [no]
  --enable-libmfx          enable Intel MediaSDK (AKA Quick Sync Video) code via libmfx [no]
  --enable-libnpp          enable Nvidia Performance Primitives-based code [no]
  --enable-mmal            enable Broadcom Multi-Media Abstraction Layer (Raspberry Pi) via MMAL [no]
  --disable-nvdec          disable Nvidia video decoding acceleration (via hwaccel) [autodetect]
  --disable-nvenc          disable Nvidia video encoding code [autodetect]
  --enable-omx             enable OpenMAX IL code [no]
  --enable-omx-rpi         enable OpenMAX IL code for Raspberry Pi [no]
  --enable-rkmpp           enable Rockchip Media Process Platform code [no]
  --disable-v4l2-m2m       disable V4L2 mem2mem code [autodetect]
  --disable-vaapi          disable Video Acceleration API (mainly Unix/Intel) code [autodetect]
  --disable-vdpau          disable Nvidia Video Decode and Presentation API for Unix code [autodetect]
  --disable-videotoolbox   disable VideoToolbox code [autodetect]

Toolchain options:
  --arch=ARCH              select architecture []
  --cpu=CPU                select the minimum required CPU (affects
                           instruction selection,may crash on older CPUs)
  --cross-prefix=PREFIX    use PREFIX for compilation tools []
  --progs-suffix=SUFFIX    program name suffix []
  --enable-cross-compile   assume a cross-compiler is used
  --sysroot=PATH           root of cross-build tree
  --sysinclude=PATH        location of cross-build system headers
  --target-os=OS           compiler targets OS []
  --target-exec=CMD        command to run executables on target
  --target-path=DIR        path to view of build directory on target
  --target-samples=DIR     path to samples directory on target
  --tempprefix=PATH        force fixed dir/prefix instead of mktemp for checks
  --toolchain=NAME         set tool defaults according to NAME
                           (gcc-asan,clang-asan,gcc-msan,clang-msan,gcc-tsan,clang-tsan,gcc-usan,clang-usan,valgrind-massif,valgrind-memcheck,msvc,icl,gcov,llvm-cov,hardened)
  --nm=NM                  use nm tool NM [nm -g]
  --ar=AR                  use archive tool AR [ar]
  --as=AS                  use assembler AS []
  --ln_s=LN_S              use symbolic link tool LN_S [ln -s -f]
  --strip=STRIP            use strip tool STRIP [strip]
  --windres=WINDRES        use windows resource compiler WINDRES [windres]
  --x86asmexe=EXE          use nasm-compatible assembler EXE [nasm]
  --cc=CC                  use C compiler CC [gcc]
  --cxx=CXX                use C compiler CXX [g++]
  --objcc=OCC              use ObjC compiler OCC [gcc]
  --dep-cc=DEPCC           use dependency generator DEPCC [gcc]
  --nvcc=NVCC              use Nvidia CUDA compiler NVCC or clang []
  --ld=LD                  use linker LD []
  --pkg-config=PKGCONFIG   use pkg-config tool PKGCONFIG [pkg-config]
  --pkg-config-flags=FLAGS pass additional flags to pkgconf []
  --ranlib=RANLIB          use ranlib RANLIB [ranlib]
  --doxygen=DOXYGEN        use DOXYGEN to generate API doc [doxygen]
  --host-cc=HOSTCC         use host C compiler HOSTCC
  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
  --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host
  --host-ld=HOSTLD         use host linker HOSTLD
  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
  --host-extralibs=HLIBS   use libs HLIBS when linking for host
  --host-os=OS             compiler host OS []
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS []
  --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS []
  --extra-objcflags=FLAGS  add FLAGS to OBJCFLAGS []
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS []
  --extra-ldexeflags=ELDFLAGS add ELDFLAGS to LDEXEFLAGS []
  --extra-ldsoflags=ELDFLAGS add ELDFLAGS to LDSOFLAGS []
  --extra-libs=ELIBS       add ELIBS []
  --extra-version=STRING   version string suffix []
  --optflags=OPTFLAGS      override optimization-related compiler flags
  --nvccflags=NVCCFLAGS    override nvcc flags []
  --build-suffix=SUFFIX    library name suffix []
  --enable-pic             build position-independent code
  --enable-thumb           compile for Thumb instruction set
  --enable-lto             use link-time optimization
  --env="ENV=override"     override the environment variables

Advanced options (experts only):
  --malloc-prefix=PREFIX   prefix malloc and related names with PREFIX
  --custom-allocator=NAME  use a supported custom allocator
  --disable-symver         disable symbol versioning
  --enable-hardcoded-tables use hardcoded tables instead of runtime generation
  --disable-safe-bitstream-reader
                           disable buffer boundary checking in bitreaders
                           (faster,but may crash)
  --sws-max-filter-size=N  the max filter size swscale uses [256]

Optimization options (experts only):
  --disable-asm            disable all assembly optimizations
  --disable-altivec        disable AltiVec optimizations
  --disable-vsx            disable VSX optimizations
  --disable-power8         disable POWER8 optimizations
  --disable-amd3dnow       disable 3DNow! optimizations
  --disable-amd3dnowext    disable 3DNow! extended optimizations
  --disable-mmx            disable MMX optimizations
  --disable-mmxext         disable MMXEXT optimizations
  --disable-sse            disable SSE optimizations
  --disable-sse2           disable SSE2 optimizations
  --disable-sse3           disable SSE3 optimizations
  --disable-ssse3          disable SSSE3 optimizations
  --disable-sse4           disable SSE4 optimizations
  --disable-sse42          disable SSE4.2 optimizations
  --disable-avx            disable AVX optimizations
  --disable-xop            disable XOP optimizations
  --disable-fma3           disable FMA3 optimizations
  --disable-fma4           disable FMA4 optimizations
  --disable-avx2           disable AVX2 optimizations
  --disable-avx512         disable AVX-512 optimizations
  --disable-aesni          disable AESNI optimizations
  --disable-armv5te        disable armv5te optimizations
  --disable-armv6          disable armv6 optimizations
  --disable-armv6t2        disable armv6t2 optimizations
  --disable-vfp            disable VFP optimizations
  --disable-neon           disable NEON optimizations
  --disable-inline-asm     disable use of inline assembly
  --disable-x86asm         disable use of standalone x86 assembly
  --disable-mipsdsp        disable MIPS DSP ASE R1 optimizations
  --disable-mipsdspr2      disable MIPS DSP ASE R2 optimizations
  --disable-msa            disable MSA optimizations
  --disable-msa2           disable MSA2 optimizations
  --disable-mipsfpu        disable floating point MIPS optimizations
  --disable-mmi            disable Loongson SIMD optimizations
  --disable-fast-unaligned consider unaligned accesses slow

Developer options (useful when working on FFmpeg itself):
  --disable-debug          disable debugging symbols
  --enable-debug=LEVEL     set the debug level []
  --disable-optimizations  disable compiler optimizations
  --enable-extra-warnings  enable more compiler warnings
  --disable-stripping      disable stripping of executables and shared libraries
  --assert-level=level     0(default),1 or 2,amount of assertion testing,2 causes a slowdown at runtime.
  --enable-memory-poisoning fill heap uninitialized allocated space with arbitrary data
  --valgrind=VALGRIND      run "make fate" tests through valgrind to detect memory
                           leaks and errors,using the specified valgrind binary.
                           Cannot be combined with --target-exec
  --enable-ftrapv          Trap arithmetic overflows
  --samples=PATH           location of test samples for FATE,if not set use
                           $FATE_SAMPLES at make invocation time.
  --enable-neon-clobber-test check NEON registers for clobbering (should be
                           used only for debugging purposes)
  --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
                           should be used only for debugging purposes)
  --enable-random          randomly enable/disable components
  --disable-random
  --enable-random=LIST     randomly enable/disable specific components or
  --disable-random=LIST    component groups. LIST is a comma-separated list
                           of NAME[:PROB] entries where NAME is a component
                           (group) and PROB the probability associated with
                           NAME (default 0.5).
  --random-seed=VALUE      seed value for --enable/disable-random
  --disable-valgrind-backtrace do not print a backtrace under Valgrind
                           (only applies to --disable-optimizations builds)
  --enable-ossfuzz         Enable building fuzzer tool
  --libfuzzer=PATH         path to libfuzzer
  --ignore-tests=TESTS     comma-separated list (without "fate-" prefix
                           in the name) of tests whose result is ignored
  --enable-linux-perf      enable Linux Performance Monitor API
  --disable-large-tests    disable tests that use a large amount of memory

NOTE: Object files are built at the place where configure is launched.
複製程式碼

上面包括了很多配置引數,隨著我們對ffmpeg的深入,我們也會慢慢了解這些配置引數,剛開始我們只需要知道我們關心的就好了。

例如我們不記得了禁止編譯static怎麼寫的,我們這樣查詢一下:

./configure --help | grep static
複製程式碼

查詢禁止編譯static怎麼寫的

同樣我們可以查詢一下share相關的

./configure --help | grep share
複製程式碼

查詢一下share
這裡我設定configure時禁止編譯靜態庫,開啟動態庫,如下:

設定configure
執行

./configure --prefix=/usr/local/ffmpeg --enable-debug=3 --enable-shared --disable-static
複製程式碼

輸入上面命令後回車,會等待一段時間,這個時候指令碼在查詢系統所有匹配的庫,如果有不匹配的會有提示,如下圖,我的配置會報一個錯誤:

配置會報一個錯誤
由於我的電腦沒有安裝yasm庫,所以需要先安裝一下:

安裝yasm編譯器。安裝方法如下:

  1. 下載:yasm的下載連結
  2. 解壓:把下載下來的壓縮包進行解壓
  3. 切換路徑: cd yasm-1.3.0
  4. 執行配置: ./configure
  5. 編譯:make
  6. 安裝:make install(提示:Permission denied,就執行sudo make install)

下面我們下來安裝yasm編譯器 (1)下載:yasm的下載連結 如果上面的連結下載比較慢,可以從我的百度雲盤下載: 連結:pan.baidu.com/s/1oGMcX4HY… 密碼:m1k2

下載yasm編譯器
(2) 解壓,這裡需要用到本篇部落格開篇的準備知識的解壓命令tar -zxvf yasm-1.3.0.tar

tar -zxvf yasm-1.3.0.tar
複製程式碼

解壓檔案

(3)切換路徑: cd yasm-1.3.0

切換路徑
(4)執行配置: ./configure
執行配置
(5)編譯:make
執行編譯
(6)安裝:make install(提示:Permission denied,就執行sudo make install)
執行安裝
執行安裝2

安裝了yasm編譯器後,我們從新執行一下configure配置:

./configure --prefix=/usr/local/ffmpeg --enable-debug=3 --enable-shared --disable-static
複製程式碼

如果沒有報錯,則會列印了下面資訊:

 ✘ apple@kongyulu  ~/development/study/ffmpeg/ffmpeg/ffmpeg   master./configure --prefix=/usr/local/ffmpeg --enable-debug=3 --enable-shared --disable-static
install prefix            /usr/local/ffmpeg
source path               .
C compiler                gcc
C library
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             yasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    no
shared                    yes
postprocessing support    no
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          yes
makeinfo supports HTML    no

External libraries:
appkit                  bzlib                   iconv                   securetransport
avfoundation            coreimage               lzma                    zlib

External libraries providing hardware acceleration:
audiotoolbox            videotoolbox

Libraries:
avcodec                 avfilter                avutil                  swscale
avdevice                avformat                swresample

Programs:
ffmpeg                  ffprobe

Enabled decoders:
aac                     cscd                    mp1float                rv40
aac_at                  cyuv                    mp2                     s302m
aac_fixed               dca                     mp2_at                  sami
aac_latm                dds                     mp2float                sanm
aasc                    derf_dpcm               mp3                     sbc
ac3                     dfa                     mp3_at                  scpr
ac3_at                  dirac                   mp3adu                  screenpresso
ac3_fixed               dnxhd                   mp3adufloat             sdx2_dpcm
acelp_kelvin            dolby_e                 mp3float                sgi
adpcm_4xm               dpx                     mp3on4                  sgirle
adpcm_adx               dsd_lsbf                mp3on4float             sheervideo
adpcm_afc               dsd_lsbf_planar         mpc7                    shorten
adpcm_agm               dsd_msbf                mpc8                    sipr
adpcm_aica              dsd_msbf_planar         mpeg1video              siren
adpcm_argo              dsicinaudio             mpeg2video              smackaud
adpcm_ct                dsicinvideo             mpeg4                   smacker
adpcm_dtk               dss_sp                  mpegvideo               smc
adpcm_ea                dst                     mpl2                    smvjpeg
adpcm_ea_maxis_xa       dvaudio                 msa1                    snow
adpcm_ea_r1             dvbsub                  mscc                    sol_dpcm
adpcm_ea_r2             dvdsub                  msmpeg4v1               sonic
adpcm_ea_r3             dvvideo                 msmpeg4v2               sp5x
adpcm_ea_xas            dxa                     msmpeg4v3               speedhq
adpcm_g722              dxtory                  msrle                   srgc
adpcm_g726              dxv                     mss1                    srt
adpcm_g726le            eac3                    mss2                    ssa
adpcm_ima_alp           eac3_at                 msvideo1                stl
adpcm_ima_amv           eacmv                   mszh                    subrip
adpcm_ima_apc           eamad                   mts2                    subviewer
adpcm_ima_apm           eatgq                   mv30                    subviewer1
adpcm_ima_cunning       eatgv                   mvc1                    sunrast
adpcm_ima_dat4          eatqi                   mvc2                    svq1
adpcm_ima_dk3           eightbps                mvdv                    svq3
adpcm_ima_dk4           eightsvx_exp            mvha                    tak
adpcm_ima_ea_eacs       eightsvx_fib            mwsc                    targa
adpcm_ima_ea_sead       escape124               mxpeg                   targa_y216
adpcm_ima_iss           escape130               nellymoser              tdsc
adpcm_ima_mtf           evrc                    nuv                     text
adpcm_ima_oki           exr                     on2avc                  theora
adpcm_ima_qt            ffv1                    opus                    thp
adpcm_ima_qt_at         ffvhuff                 paf_audio               tiertexseqvideo
adpcm_ima_rad           ffwavesynth             paf_video               tiff
adpcm_ima_smjpeg        fic                     pam                     tmv
adpcm_ima_ssi           fits                    pbm                     truehd
adpcm_ima_wav           flac                    pcm_alaw                truemotion1
adpcm_ima_ws            flashsv                 pcm_alaw_at             truemotion2
adpcm_ms                flashsv2                pcm_bluray              truemotion2rt
adpcm_mtaf              flic                    pcm_dvd                 truespeech
adpcm_psx               flv                     pcm_f16le               tscc
adpcm_sbpro_2           fmvc                    pcm_f24le               tscc2
adpcm_sbpro_3           fourxm                  pcm_f32be               tta
adpcm_sbpro_4           fraps                   pcm_f32le               twinvq
adpcm_swf               frwu                    pcm_f64be               txd
adpcm_thp               g2m                     pcm_f64le               ulti
adpcm_thp_le            g723_1                  pcm_lxf                 utvideo
adpcm_vima              g729                    pcm_mulaw               v210
adpcm_xa                gdv                     pcm_mulaw_at            v210x
adpcm_yamaha            gif                     pcm_s16be               v308
adpcm_zork              gremlin_dpcm            pcm_s16be_planar        v408
agm                     gsm                     pcm_s16le               v410
aic                     gsm_ms                  pcm_s16le_planar        vb
alac                    gsm_ms_at               pcm_s24be               vble
alac_at                 h261                    pcm_s24daud             vc1
alias_pix               h263                    pcm_s24le               vc1image
als                     h263i                   pcm_s24le_planar        vcr1
amr_nb_at               h263p                   pcm_s32be               vmdaudio
amrnb                   h264                    pcm_s32le               vmdvideo
amrwb                   hap                     pcm_s32le_planar        vmnc
amv                     hca                     pcm_s64be               vorbis
anm                     hcom                    pcm_s64le               vp3
ansi                    hevc                    pcm_s8                  vp4
ape                     hnm4_video              pcm_s8_planar           vp5
apng                    hq_hqa                  pcm_u16be               vp6
aptx                    hqx                     pcm_u16le               vp6a
aptx_hd                 huffyuv                 pcm_u24be               vp6f
arbc                    hymt                    pcm_u24le               vp7
ass                     iac                     pcm_u32be               vp8
asv1                    idcin                   pcm_u32le               vp9
asv2                    idf                     pcm_u8                  vplayer
atrac1                  iff_ilbm                pcm_vidc                vqa
atrac3                  ilbc                    pcx                     wavpack
atrac3al                ilbc_at                 pgm                     wcmv
atrac3p                 imc                     pgmyuv                  webp
atrac3pal               imm4                    pgssub                  webvtt
atrac9                  imm5                    pictor                  wmalossless
aura                    indeo2                  pixlet                  wmapro
aura2                   indeo3                  pjs                     wmav1
avrn                    indeo4                  png                     wmav2
avrp                    indeo5                  ppm                     wmavoice
avs                     interplay_acm           prores                  wmv1
avui                    interplay_dpcm          prosumer                wmv2
ayuv                    interplay_video         psd                     wmv3
bethsoftvid             jacosub                 ptx                     wmv3image
bfi                     jpeg2000                qcelp                   wnv1
bink                    jpegls                  qdm2                    wrapped_avframe
binkaudio_dct           jv                      qdm2_at                 ws_snd1
binkaudio_rdft          kgv1                    qdmc                    xan_dpcm
bintext                 kmvc                    qdmc_at                 xan_wc3
bitpacked               lagarith                qdraw                   xan_wc4
bmp                     loco                    qpeg                    xbin
bmv_audio               lscr                    qtrle                   xbm
bmv_video               m101                    r10k                    xface
brender_pix             mace3                   r210                    xl
c93                     mace6                   ra_144                  xma1
cavs                    magicyuv                ra_288                  xma2
ccaption                mdec                    ralf                    xpm
cdgraphics              metasound               rasc                    xsub
cdtoons                 microdvd                rawvideo                xwd
cdxl                    mimic                   realtext                y41p
cfhd                    mjpeg                   rl2                     ylc
cinepak                 mjpegb                  roq                     yop
clearvideo              mlp                     roq_dpcm                yuv4
cljr                    mmvideo                 rpza                    zero12v
cllc                    motionpixels            rscc                    zerocodec
comfortnoise            movtext                 rv10                    zlib
cook                    mp1                     rv20                    zmbv
cpia                    mp1_at                  rv30

Enabled encoders:
a64multi                fits                    pcm_mulaw_at            s302m
a64multi5               flac                    pcm_s16be               sbc
aac                     flashsv                 pcm_s16be_planar        sgi
aac_at                  flashsv2                pcm_s16le               snow
ac3                     flv                     pcm_s16le_planar        sonic
ac3_fixed               g723_1                  pcm_s24be               sonic_ls
adpcm_adx               gif                     pcm_s24daud             srt
adpcm_g722              h261                    pcm_s24le               ssa
adpcm_g726              h263                    pcm_s24le_planar        subrip
adpcm_g726le            h263p                   pcm_s32be               sunrast
adpcm_ima_qt            h264_videotoolbox       pcm_s32le               svq1
adpcm_ima_wav           hevc_videotoolbox       pcm_s32le_planar        targa
adpcm_ms                huffyuv                 pcm_s64be               text
adpcm_swf               ilbc_at                 pcm_s64le               tiff
adpcm_yamaha            jpeg2000                pcm_s8                  truehd
alac                    jpegls                  pcm_s8_planar           tta
alac_at                 ljpeg                   pcm_u16be               utvideo
alias_pix               magicyuv                pcm_u16le               v210
amv                     mjpeg                   pcm_u24be               v308
apng                    mlp                     pcm_u24le               v408
aptx                    movtext                 pcm_u32be               v410
aptx_hd                 mp2                     pcm_u32le               vc2
ass                     mp2fixed                pcm_u8                  vorbis
asv1                    mpeg1video              pcm_vidc                wavpack
asv2                    mpeg2video              pcx                     webvtt
avrp                    mpeg4                   pgm                     wmav1
avui                    msmpeg4v2               pgmyuv                  wmav2
ayuv                    msmpeg4v3               png                     wmv1
bmp                     msvideo1                ppm                     wmv2
cinepak                 nellymoser              prores                  wrapped_avframe
cljr                    opus                    prores_aw               xbm
comfortnoise            pam                     prores_ks               xface
dca                     pbm                     qtrle                   xsub
dnxhd                   pcm_alaw                r10k                    xwd
dpx                     pcm_alaw_at             r210                    y41p
dvbsub                  pcm_dvd                 ra_144                  yuv4
dvdsub                  pcm_f32be               rawvideo                zlib
dvvideo                 pcm_f32le               roq                     zmbv
eac3                    pcm_f64be               roq_dpcm
ffv1                    pcm_f64le               rv10
ffvhuff                 pcm_mulaw               rv20

Enabled hwaccels:
h263_videotoolbox       hevc_videotoolbox       mpeg2_videotoolbox
h264_videotoolbox       mpeg1_videotoolbox      mpeg4_videotoolbox

Enabled parsers:
aac                     dpx                     h264                    sbc
aac_latm                dvaudio                 hevc                    sipr
ac3                     dvbsub                  mjpeg                   tak
adx                     dvd_nav                 mlp                     vc1
av1                     dvdsub                  mpeg4video              vorbis
avs2                    flac                    mpegaudio               vp3
bmp                     g723_1                  mpegvideo               vp8
cavsvideo               g729                    opus                    vp9
cook                    gif                     png                     webp
dca                     gsm                     pnm                     xma
dirac                   h261                    rv30
dnxhd                   h263                    rv40

Enabled demuxers:
aa                      filmstrip               lrc                     rpl
aac                     fits                    lvf                     rsd
ac3                     flac                    lxf                     rso
acm                     flic                    m4v                     rtp
act                     flv                     matroska                rtsp
adf                     fourxm                  mgsts                   s337m
adp                     frm                     microdvd                sami
ads                     fsb                     mjpeg                   sap
adx                     fwse                    mjpeg_2000              sbc
aea                     g722                    mlp                     sbg
afc                     g723_1                  mlv                     scc
aiff                    g726                    mm                      sdp
aix                     g726le                  mmf                     sdr2
alp                     g729                    mov                     sds
amr                     gdv                     mp3                     sdx
amrnb                   genh                    mpc                     segafilm
amrwb                   gif                     mpc8                    ser
anm                     gsm                     mpegps                  shorten
apc                     gxf                     mpegts                  siff
ape                     h261                    mpegtsraw               sln
apm                     h263                    mpegvideo               smacker
apng                    h264                    mpjpeg                  smjpeg
aptx                    hca                     mpl2                    smush
aptx_hd                 hcom                    mpsub                   sol
aqtitle                 hevc                    msf                     sox
argo_asf                hls                     msnwc_tcp               spdif
asf                     hnm                     mtaf                    srt
asf_o                   ico                     mtv                     stl
ass                     idcin                   musx                    str
ast                     idf                     mv                      subviewer
au                      iff                     mvi                     subviewer1
av1                     ifv                     mxf                     sup
avi                     ilbc                    mxg                     svag
avr                     image2                  nc                      swf
avs                     image2_alias_pix        nistsphere              tak
avs2                    image2_brender_pix      nsp                     tedcaptions
bethsoftvid             image2pipe              nsv                     thp
bfi                     image_bmp_pipe          nut                     threedostr
bfstm                   image_dds_pipe          nuv                     tiertexseq
bink                    image_dpx_pipe          ogg                     tmv
bintext                 image_exr_pipe          oma                     truehd
bit                     image_gif_pipe          paf                     tta
bmv                     image_j2k_pipe          pcm_alaw                tty
boa                     image_jpeg_pipe         pcm_f32be               txd
brstm                   image_jpegls_pipe       pcm_f32le               ty
c93                     image_pam_pipe          pcm_f64be               v210
caf                     image_pbm_pipe          pcm_f64le               v210x
cavsvideo               image_pcx_pipe          pcm_mulaw               vag
cdg                     image_pgm_pipe          pcm_s16be               vc1
cdxl                    image_pgmyuv_pipe       pcm_s16le               vc1t
cine                    image_pictor_pipe       pcm_s24be               vividas
codec2                  image_png_pipe          pcm_s24le               vivo
codec2raw               image_ppm_pipe          pcm_s32be               vmd
concat                  image_psd_pipe          pcm_s32le               vobsub
data                    image_qdraw_pipe        pcm_s8                  voc
daud                    image_sgi_pipe          pcm_u16be               vpk
dcstr                   image_sunrast_pipe      pcm_u16le               vplayer
derf                    image_svg_pipe          pcm_u24be               vqf
dfa                     image_tiff_pipe         pcm_u24le               w64
dhav                    image_webp_pipe         pcm_u32be               wav
dirac                   image_xpm_pipe          pcm_u32le               wc3
dnxhd                   image_xwd_pipe          pcm_u8                  webm_dash_manifest
dsf                     ingenient               pcm_vidc                webvtt
dsicin                  ipmovie                 pjs                     wsaud
dss                     ircam                   pmp                     wsd
dts                     iss                     pp_bnk                  wsvqa
dtshd                   iv8                     pva                     wtv
dv                      ivf                     pvf                     wv
dvbsub                  ivr                     qcp                     wve
dvbtxt                  jacosub                 r3d                     xa
dxa                     jv                      rawvideo                xbin
ea                      kux                     realtext                xmv
ea_cdata                kvag                    redspark                xvag
eac3                    live_flv                rl2                     xwma
epaf                    lmlm4                   rm                      yop
ffmetadata              loas                    roq                     yuv4mpegpipe

Enabled muxers:
a64                     framemd5                mpeg1video              roq
ac3                     g722                    mpeg2dvd                rso
adts                    g723_1                  mpeg2svcd               rtp
adx                     g726                    mpeg2video              rtp_mpegts
aiff                    g726le                  mpeg2vob                rtsp
amr                     gif                     mpegts                  sap
apng                    gsm                     mpjpeg                  sbc
aptx                    gxf                     mxf                     scc
aptx_hd                 h261                    mxf_d10                 segafilm
asf                     h263                    mxf_opatom              segment
asf_stream              h264                    null                    singlejpeg
ass                     hash                    nut                     smjpeg
ast                     hds                     oga                     smoothstreaming
au                      hevc                    ogg                     sox
avi                     hls                     ogv                     spdif
avm2                    ico                     oma                     spx
avs2                    ilbc                    opus                    srt
bit                     image2                  pcm_alaw                stream_segment
caf                     image2pipe              pcm_f32be               streamhash
cavsvideo               ipod                    pcm_f32le               sup
codec2                  ircam                   pcm_f64be               swf
codec2raw               ismv                    pcm_f64le               tee
crc                     ivf                     pcm_mulaw               tg2
dash                    jacosub                 pcm_s16be               tgp
data                    latm                    pcm_s16le               truehd
daud                    lrc                     pcm_s24be               tta
dirac                   m4v                     pcm_s24le               uncodedframecrc
dnxhd                   matroska                pcm_s32be               vc1
dts                     matroska_audio          pcm_s32le               vc1t
dv                      md5                     pcm_s8                  voc
eac3                    microdvd                pcm_u16be               w64
f4v                     mjpeg                   pcm_u16le               wav
ffmetadata              mkvtimestamp_v2         pcm_u24be               webm
fifo                    mlp                     pcm_u24le               webm_chunk
fifo_test               mmf                     pcm_u32be               webm_dash_manifest
filmstrip               mov                     pcm_u32le               webp
fits                    mp2                     pcm_u8                  webvtt
flac                    mp3                     pcm_vidc                wtv
flv                     mp4                     psp                     wv
framecrc                mpeg1system             rawvideo                yuv4mpegpipe
framehash               mpeg1vcd                rm

Enabled protocols:
async                   gopher                  mmst                    srtp
cache                   hls                     pipe                    subfile
concat                  http                    prompeg                 tcp
crypto                  httpproxy               rtmp                    tee
data                    https                   rtmps                   tls
ffrtmphttp              icecast                 rtmpt                   udp
file                    md5                     rtmpts                  udplite
ftp                     mmsh                    rtp                     unix

Enabled filters:
abench                  bwdif                   haldclutsrc             scroll
abitscope               cas                     hdcd                    select
acompressor             cellauto                headphone               selectivecolor
acontrast               channelmap              hflip                   sendcmd
acopy                   channelsplit            highpass                separatefields
acrossfade              chorus                  highshelf               setdar
acrossover              chromahold              hilbert                 setfield
acrusher                chromakey               histogram               setparams
acue                    chromashift             hqx                     setpts
addroi                  ciescope                hstack                  setrange
adeclick                codecview               hue                     setsar
adeclip                 color                   hwdownload              settb
adelay                  colorbalance            hwmap                   showcqt
aderivative             colorchannelmixer       hwupload                showfreqs
adrawgraph              colorhold               hysteresis              showinfo
aecho                   colorkey                idet                    showpalette
aemphasis               colorlevels             il                      showspatial
aeval                   colorspace              inflate                 showspectrum
aevalsrc                compand                 interleave              showspectrumpic
afade                   compensationdelay       join                    showvolume
afftdn                  concat                  lagfun                  showwaves
afftfilt                convolution             lenscorrection          showwavespic
afifo                   convolve                life                    shuffleframes
afir                    copy                    limiter                 shuffleplanes
afirsrc                 coreimage               loop                    sidechaincompress
aformat                 coreimagesrc            loudnorm                sidechaingate
agate                   crop                    lowpass                 sidedata
agraphmonitor           crossfeed               lowshelf                sierpinski
ahistogram              crystalizer             lumakey                 signalstats
aiir                    cue                     lut                     silencedetect
aintegral               curves                  lut1d                   silenceremove
ainterleave             datascope               lut2                    sinc
alimiter                dcshift                 lut3d                   sine
allpass                 dctdnoiz                lutrgb                  smptebars
allrgb                  deband                  lutyuv                  smptehdbars
allyuv                  deblock                 mandelbrot              sobel
aloop                   decimate                maskedclamp             spectrumsynth
alphaextract            deconvolve              maskedmax               split
alphamerge              dedot                   maskedmerge             sr
amerge                  deesser                 maskedmin               ssim
ametadata               deflate                 maskedthreshold         stereotools
amix                    deflicker               maskfun                 stereowiden
amovie                  dejudder                mcompand                streamselect
amplify                 derain                  median                  superequalizer
amultiply               deshake                 mergeplanes             surround
anequalizer             despill                 mestimate               swaprect
anlmdn                  detelecine              metadata                swapuv
anlms                   dilation                midequalizer            tblend
anoisesrc               displace                minterpolate            telecine
anull                   dnn_processing          mix                     testsrc
anullsink               doubleweave             movie                   testsrc2
anullsrc                drawbox                 negate                  thistogram
apad                    drawgraph               nlmeans                 threshold
aperms                  drawgrid                noformat                thumbnail
aphasemeter             drmeter                 noise                   tile
aphaser                 dynaudnorm              normalize               tlut2
apulsator               earwax                  null                    tmedian
arealtime               ebur128                 nullsink                tmix
aresample               edgedetect              nullsrc                 tonemap
areverse                elbg                    oscilloscope            tpad
arnndn                  entropy                 overlay                 transpose
aselect                 equalizer               pad                     treble
asendcmd                erosion                 pal100bars              tremolo
asetnsamples            extractplanes           pal75bars               trim
asetpts                 extrastereo             palettegen              unpremultiply
asetrate                fade                    paletteuse              unsharp
asettb                  fftdnoiz                pan                     v360
ashowinfo               fftfilt                 perms                   vectorscope
asidedata               field                   photosensitivity        vflip
asoftclip               fieldhint               pixdesctest             vfrdet
asplit                  fieldmatch              pixscope                vibrance
astats                  fieldorder              premultiply             vibrato
astreamselect           fifo                    prewitt                 vignette
asubboost               fillborders             pseudocolor             vmafmotion
atadenoise              firequalizer            psnr                    volume
atempo                  flanger                 qp                      volumedetect
atrim                   floodfill               random                  vstack
avectorscope            format                  readeia608              w3fdif
avgblur                 fps                     readvitc                waveform
axcorrelate             framepack               realtime                weave
bandpass                framerate               remap                   xbr
bandreject              framestep               removegrain             xfade
bass                    freezedetect            removelogo              xmedian
bbox                    freezeframes            replaygain              xstack
bench                   gblur                   reverse                 yadif
bilateral               geq                     rgbashift               yaepblur
biquad                  gradfun                 rgbtestsrc              yuvtestsrc
bitplanenoise           graphmonitor            roberts                 zoompan
blackdetect             greyedge                rotate
blend                   haas                    scale
bm3d                    haldclut                scale2ref

Enabled bsfs:
aac_adtstoasc           filter_units            mjpega_dump_header      prores_metadata
av1_frame_merge         h264_metadata           mov2textsub             remove_extradata
av1_frame_split         h264_mp4toannexb        mp3_header_decompress   text2movsub
av1_metadata            h264_redundant_pps      mpeg2_metadata          trace_headers
chomp                   hapqa_extract           mpeg4_unpack_bframes    truehd_core
dca_core                hevc_metadata           noise                   vp9_metadata
dump_extradata          hevc_mp4toannexb        null                    vp9_raw_reorder
eac3_core               imx_dump_header         opus_metadata           vp9_superframe
extract_extradata       mjpeg2jpeg              pcm_rechunk             vp9_superframe_split

Enabled indevs:
avfoundation            lavfi

Enabled outdevs:

License: LGPL version 2.1 or later
libavutil/avconfig.h is unchanged
libavfilter/filter_list.c is unchanged
libavcodec/codec_list.c is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavdevice/indev_list.c is unchanged
libavdevice/outdev_list.c is unchanged
libavformat/protocol_list.c is unchanged
ffbuild/config.sh is unchanged
 apple@kongyulu  ~/development/study/ffmpeg/ffmpeg/ffmpeg   master 
複製程式碼

這樣我們已經成功配置了FFmpeg,接下來執行編譯

  • 執行make -j 4 這裡命令的意思是增加4個核心,並行編譯,這樣提高編譯速度 執行make命令後,接下來需要等待比較長的時間等編譯完成,需要耐心
    漫長編譯過程
    編譯完成
  • 執行make install

這裡我執行make install提示沒有許可權,所以需要用到開篇的基礎命令sudo增加執行許可權

沒有許可權

執行sudo make install

增加許可權後,就可以安裝成功了。

這樣就成功安裝到了/usr/local/ffmpeg 目錄下面了,我們切換到這個目錄檢視一下

目錄檢視

我們可以看到有四個子目錄:bin,include,lib,share

  1. bin目錄:存放所有ffmpeg的工具庫
  2. include目錄: 存放ffmpeg庫的所有標頭檔案
  3. lib目錄:ffmepg生成的動態庫或靜態庫
  4. share目錄:存放檔案相關內容和一些demo例項

我們接下來可以進入bin目錄執行命令:

進入bin目錄
正常會有三個子目錄,由於我這裡沒有安裝ffplay所以少了一個ffplay

這是為什麼呢?

因為ffplay實際上是客戶端ffplay.c的C程式編譯出來的,該ffplay.c需要依賴avdevice模組,而avdevice模組使用了sdl的API,如果你的PC上沒有sdl(1.x版本,最常用的是1.2.0版本),那麼ffplay就會編譯不出來了,所以要想編譯出命令列工具ffplay,首先的編譯基礎庫 sdl

  • Mac OS 安裝sdl 庫

如果沒有安裝brew的話,要先安裝Homebrew

ruby -e "$(curl -fsSL \
https://raw.githubusercontent.com/Homebrew/install/master/install)”
複製程式碼

等待一段時間,就安裝好了,

然後執行命令:

brew install sdl 
複製程式碼

等待下載並且安裝完畢之後,重新執行上述FFmpeg的配置和安裝步驟,待make install結束之後,再去bin目錄下就可以找到命令列工具ffplay了。

  • 安裝完成之後接下來一個很重要的事情就是配置環境變數,如果沒有配置,你直接執行ffmpeg命令是會報錯的

執行ffmpeg命令是會報錯

如果你配置環境變數,則需要每次帶上全路徑,如下:

/usr/local/ffmpeg/bin/ffmpeg -version
複製程式碼

接下來配置環境變數

執行命令

vi ~/.bash_profile
複製程式碼

配置環境變數
在配置檔案加入ffmpeg的bin資料夾路徑:

export PATH=$PATH:/usr/local/ffmpeg/bin
複製程式碼

然後輸入:wq儲存退出,再執行下面命令讓剛配置的環境變數生效:

source ~/.bash_profile
複製程式碼

配置的環境變數生效

3.2 在Linux下編譯安裝FFmpeg

3.2.1 apt 命令安裝

在ubuntu作業系統上可以很容易的跟Mac電腦上執行brew install ffmpeg一樣可以一行命令執行 通過執行apt 安裝如下:

sudo apt install ffmpeg
複製程式碼

這個的弊端也是無法定製化,如果要定製化還是要手動編譯原始碼安裝

安裝完成後,我們可以執行ffmpeg -version測試是否安裝成功

測試是否安裝成功

Centos 作業系統下安裝

  • 需安裝Nux Dextop Yum 源, 由於CentOS沒有官方FFmpeg rpm軟體包。但是,我們可以使用第三方YUM源(Nux Dextop)完成此工作。

CentOS 7下:

sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
複製程式碼

然後

sudo yum install ffmpeg ffmpeg-devel -y
複製程式碼

3.2.2 原始碼安裝

tar -xjvf ffmpeg-4.1.tar.bz2
cd ffmpeg-4.1/
複製程式碼
  • 跟上面mac原始碼安裝類似,先進行configure配置,配置過程可能報錯,如報下面錯誤:
[root@kongyulu ffmpeg-4.1]# ./configure 
gcc is unable to create an executable file.
If gcc is a cross-compiler,use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake,make sure you are using the latest
version from Git.  If the latest version fails,report the problem to the
[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will   help
solve the problem.
複製程式碼

則說明yasm編譯器沒有安裝或者太老了,需要先安裝新的yasm彙編器。

可以使用--disable-yasm禁用這個選項編譯,yasm是一款彙編器,並且是完全重寫了nasm的彙編環境,接收nasm和gas語法,支援x86和amd64指令集,所以這裡安裝一下yasm即可

  • Linux下安裝yasm 跟Mac下安裝相似,都是先下載原始碼,然後配置,編譯,安裝

官網下載yasm.tortall.net/Download.ht…

下載後解壓,安裝

tar -xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
make install
複製程式碼
  • 安裝成功後,還是和mac安裝ffmpeg一樣,需要重新配置FFmpeg:
./configure --enable-shared --prefix=/opt/ffmpeg
複製程式碼

/opt/ffmpeg 是配置的安裝目錄,可以自己配置路徑

  • 然後make進行編譯
make
複製程式碼
  • 安裝
make install
複製程式碼

make install會把ffmpeg相關執行程式、標頭檔案、lib庫安裝在/opt/ffmpeg/

  • 安裝完成後可以進入/opt/ffmpeg/檢視

發現有bin,share這4個目錄

bin是ffmpeg主程式二進位制目錄 include是C/C++標頭檔案目錄 lib是編譯好的庫檔案目錄 share是檔案目錄

  • 我們可以進入bin目錄執行./ffmpeg -version, 檢視當前版本的詳細資訊 可能會報錯:
libavdevice.so.57: cannot open shared object file: No such file or directory
複製程式碼

原因是lib目錄未載入到連結到系統庫中 系統ld目錄列表在/etc/ld.so.conf中,開啟檔案會發現, 裡面引用了/etc/ld.so.conf.d/下面所有的.conf檔案,比如mariadb-x86_64.conf

解決上面報錯,需要建立一個檔案並寫入lib路徑即可

  1. 執行命令:vim /etc/ld.so.conf.d/ffmpeg.conf
  2. 然後新增一行內容:/opt/ffmpeg/lib
  3. 之後儲存並退出,然後執行 ldconfig使配置生效,
  4. 再次執行./ffmpeg -version 顯示就正常了

正常會列印如下資訊

[root@kongyulu ffmpeg-4.1]#  ffmpeg -ersion
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-28)
configuration: --enable-shared --prefix=/opt/ffmpeg-4
libavutil      56. 22.100 / 56. 22.100
libavcodec     58. 35.100 / 58. 35.100
libavformat    58. 20.100 / 58. 20.100
libavdevice    58.  5.100 / 58.  5.100
libavfilter     7. 40.101 /  7. 40.101
libswscale      5.  3.100 /  5.  3.100
libswresample   3.  3.100 /  3.  3.100
複製程式碼
  • 接下來需要配置環境變數 使用命令vim /etc/profile:編輯寫入↓
PATH=/opt/python364/bin/:/opt/ffmpeg-4/bin/:$PATH
複製程式碼

然後執行命令source /etc/profile:使修改後的配置檔案生效

  • 檢測ffmpeg是否安裝成功 執行which ffmpeg 檢視安裝路徑

3.3 在Window下編譯安裝FFmpeg

3.3.1 Window編譯工具介紹

window下編譯FFmpeg相對複雜一下,需要藉助Cygwin或MinGW來編譯,可以通過MinGW+ MSYS2 或者 VS+ MSYS2來編譯ffmpeg

Cygwin(Cygnus Windows)實際上相當於在window安裝了一個軟體來模擬linux系統

MinGW(Minimalist GNU for Windows)是完全模仿了linux的編譯工具,相對於將linux的編譯工具移植到 window,基於window系統api進行編譯,需要提供額外的工具配合使用

VS就是 window開發很熟悉了

MSYS2(Minimal SYStem 2)

3.3.2 Window如何編譯ffmpeg

Window編譯ffmpeg主要有下面三種方式

  • Cygwin直接安裝使用: Cygwin編譯跟linux編譯一模一樣的,Cygwin完全就像一個虛擬機器器模擬了linux作業系統。Cygwin實際上是做了一層linux的api到windows 的api的轉換。

但是這樣編譯出來的ffmpeg的exe程式需要掛在一個Cygwin.dll庫才可以執行,因為它有一層轉換,所以效能對比原始的window程式有一些損耗。

  • MinGW + MSYS2 : 官方推薦的方式,這種編譯出來的就是原生的window程式,不需要和Cygwin一樣需要載入一個動態庫了。

它的編譯方式實際上和linux是一致的

  • VS + MSYS2: 這種就是採用類linux的編譯,只是把裡面的工具鏈換成了VS的工具,但是這種方式生成ffplay比較麻煩。

所以一般都選擇MinGW + MSYS2 : 官方推薦的方式

3.3.2.1 Cygwin 編譯FFmpeg

在windows下安裝 ffmpeg 的最好方式就是使用 CygwinCygwin 是什麼呢?簡單的說,就是在 Windows上裝了一個Linux模擬器。然後你可以在這個模擬器上按照Linux的方式操作 Windows系統。因此,Windows安裝了 Cygwin 之後,你就把它當Linux用就可以了。

首先,到 Cygwin 官網下載 Cygwin 的可執行程式 setup-x86_64.exe。當然,它是 64位的,如果你現在還在用 32位的,那請在 Cygwin官網上找 32位對應的版本。

  • 首先要安裝Cygwin
    安裝Cygwin

下載軟體後開始安裝

開始安裝

下一步繼續

選擇系統的網路連線方式,跟虛擬機器器類似

選擇網路連線方式

選擇映象安裝

下載安裝

選擇映象的對應包

選擇映象的對應包

然後選擇我們需要的安裝包安裝,我這裡選擇 Debug,Devel這兩個必須的

選擇 Debug,Devel這兩個必須的

此外還需要選擇網路

此外還需要選擇網路

還需要新增wget

還需要新增wget

此外我們選擇一個sdl的庫

此外我們選擇一個sdl的庫
為了後面編譯出ffplay庫,最好把下面的紅框裡面都選上
最好把紅框裡面都選上
以上就是一個最小的安裝了

需要確保安裝了下面這些工具

  1. gcc
  2. g++
  3. make
  4. cmake
  5. automake
  6. gdb
  7. nasm
  8. yasm
  9. wget

選好之後繼續下一步

選好之後繼續下一步

等待安裝完成

等待安裝完成

然後點選圖示開啟

然後點選圖示開啟

可以看到一個linux的控制檯,如果在window下學習linux命名,就可以在這個控制檯練習

這樣你就可以敲入linux命令了

可以自由敲入linux命令

如果我們要訪問window下的D:盤,可以像下面這樣訪問:

在這裡插入圖片描述

檢視D盤下的檔案目錄

  • 然後要安裝apt-cyg: 這個實際就是Cygwin下的apt工具

apt-cyg與 Ubuntu系統中的 apt一樣特別好用,而且使用的方式與 apt也是一個樣子的。

我們可以在Cygwin下執行下面的命令就好了

wget -c https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg

複製程式碼

在Cygwin下執行下面的命令
然後執行命令

install apt-cyg /bin
複製程式碼

安裝apt-cyg

安裝好apt-cyg後,就可以用 apt-cyg instal xxx這樣來安裝了我們的包了跟Mac下使用brew install xxx一樣爽歪歪。

測試apt-cyg

  • 接下來安裝pkg-config工具 在Windows系統下,一般不會預設安裝該工具,所以在Windows下做實驗的同學大都會遇到明明已經裝了某個庫,但仍然找不到該庫的情況。其原因就是沒有安裝 pkg-config這個工具。 首先確認是否已經將 pkg-config工具安裝好了。可以執行下面的命令:
pkg-config
複製程式碼

如果提示沒有安裝,則先將該工具安裝好,安裝命令如下:

apt-cyg install pkg-config
複製程式碼

然後就是安裝了,安裝方式跟mac,linux一樣

  1. 輸入命令:./configure --prefix=/usr/local/ffmpeg 配置環境
  2. 執行命令:make -j 4 編譯原始碼
  3. 執行命令:make install 安裝

下載原始碼通過http直接下載或者git下載

下載原始碼
git下載原始碼

這裡我使用git方式,先建立一個ffmpeg目錄,然後Git clone程式碼

Git clone

下載好原始碼後,進入目錄,然後配置configure

配置configure

配置完成報告如下:

配置完成

此時make檔案已經生成好了,我們輸入make -j 4 執行編譯

執行編譯
這個編譯過程比較長,耐心等待

最好執行make install 安裝

執行安裝

安裝好之後,我們可以進入/usr/local/ffmpeg目錄檢視

檢視目錄
我們可以看到四個目錄:bin,share 接下來,我們進入bin目錄:

我們進入bin目錄
可以看到三個exe檔案,ffmpeg.exe,ffplayer.exe,ffprobe.exe

我們可以執行ffmpeg.exe

執行ffmpeg.exe

  • 接下來也需要配置環境變數,不然每次要帶全路徑

輸入命令:vi ~/.bashrc 編輯配置檔案

開啟配置檔案

按快捷鍵“Shift+G”跳到檔案末尾,在配置檔案末尾插入:export PATH=/usr/local/ffmpeg/bin:$PATH

然後按esc鍵,退出編輯模式,輸入:wq 儲存退出

配置ffmpeg環境變數

然後,我們輸入source ~/.bashrc 使配置檔案生效

使配置檔案生效

最好我們輸入env | grep PATH 來測試配置檔案是否生效

測試配置檔案是否生效

配置好環境變數後,我們直接輸入ffmpeg.exe就可以找到了

配置好環境變數後,我們直接輸入ffmpeg.exe

3.3.2.1.2 x264 安裝

雖然有了apt-cyg這個神器,但它目前只能安裝Linux下的一些常用命令,像我們編譯時需要的 x264,x265這些庫它是無法找到的。

所以這些庫需要我們自己來編譯

  • 編譯yasm
  1. 下載原始碼:wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
  2. 解壓:tar zxvf yasm-1.3.0.tar.gz
  3. 切換到目錄:cd yasm-1.3.0
  4. 配置選項:./configure
  5. 編譯安裝:make && sudo make install
  • 編譯fdk-aac
  1. 下載原始碼:wget https://jaist.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.6.tar.gz
  2. 解壓:tar xvf fdk-aac-0.1.6.tar.gz
  3. 切換到目錄: cd fdk-aac-0.1.6
  4. 配置選項:./configure
  5. 編譯安裝:make && sudo make install
  • 安裝lame
  1. 下載原始碼:wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
  2. 解壓:tar -xzf lame-3.99.5.tar.gz
  3. 切換到目錄:cd lame-3.99.5
  4. 配置選項:./configure
  5. 編譯安裝:make && sudo make install

注:編譯lame可能遇到的問題:

  1. 問題一: 在Cygwin下安裝 lame的時候遇到執行 ./configure 失敗的情況。如 "error: cannot guess build type; you must sepcify one",對這個問題可以通過下面的步驟來解決: 安裝automake。可以通過 which automake來確認automake 是否已經安裝。如果沒有安裝,可以通使用 apt-cyg install automake進行安裝。 確認automake當前版本。可執行automake --version獲取當前automake的版本號。 將 lame目錄下的 config.guess檔案替換為 /usr/share/automake-version下的config.guess 檔案。 此時,再執行./configure進就可以下成功了。
  2. 問題二: make時出現 "error: '_O_BINARY' undeclared (first use in this function)"的錯誤,解決辦法如下: 開啟出錯檔案 vi ./frontend/lametime.c 將下面這段程式碼註釋掉 /* #elif defined __CYGWIN setmod(fileno(fp),_O_BINARY); */ 再執行make就可以成功了。
  • 安裝nasm
  1. 下載原始碼:wget https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.gz
  2. 解壓:tar xvf nasm-2.13.03.tar.gz
  3. 切換到目錄:cd nasm-2.13.03
  4. 配置選項:./configure
  5. 編譯安裝:make && sudo make install
  • 安裝x264
  1. 下載原始碼: wget mirror.yandex.ru/mirrors/ftp… bunzip2 last_x264.tar.bz2
  2. 解壓:tar -vxf last_x264.tar
  3. 切換到目錄:cd last_x264
  4. 配置選項:./configure --enable-static --enable-shared --disable-asm --disable-avs
  5. 編譯安裝: make && sudo make install
  • 安裝ffmpeg
  1. 下載原始碼:wget -c https://ffmpeg.org/releases/ffmpeg-4.0.2.tar.bz2
  2. 解壓:bunzip2 ffmpeg-4.0.2.tar.bz2
  3. 切換到目錄:cd ffmpeg-4.0.2
  4. 配置選項:./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-small --arch=x86_64 --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-filter=delogo --enable-debug --disable-optimizations --enable-shared
  5. 編譯安裝:make && sudo make install

FFmpeg編譯的問題:

  1. 問題一:找不到 fdk-aac庫 在編譯ffmpeg時,有可能會報找不到fdk_aac庫的錯誤。此時我們應該設定一下 PKG_CONFIG_PATH,指定ffmpeg到哪裡找我們安裝好的庫。 上面通過原始碼安裝的庫,預設地址為/usr/local/lib下面,當然你可以通過./configure 中的–prefix引數改變這個目錄。 如果使用預設路徑的話,可以通過下面的命令來指定編譯時去哪裡找庫export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 如果你改變了預設路徑,則將後面的 /usr/local/lib/pkgconfig修改為你變更後的路徑/xxx/.../lib/pkgconfig即可。

3.3.2.2 MinGW + MSYS2 編譯FFmpeg

3.3.2.3 VS + MSYS2 編譯FFmpeg

參考:李超大神的部落格和視訊:www.imooc.com/article/247…