FFmpeg的目錄結(jié)構(gòu)
compact目錄下主要是頭文件葱蝗,是為了兼容不同平臺或系統(tǒng)的數(shù)據(jù)類型定義,例如compat/msvcrt/snprintf.h和snprintf.c是兼容C99的snprintf()和vsnprintf()聲明及實現(xiàn)韩玩;
libavcodec目錄下是編碼/解碼庫所在的代碼路徑;
libavdevice目錄下是和一些特定設(shè)備相關(guān)的接口實現(xiàn)陆馁,比如sdl顯示設(shè)備找颓,alsa音頻輸出設(shè)備,opengl圖形加速設(shè)備叮贩,v4l2視頻設(shè)備(比如攝像頭)击狮;
libavfilter是一個類似DirecShow機制的幀處理函數(shù)集,通過graph-based機制益老,將不同處理功能的filter函數(shù)彪蓬,鏈接(link)起來;
libavformat是復(fù)用/解復(fù)用庫捺萌,一般用于多媒體文件的處理档冬;
libavresample顧名思義,是一個重采樣庫桃纯,比如音頻采樣率從44.1KHz到96KHz酷誓;
libavutil是支撐FFmpeg的工具集,像fifo管理态坦,內(nèi)存管理盐数,時間管理等;
libpostproc是后期處理庫伞梯;
libswresample是音頻重采樣玫氢,格式轉(zhuǎn)換和混合;功能和libavresample十分類似谜诫,是FFmpeg相對早期的實現(xiàn)方法漾峡;
libswscale是顏色空間轉(zhuǎn)換和大小尺寸縮放的庫;
cmdutils.c是用戶使用命令行進行ffmpeg操作時用到的工具喻旷;
ffmpeg.c是ffmpeg工具的源碼灰殴;
ffplay.c是一個基于FFmpeg庫文件的播放器實例;
ffprobe.c是解析媒體文件格式信息的例子;
ffserver.c是RTSP/HTTP流媒體服務(wù)器的源代碼牺陶;
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 :=
(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)。