FFmpeg的代碼結(jié)構(gòu)和編譯系統(tǒng)

FFmpeg的目錄結(jié)構(gòu)

目錄結(jié)構(gòu)
  1. compact目錄下主要是頭文件葱蝗,是為了兼容不同平臺或系統(tǒng)的數(shù)據(jù)類型定義,例如compat/msvcrt/snprintf.h和snprintf.c是兼容C99的snprintf()和vsnprintf()聲明及實現(xiàn)韩玩;

  2. libavcodec目錄下是編碼/解碼庫所在的代碼路徑;

  3. libavdevice目錄下是和一些特定設(shè)備相關(guān)的接口實現(xiàn)陆馁,比如sdl顯示設(shè)備找颓,alsa音頻輸出設(shè)備,opengl圖形加速設(shè)備叮贩,v4l2視頻設(shè)備(比如攝像頭)击狮;

  4. libavfilter是一個類似DirecShow機制的幀處理函數(shù)集,通過graph-based機制益老,將不同處理功能的filter函數(shù)彪蓬,鏈接(link)起來;

  5. libavformat是復(fù)用/解復(fù)用庫捺萌,一般用于多媒體文件的處理档冬;

  6. libavresample顧名思義,是一個重采樣庫桃纯,比如音頻采樣率從44.1KHz到96KHz酷誓;

  7. libavutil是支撐FFmpeg的工具集,像fifo管理态坦,內(nèi)存管理盐数,時間管理等;

  8. libpostproc是后期處理庫伞梯;

  9. libswresample是音頻重采樣玫氢,格式轉(zhuǎn)換和混合;功能和libavresample十分類似谜诫,是FFmpeg相對早期的實現(xiàn)方法漾峡;

  10. libswscale是顏色空間轉(zhuǎn)換和大小尺寸縮放的庫;

  11. cmdutils.c是用戶使用命令行進行ffmpeg操作時用到的工具喻旷;

  12. ffmpeg.c是ffmpeg工具的源碼灰殴;

  13. ffplay.c是一個基于FFmpeg庫文件的播放器實例;

  14. ffprobe.c是解析媒體文件格式信息的例子;

  15. ffserver.c是RTSP/HTTP流媒體服務(wù)器的源代碼牺陶;

  16. configure是編譯前執(zhí)行配置的腳本伟阔;

FFmpeg的配置

FFmpeg在編譯前需要進行配置,它的配置選項也極其豐富掰伸,可以通過如下命令來查看詳細(xì)的配置信息皱炉,

./configure --help

下面,我們來分類了解一下FFmpeg的配置詳情狮鸭。

幫助選項

可以通過列表顯示編解碼器信息合搅,復(fù)用/解復(fù)用信息,硬件加速歧蕉,解析器灾部,協(xié)議,過濾器惯退,輸入輸出設(shè)備等信息赌髓,

Help options:
--help print this message
--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

標(biāo)準(zhǔn)選項

比如把log輸出重定向到某路徑,編譯后的庫文件的安裝路徑等催跪,[ ]里的內(nèi)容是默認(rèn)的配置锁蠕,

Standard options:
--logfile=FILE log tests and output to FILE [config.log]
--disable-logging do not log configure debug information
--fatal-warnings fail if any configure warning is generated
--prefix=PREFIX install in PREFIX []
--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

開源許可的相關(guān)選項

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]

配置選項

比如靜態(tài)庫和動態(tài)庫的選擇,編譯優(yōu)化等懊蒸,

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
--enable-raise-major increase major version numbers in sonames [no]

程序選項

每個選項對應(yīng)一個可單獨執(zhí)行的程序荣倾,可選擇編譯還是不編譯,

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
--disable-ffserver disable ffserver build

文檔選項

是否關(guān)閉生成文檔骑丸,

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 [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

獨立功能選項

比如編解碼開關(guān)通危,可以配置到某一編解碼類型抡笼,

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

擴展庫支持的配置

也就是依賴第三方的庫文件,由FFmpeg提供接口調(diào)用相關(guān)的庫黄鳍,比如要開啟x264的支持 推姻,
–enable-libx264,要關(guān)閉Intel硬件加速 框沟, –disable-vaapi藏古,

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.
--enable-avisynth enable reading of AviSynth script files [no]
--disable-bzlib disable bzlib [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

工具鏈配置選項

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
--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]

高級配置選項(專家級)

主要是和內(nèi)存分配,編解碼相關(guān)的一些高級選項忍燥,一般無需涉及拧晕,

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)
--enable-memalign-hack emulate memalign, interferes with memory debuggers
--sws-max-filter-size=N the max filter size swscale uses [256]

優(yōu)化選項(也是專家級),是和目標(biāo)平臺target有關(guān)的優(yōu)化梅垄,比如音視頻相關(guān)的指令及匯編代碼厂捞,

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

開發(fā)者配置選項

在調(diào)試FFmpeg源代碼時使用,

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)

從上可知,F(xiàn)Fmpeg源碼的配置選項十分豐富靡馁,但是條理十分清晰欲鹏,執(zhí)行配置的操作也十分簡單,只需要在configure腳本后跟上相關(guān)的選項即可臭墨,比如要開啟x264的支持赔嚎,可以如下,

./configure --enable-libx264 --enable-gpl

整個配置結(jié)束后胧弛,會在FFmpeg源代碼的根目錄下生成config.mak文件尤误,其內(nèi)容是configure腳本根據(jù)前述配置(可能很多選項是默認(rèn))自動生成的key-value值,供后面make編譯使用结缚。

FFmpeg的編譯系統(tǒng)

FFmpeg的編譯是依賴于源代碼根目錄下的Makefile進行的损晤,首先通過include config.mak 將前述配置變量config.mak引入,這些配置將在整個編譯過程中生效红竭。同時還會引入common.mak尤勋,主要是一些公共變量定義以及方法定義,像變量ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil postproc swscale swresample 就定義了所有的庫集合德崭。另外斥黑,主Makefile還會引入library.mak揖盘,library.mak的主要作用是編譯各個庫的規(guī)則眉厨,如libavformat。
整個make的目標(biāo)是如下語句兽狭,

all: $(AVPROGS)

而變量$(AVPROGS)則由下列語句獲得憾股,

AVPROGS := (AVPROGS-yes:%=%(PROGSSUF)$(EXESUF))

變量$(AVPROGS-yes)的定義如下,

AVPROGS-$(CONFIG_FFMPEG) += ffmpeg

AVPROGS-$(CONFIG_FFPLAY) += ffplay

AVPROGS-$(CONFIG_FFPROBE) += ffprobe

AVPROGS-$(CONFIG_FFSERVER) += ffserver

即配置程序的集合箕慧,make install的規(guī)則如下服球,

install: install-libs install-headers

完成lib庫的安裝以及頭文件的安裝。

總體來看颠焦,整個FFmpeg的編譯系統(tǒng)也比較龐大斩熊,但是條理十分清晰,為了讓FFmpeg可以跨多個平臺進行編譯伐庭,Makefile系統(tǒng)封裝了很多的變量粉渠。通過配置文件,將不同平臺不同編譯選項的需求圾另,統(tǒng)一用一套Makefile來完成霸株,其跨平臺性得到了玲離盡致的體現(xiàn)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末集乔,一起剝皮案震驚了整個濱河市去件,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖尤溜,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件倔叼,死亡現(xiàn)場離奇詭異,居然都是意外死亡靴跛,警方通過查閱死者的電腦和手機缀雳,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來梢睛,“玉大人肥印,你說我怎么就攤上這事【希” “怎么了深碱?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長藏畅。 經(jīng)常有香客問我敷硅,道長,這世上最難降的妖魔是什么愉阎? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任绞蹦,我火速辦了婚禮,結(jié)果婚禮上榜旦,老公的妹妹穿的比我還像新娘幽七。我一直安慰自己,他們只是感情好溅呢,可當(dāng)我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布澡屡。 她就那樣靜靜地躺著,像睡著了一般咐旧。 火紅的嫁衣襯著肌膚如雪驶鹉。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天铣墨,我揣著相機與錄音室埋,去河邊找鬼。 笑死伊约,一個胖子當(dāng)著我的面吹牛姚淆,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播碱妆,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼肉盹,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了疹尾?” 一聲冷哼從身側(cè)響起上忍,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤骤肛,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后窍蓝,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體腋颠,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年吓笙,在試婚紗的時候發(fā)現(xiàn)自己被綠了淑玫。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡面睛,死狀恐怖絮蒿,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情叁鉴,我是刑警寧澤土涝,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站幌墓,受9級特大地震影響但壮,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜常侣,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一蜡饵、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧胳施,春花似錦溯祸、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽鸟召。三九已至胆绊,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間欧募,已是汗流浹背压状。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留跟继,地道東北人种冬。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓,卻偏偏與公主長得像舔糖,于是被迫代替她去往敵國和親娱两。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內(nèi)容

  • 下載FFmpeg源碼 首先登陸FFmpeg的官方網(wǎng)站https://ffmpeg.org/金吗,打開下載地址:http...
    張俊峰0613閱讀 12,201評論 0 7
  • 1. 安裝編譯環(huán)境 2. 下載源碼 3. 配置選項 通過configure來配置需要編譯的ffmpeg庫 3.1 ...
    Weller0閱讀 1,345評論 2 4
  • 1.FFmepg編譯環(huán)境及結(jié)構(gòu) 下載FFmepg FFmpeg配置選項介紹 下載gas-preprocessor....
    Jackey_song閱讀 2,238評論 2 2
  • 下面列舉我們需要用到的一些編譯參數(shù) openssl --with-openssl mysql,pdo --wit...
    黑魔術(shù)師閱讀 1,361評論 0 0
  • 我二十一二歲的時候十兢,所得到的情感大部分被性左右著趣竣,所以很多戀情都不長久。這一段時間大概是內(nèi)心荒蕪到極點旱物,病急亂投醫(yī)...
    妙鋒閱讀 116評論 0 0