Build Minimal FFmpeg with H.264 and AAC Decoders

Compiling a custom, lightweight version of FFmpeg can drastically reduce binary size and memory usage by stripping away unused codecs and features. This guide provides a precise shell configuration script and compilation steps to build a minimal FFmpeg binary optimized strictly for decoding H.264 video and AAC audio.

The Minimal Configuration Script

To build a stripped-down version of FFmpeg, you must start by disabling all default components using the --disable-everything flag. You then selectively re-enable only the H.264 and AAC decoders, along with the essential demuxers, parsers, and protocols required to read and process container formats like MP4.

Create a file named build_minimal_ffmpeg.sh and paste the following script:

#!/usr/bin/env bash

# Exit immediately if a command exits with a non-zero status
set -e

# Run the configure script with minimal flags
./configure \
  --disable-gpl \
  --disable-doc \
  --disable-programs \
  --enable-ffmpeg \
  --disable-everything \
  --disable-network \
  --disable-autodetect \
  --enable-decoder=h264 \
  --enable-decoder=aac \
  --enable-parser=h264 \
  --enable-parser=aac \
  --enable-demuxer=mov \
  --enable-demuxer=h264 \
  --enable-demuxer=aac \
  --enable-protocol=file \
  --disable-hwaccels \
  --disable-filters \
  --disable-swscale \
  --disable-devices

Understanding the Configuration Flags

Compilation Steps

Once the configuration script is ready, execute the following commands in your terminal from the root of the FFmpeg source directory:

  1. Make the script executable:

    chmod +x build_minimal_ffmpeg.sh
  2. Run the configuration script:

    ./build_minimal_ffmpeg.sh
  3. Compile the binary using your available CPU cores (e.g., 4 cores):

    make -j4

Upon successful compilation, the resulting ffmpeg binary will be located in the root source directory. This binary will be significantly smaller than a standard distribution build, often occupying only a few megabytes.