ffmpeg裁剪编译

FFmpeg可以支持模块的裁剪编译,通常我们会按默认的方式进行编译,把常用的功能模块全部编译到程序中,但是应用到嵌入式系统中,或者存储空间有限制的环境,就需要对FFmpeg进行按需编译。

默认编译

我们可以看一下通常的编译的ffmpeg文件大小,32MB (不同环境和编译选项不一样)

ffmpeg version 4.2.2 Copyright © 2000-2019 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --prefix=…/local --env=‘PKG_CONFIG_PATH=…/local/lib/pkgconfig’ --pkg-config-flags=–static --extra-ldexeflags=-static --disable-doc --disable-libxcb --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfreetype --enable-libfdk-aac --enable-libmp3lame --enable-libwebp --enable-libx265 --enable-libvmaf --extra-libs=’-lpthread -lm -lstdc++’ --extra-cflags=-I…/local/include --extra-ldflags=-L…/local/lib

gcc静态编译strip去皮后的size为32M:
-rwxr-xr-x 1 root root 32M Jan 29 14:14 ffmpeg

裁剪编译

./configure --prefix=…/local --env=“PKG_CONFIG_PATH=…/local/lib/pkgconfig” --pkg-config-flags=–static --extra-ldexeflags="-static" --disable-doc --disable-libxcb --disable-filters --disable-decoders --disable-encoders --disable-hwaccels --disable-muxers --disable-demuxers --disable-parsers --disable-bsfs --disable-protocols --disable-indevs --disable-outdevs --disable-devices --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfdk-aac --enable-encoder=libx264 --enable-decoder=h264 --enable-muxer=mp4 --enable-demuxer=mov --enable-demuxer=mpegts --enable-protocol=file --extra-libs="-lpthread -lm -lstdc++" --extra-cflags="-I…/local/include" --extra-ldflags="-L…/local/lib"

编译后的文件大小,6.9MB:
-rwxr-xr-x 1 root root 6.9M Jan 30 04:49 ffmpeg

最简编译

./configure --prefix=…/local --env=“PKG_CONFIG_PATH=…/local/lib/pkgconfig” --pkg-config-flags=–static --extra-ldexeflags="-static" --disable-doc --disable-libxcb --disable-filters --disable-decoders --disable-encoders --disable-hwaccels --disable-muxers --disable-demuxers --disable-parsers --disable-bsfs --disable-protocols --disable-indevs --disable-outdevs --disable-devices --enable-gpl --enable-version3 --enable-nonfree --extra-libs="-lpthread -lm -lstdc++" --extra-cflags="-I…/local/include" --extra-ldflags="-L…/local/lib"

编译后的文件大小 3.2MB:
-rwxr-xr-x 1 root root 3.2M Jan 30 04:56 ffmpeg

如果生产环境对文件的大小敏感,可以尝试进行按需编译来减小ffmpeg程序的文件大小,如果对存储文件不敏感,建议还是把默认相关的模块都编译到内部。

发布了141 篇原创文章 · 获赞 107 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/ternence_hsu/article/details/104114323