直接对ffmpeg的源码进行编译链接生成的静态库非常大,仅仅avcodec就有几十兆。因此根据我们自己的需求对ffmpeg进行裁剪是非常必要的。
先不说具体的,直接上代码。在ffmpeg源码的根目录下新建shell脚本,命名为ffmpeg_small(随便起的),然后把下面的内容复制进去,修改执行权限,然后执行,大概十多分钟后就可以得到裁剪后的ffmpeg静态库啦。经过验证,生成的libavcodec.a仅有2MB,libavdevice仅有7.5KB,libavfilter仅有192.4KB,libavformat.a仅有450.2KB,libavutil为298.2KB。
另外需要说明的是,为了使得生成的静态库可以对视频进行h264编码,对音频进行aac编码,我们需要对ffmpeg添加x264和aac支持,因此需要下载编译x264和vo-aacenc的源码。x264源码从git上下载就行,vo-aacenc可以在bitbucket下载:vo-aacenc源码下载。
- #!/bin/sh
- ./configure --enable-gpl --enable-nonfree --enable-version3 --enable-small\
- --disable-encoders --enable-libx264 --enable-libvo-aacenc --enable-encoder=libx264 --enable-encoder=libvo_aacenc\
- --disable-muxers --enable-muxer=mov --enable-muxer=mp4 --enable-muxer=avi\
- --disable-decoders --enable-decoder=aac --enable-decoder=aac_latm --enable-decoder=h264 --enable-decoder=mpeg4\
- --disable-filters --enable-filter=anull --enable-filter=null --enable-filter=aresample --enable-filter=pad --enable-filter=scale --enable-filter=overlay --enable-filter=amix --enable-filter=aresample\
- --disable-demuxers --enable-demuxer=h264 --enable-demuxer=avi --enable-demuxer=mpc --enable-demuxer=mov\
- --disable-parsers --enable-parser=aac --enable-parser=h264\
- --disable-protocols --enable-protocol=file\
- --disable-bsfs --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb\
- --disable-indevs\
- --disable-outdevs --disable-ffprobe --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-debug
- make
- sudo make install
如果我们不进行裁剪,直接./configure 输出的结果如下:
我们可以看到不管是decoder还是encoder或者filter或者protocal我们都Enable了一大堆,在实际应用中我们完全不需要这么全面的库。
- <pre name="code" class="html">nstall prefix /usr/local
- source path .
- C compiler gcc
- C library glibc
- ARCH x86 (generic)
- big-endian no
- runtime cpu detection yes
- yasm yes
- MMX enabled yes
- MMXEXT enabled yes
- 3DNow! enabled yes
- 3DNow! extended enabled yes
- SSE enabled yes
- SSSE3 enabled yes
- AVX enabled yes
- XOP enabled yes
- FMA3 enabled yes
- FMA4 enabled yes
- i686 features enabled yes
- CMOV is fast no
- EBX available yes
- EBP available yes
- debug symbols yes
- strip symbols yes
- optimize for size no
- optimizations yes
- static yes
- shared no
- postprocessing support no
- new filter support yes
- network support yes
- threading support pthreads
- safe bitstream reader yes
- SDL support no
- opencl enabled no
- texi2html enabled no
- perl enabled yes
- pod2man enabled yes
- makeinfo enabled no
- makeinfo supports HTML no
- External libraries:
- iconv
- <strong><span style="color:#FF0000;"><span style="background-color: rgb(255, 255, 255);">Enabled decoders:</span></span></strong>
- aac bink h264
- aac_latm binkaudio_dct hevc
- aasc binkaudio_rdft hnm4_video
- ac3 bintext huffyuv
- ac3_fixed bmp iac
- adpcm_4xm bmv_audio idcin
- adpcm_adx bmv_video idf
- adpcm_afc brender_pix iff_byterun1
- adpcm_ct c93 iff_ilbm
- adpcm_dtk cavs imc
- adpcm_ea cdgraphics indeo2
- adpcm_ea_maxis_xa cdxl indeo3
- adpcm_ea_r1 cinepak indeo4
- adpcm_ea_r2 cljr indeo5
- adpcm_ea_r3 cllc interplay_dpcm
- adpcm_ea_xas comfortnoise interplay_video
- adpcm_g722 cook jacosub
- adpcm_g726 cpia jpeg2000
- adpcm_g726le cscd jpegls
- adpcm_ima_amv cyuv jv
- adpcm_ima_apc dca kgv1
- adpcm_ima_dk3 dfa kmvc
- adpcm_ima_dk4 dirac lagarith
- adpcm_ima_ea_eacs dnxhd loco
- adpcm_ima_ea_sead dpx mace3
- adpcm_ima_iss dsd_lsbf mace6
- adpcm_ima_oki dsd_lsbf_planar mdec
- adpcm_ima_qt dsd_msbf metasound
- adpcm_ima_rad dsd_msbf_planar microdvd
- adpcm_ima_smjpeg dsicinaudio mimic
- adpcm_ima_wav dsicinvideo mjpeg
- adpcm_ima_ws dvbsub mjpegb
- adpcm_ms dvdsub mlp
- adpcm_sbpro_2 dvvideo mmvideo
- adpcm_sbpro_3 dxtory motionpixels
- adpcm_sbpro_4 eac3 movtext
- adpcm_swf eacmv mp1
- adpcm_thp eamad mp1float
- adpcm_vima eatgq mp2
- adpcm_xa eatgv mp2float
- adpcm_yamaha eatqi mp3
- aic eightbps mp3adu
- alac eightsvx_exp mp3adufloat
- alias_pix eightsvx_fib mp3float
- als escape124 mp3on4
- amrnb escape130 mp3on4float
- amrwb evrc mpc7
- amv ffv1 mpc8
- anm ffvhuff mpeg1video
- ansi ffwavesynth mpeg2video
- ape fic mpeg4
- ass flac mpegvideo
- asv1 flic mpl2
- asv2 flv msa1
- atrac1 fourxm msmpeg4v1
- atrac3 fraps msmpeg4v2
- atrac3p frwu msmpeg4v3
- aura g723_1 msrle
- aura2 g729 mss1
- avrn gif mss2
- avrp gsm msvideo1
- avs gsm_ms mszh
- avui h261 mts2
- ayuv h263 mvc1
- bethsoftvid h263i mvc2
- bfi h263p mxpeg
- nellymoser ra_144 ulti
- nuv ra_288 utvideo
- on2avc ralf v210
- opus rawvideo v210x
- paf_audio realtext v308
- paf_video rl2 v408
- pam roq v410
- pbm roq_dpcm vb
- pcm_alaw rpza vble
- pcm_bluray rv10 vc1
- pcm_dvd rv20 vc1image
- pcm_f32be rv30 vcr1
- pcm_f32le rv40 vima
- pcm_f64be s302m vmdaudio
- pcm_f64le sami vmdvideo
- pcm_lxf sanm vmnc
- pcm_mulaw sgi vorbis
- pcm_s16be sgirle vp3
- pcm_s16be_planar shorten vp5
- pcm_s16le sipr vp6
- pcm_s16le_planar smackaud vp6a
- pcm_s24be smacker vp6f
- pcm_s24daud smc vp7
- pcm_s24le smvjpeg vp8
- pcm_s24le_planar snow vp9
- pcm_s32be sol_dpcm vplayer
- pcm_s32le sonic vqa
- pcm_s32le_planar sp5x wavpack
- pcm_s8 srt webp
- pcm_s8_planar ssa webvtt
- pcm_u16be stl wmalossless
- pcm_u16le subrip wmapro
- pcm_u24be subviewer wmav1
- pcm_u24le subviewer1 wmav2
- pcm_u32be sunrast wmavoice
- pcm_u32le svq1 wmv1
- pcm_u8 svq3 wmv2
- pcm_zork tak wmv3
- pcx targa wmv3image
- pgm targa_y216 wnv1
- pgmyuv text ws_snd1
- pgssub theora xan_dpcm
- pictor thp xan_wc3
- pjs tiertexseqvideo xan_wc4
- ppm tiff xbin
- prores tmv xbm
- prores_lgpl truehd xface
- ptx truemotion1 xl
- qcelp truemotion2 xsub
- qdm2 truespeech xwd
- qdraw tscc2 y41p
- qpeg tta yop
- qtrle twinvq yuv4
- r10k txd zero12v
- r210
- <strong><span style="color:#FF0000;">Enabled encoders:</span></strong>
- a64multi jpegls ppm
- a64multi5 ljpeg prores
- aac mjpeg prores_aw
- ac3 movtext prores_ks
- ac3_fixed mp2 qtrle
- adpcm_adx mp2fixed r10k
- adpcm_g722 mpeg1video r210
- adpcm_g726 mpeg2video ra_144
- adpcm_ima_qt mpeg4 rawvideo
- adpcm_ima_wav msmpeg4v2 roq
- adpcm_ms msmpeg4v3 roq_dpcm
- adpcm_swf msvideo1 rv10
- adpcm_yamaha nellymoser rv20
- alac pam s302m
- alias_pix pbm sgi
- amv pcm_alaw snow
- ass pcm_f32be sonic
- asv1 pcm_f32le sonic_ls
- asv2 pcm_f64be srt
- avrp pcm_f64le ssa
- avui pcm_mulaw subrip
- ayuv pcm_s16be sunrast
- bmp pcm_s16be_planar svq1
- cinepak pcm_s16le targa
- cljr pcm_s16le_planar tiff
- comfortnoise pcm_s24be tta
- dca pcm_s24daud utvideo
- dnxhd pcm_s24le v210
- dpx pcm_s24le_planar v308
- dvbsub pcm_s32be v408
- dvdsub pcm_s32le v410
- dvvideo pcm_s32le_planar vorbis
- eac3 pcm_s8 wavpack
- ffv1 pcm_s8_planar webvtt
- ffvhuff pcm_u16be wmav1
- flac pcm_u16le wmav2
- flv pcm_u24be wmv1
- g723_1 pcm_u24le wmv2
- gif pcm_u32be xbm
- h261 pcm_u32le xface
- h263 pcm_u8 xsub
- h263p pcx xwd
- huffyuv pgm y41p
- jpeg2000 pgmyuv yuv4
- Enabled hwaccels:
- <span style="color:#FF0000;"><strong>Enabled parsers:</strong></span>
- aac dvd_nav mpegvideo
- aac_latm dvdsub opus
- ac3 flac png
- adx gsm pnm
- bmp h261 rv30
- cavsvideo h263 rv40
- cook h264 tak
- dca hevc vc1
- dirac mjpeg vorbis
- dnxhd mlp vp3
- dpx mpeg4video vp8
- dvbsub mpegaudio vp9
- <span style="color:#FF0000;"><strong>
- Enabled demuxers:</strong></span>
- aac h263 nc
- ac3 h264 nistsphere
- act hevc nsv
- adf hls nut
- adp hnm nuv
- adx ico ogg
- aea idcin oma
- afc idf paf
- aiff iff pcm_alaw
- amr ilbc pcm_f32be
- anm image2 pcm_f32le
- apc image2_alias_pix pcm_f64be
- ape image2_brender_pix pcm_f64le
- aqtitle image2pipe pcm_mulaw
- asf image_bmp_pipe pcm_s16be
- ass image_dpx_pipe pcm_s16le
- ast image_exr_pipe pcm_s24be
- au image_j2k_pipe pcm_s24le
- avi image_jpeg_pipe pcm_s32be
- avr image_jpegls_pipe pcm_s32le
- avs image_pictor_pipe pcm_s8
- bethsoftvid image_png_pipe pcm_u16be
- bfi image_sgi_pipe pcm_u16le
- bink image_sunrast_pipe pcm_u24be
- bintext image_tiff_pipe pcm_u24le
- bit image_webp_pipe pcm_u32be
- bmv ingenient pcm_u32le
- boa ipmovie pcm_u8
- brstm ircam pjs
- c93 iss pmp
- caf iv8 pva
- cavsvideo ivf pvf
- cdg jacosub qcp
- cdxl jv r3d
- cine latm rawvideo
- concat live_flv realtext
- data lmlm4 redspark
- daud loas rl2
- dfa lrc rm
- dirac lvf roq
- dnxhd lxf rpl
- dsf m4v rsd
- dsicin matroska rso
- dts mgsts rtp
- dtshd microdvd rtsp
- dv mjpeg sami
- dxa mlp sap
- ea mlv sbg
- ea_cdata mm sdp
- eac3 mmf sdr2
- epaf mov segafilm
- ffm mp3 shorten
- ffmetadata mpc siff
- filmstrip mpc8 sln
- flac mpegps smacker
- flic mpegts smjpeg
- flv mpegtsraw smush
- fourxm mpegvideo sol
- frm mpl2 sox
- g722 mpsub spdif
- g723_1 msnwc_tcp srt
- g729 mtv stl
- gif mv str
- gsm mvi subviewer
- gxf mxf subviewer1
- h261 mxg sup
- swf vc1t webvtt
- tak vivo wsaud
- tedcaptions vmd wsvqa
- thp vobsub wtv
- tiertexseq voc wv
- tmv vplayer xa
- truehd vqf xbin
- tta w64 xmv
- tty wav xwma
- txd wc3 yop
- vc1 webm_dash_manifest yuv4mpegpipe
- <span style="color:#FF0000;"><strong>Enabled muxers:</strong></span>
- a64 image2pipe pcm_s24be
- ac3 ipod pcm_s24le
- adts ircam pcm_s32be
- adx ismv pcm_s32le
- aiff ivf pcm_s8
- amr jacosub pcm_u16be
- asf latm pcm_u16le
- asf_stream lrc pcm_u24be
- ass m4v pcm_u24le
- ast matroska pcm_u32be
- au matroska_audio pcm_u32le
- avi md5 pcm_u8
- avm2 microdvd psp
- bit mjpeg rawvideo
- caf mkvtimestamp_v2 rm
- cavsvideo mlp roq
- crc mmf rso
- dash mov rtp
- data mp2 rtsp
- daud mp3 sap
- dirac mp4 segment
- dnxhd mpeg1system smjpeg
- dts mpeg1vcd smoothstreaming
- dv mpeg1video sox
- eac3 mpeg2dvd spdif
- f4v mpeg2svcd spx
- ffm mpeg2video srt
- ffmetadata mpeg2vob stream_segment
- filmstrip mpegts swf
- flac mpjpeg tee
- flv mxf tg2
- framecrc mxf_d10 tgp
- framemd5 null truehd
- g722 nut uncodedframecrc
- g723_1 oga vc1
- gif ogg vc1t
- gxf oma voc
- h261 opus w64
- h263 pcm_alaw wav
- h264 pcm_f32be webm
- hds pcm_f32le webm_dash_manifest
- hevc pcm_f64be webp
- hls pcm_f64le webvtt
- ico pcm_mulaw wtv
- ilbc pcm_s16be wv
- image2 pcm_s16le yuv4mpegpipe
- <span style="color:#FF0000;"><strong>Enabled protocols:</strong></span>
- cache http rtmpt
- concat httpproxy rtp
- crypto icecast srtp
- data md5 subfile
- ffrtmphttp mmsh tcp
- file mmst udp
- ftp pipe udplite
- gopher rtmp unix
- hls
- <span style="color:#FF0000;"><strong>Enabled filters:</strong></span>
- adelay crop nullsrc
- aecho curves overlay
- aeval dctdnoiz pad
- aevalsrc decimate pan
- afade dejudder perms
- aformat deshake pixdesctest
- ainterleave drawbox psnr
- allpass drawgrid removelogo
- alphaextract earwax replaygain
- alphamerge edgedetect rgbtestsrc
- amerge elbg rotate
- amix equalizer scale
- amovie extractplanes select
- anull fade sendcmd
- anullsink field separatefields
- anullsrc fieldmatch setdar
- apad fieldorder setfield
- aperms flanger setpts
- aphaser format setsar
- aresample fps settb
- aselect framepack showcqt
- asendcmd framestep showinfo
- asetnsamples gradfun showspectrum
- asetpts haldclut showwaves
- asetrate haldclutsrc shuffleplanes
- asettb hflip signalstats
- ashowinfo highpass silencedetect
- asplit histogram silenceremove
- astats hqx sine
- astreamsync hue smptebars
- atempo idet smptehdbars
- atrim il split
- avectorscope interleave swapuv
- bandpass join telecine
- bandreject lenscorrection testsrc
- bass life thumbnail
- bbox lowpass tile
- biquad lut transpose
- blackdetect lut3d treble
- blend lutrgb trim
- cellauto lutyuv unsharp
- channelmap mandelbrot vflip
- channelsplit mergeplanes vignette
- codecview movie volume
- color negate volumedetect
- colorbalance noformat w3fdif
- colorchannelmixer noise xbr
- compand null yadif
- concat nullsink zoompan
- copy
- <strong><span style="color:#FF0000;">Enabled bsfs:</span></strong>
- aac_adtstoasc imx_dump_header mp3_header_decompress
- chomp mjpeg2jpeg noise
- dump_extradata mjpega_dump_header remove_extradata
- h264_mp4toannexb mov2textsub text2movsub
- <strong><span style="color:#FF0000;">Enabled indevs:</span></strong>
- dv1394 lavfi v4l2
- fbdev oss
- <strong><span style="color:#FF0000;">Enabled outdevs:</span></strong>
- fbdev oss v4l2
- License: LGPL version 2.1 or later
- Creating config.mak, config.h, and doc/config.texi...
- config.h is unchanged
- config.asm is unchanged
- libavutil/avconfig.h is unchanged
如果我们对ffmpeg按照上文进行裁剪,则./configure输出的信息是这样的:
比起之前的一堆东西,裁剪之后的静态库只是有目的的Enbale了一小部分编码器和解码器,filters和muxers也去掉了大部分,因此会变得很小。
install prefix /usr/local
source path .
C compiler gcc
C library glibc
ARCH x86 (generic)
big-endian no
runtime cpu detection yes
yasm yes
MMX enabled yes
MMXEXT enabled yes
3DNow! enabled yes
3DNow! extended enabled yes
SSE enabled yes
SSSE3 enabled yes
AVX enabled yes
XOP enabled yes
FMA3 enabled yes
FMA4 enabled yes
i686 features enabled yes
CMOV is fast no
EBX available yes
EBP available yes
debug symbols no
strip symbols yes
optimize for size yes
optimizations yes
static yes
shared yes
postprocessing support yes
new filter support yes
network support no
threading support pthreads
safe bitstream reader yes
SDL support no
opencl enabled no
texi2html enabled no
perl enabled yes
pod2man enabled yes
makeinfo enabled no
makeinfo supports HTML no
External libraries:
iconv libvo_aacenc libx264
Enabled decoders:
aac h263 mpeg4
aac_latm h264
Enabled encoders:
libvo_aacenc libx264
Enabled hwaccels:
Enabled parsers:
aac ac3 h264
aac_latm h263 mpeg4video
Enabled demuxers:
avi mov mpc
h264
Enabled muxers:
avi mov mp4
Enabled protocols:
file
Enabled filters:
amix color pad
anull null scale
aresample overlay
Enabled bsfs:
aac_adtstoasc h264_mp4toannexb
Enabled indevs:
Enabled outdevs:
License: nonfree and unredistributable
Creating config.mak, config.h, and doc/config.texi...
config.h is unchanged
config.asm is unchanged
libavutil/avconfig.h is unchanged