How to Minimize libvpx Binary Size
Building the libvpx video codec library with a minimal
footprint is essential for resource-constrained environments, mobile
applications, and web deployments. This article provides a direct guide
to the configuration options and compilation flags you can use to
drastically reduce the binary size of libvpx during the
build process.
Essential Configuration Options
To configure libvpx for the smallest possible storage
footprint, run the ./configure script with the following
targeted flags:
1. Optimize for Size
--enable-small: This is the most crucial flag. It instructs the build system to optimize the compilation for size rather than speed, passing optimization flags like-Osto the compiler.
2. Disable Unused Codecs
libvpx supports both VP8 and VP9. If your project only
requires one of these formats, you should disable the other to save
significant space. * --disable-vp8:
Excludes the VP8 codec entirely. *
--disable-vp9: Excludes the VP9 codec
entirely.
3. Disable Unused Functions (Encoder or Decoder)
If your application only plays videos, you do not need the encoder.
Conversely, if your application only records or streams video, you do
not need the decoder. * --disable-encoder:
Removes all encoding algorithms and tools. *
--disable-decoder: Removes all decoding
algorithms and tools.
4. Remove Auxiliary Features and High Bit-Depth Support
--disable-vp9-highbitdepth: Disables support for 10-bit and 12-bit color depths in VP9, restricting the build to standard 8-bit. This removes a large amount of specialized code.--disable-postproc: Disables post-processing filters.--disable-multithread: If your application does not require multi-threaded encoding or decoding, disabling this removes threading overhead and synchronization code.
5. Exclude Non-Library Binaries and Documentation
By default, the build process generates example applications, unit
tests, and documentation. These should be disabled to prevent
unnecessary disk usage. *
--disable-examples: Prevents building
sample command-line tools like vpxdec and
vpxenc. *
--disable-unit-tests: Excludes the
compilation of test suites. *
--disable-docs: Skips generating
documentation files.
6. Compiler and Linker Optimizations
--enable-lto: Enables Link-Time Optimization (LTO). This allows the compiler to perform optimizations across different source files, enabling more aggressive dead-code elimination and reducing the final binary size.--disable-debug: Ensures that debug symbols are omitted from the compiled library.
Example Minimal Configuration Command
To put these options into practice, use a configuration command similar to the one below. This example builds a VP9 decoder-only library optimized strictly for size, with all non-essential features disabled:
./configure \
--enable-small \
--disable-vp8 \
--disable-encoder \
--disable-vp9-highbitdepth \
--disable-postproc \
--disable-examples \
--disable-unit-tests \
--disable-docs \
--enable-lto \
--disable-debugAfter running the configuration command, compile the library using
make. For further size reduction on the final output, you
can run strip on the generated static or shared library
file to remove any remaining symbol tables.