FFmpeg Benchmark Mode for Memory Allocation

Measuring memory allocation in FFmpeg is essential for optimizing media processing pipelines, preventing out-of-memory crashes, and profiling hardware resource consumption. FFmpeg features native benchmarking flags that expose runtime statistics, including the peak resident set size (memory) used during an operation. This guide covers how to enable benchmark mode in FFmpeg to capture memory metrics and interpret the output accurately.

Using the Built-In -benchmark Flag

To measure resource usage during execution, add the -benchmark flag to your command. Place the flag after the inputs and before the output file, or right before the output.

ffmpeg -i input.mp4 -c:v libx264 -preset fast -benchmark output.mp4

To benchmark decoding or filter chains without measuring disk write overhead, route the output to the null muxer:

ffmpeg -benchmark -i input.mp4 -f null -

Understanding the Benchmark Output

Once the command finishes, FFmpeg outputs a summary line containing execution statistics:

bench: utime=1.420s stime=0.080s rtime=0.650s maxrss=142560kB
  • utime: Total CPU time spent in user mode (in seconds).
  • stime: Total CPU time spent in kernel/system mode (in seconds).
  • rtime: Real wall-clock elapsed time (in seconds).
  • maxrss: Maximum Resident Set Size. This is the peak physical memory (RAM) occupied by the FFmpeg process during execution. On Linux and macOS, this value is typically reported in kilobytes (kB).

Using -benchmark_all for Granular Tracking

If you need deeper tracking across individual passes and components rather than a single end-of-run summary, use -benchmark_all:

ffmpeg -benchmark_all -i input.mp4 -c:v libx265 -f null -

This flag prints memory and time consumption iteratively during processing, allowing you to identify memory spikes associated with specific filters, complex scenes, or keyframe intervals.

Advanced Memory Measurement with System Tools

On some platforms, FFmpeg's maxrss output depends on the underlying C library's getrusage() implementation, which can vary. For complete operating-system-level verification of memory allocation, run the command using the GNU time binary (not the shell built-in):

/usr/bin/time -v ffmpeg -i input.mp4 -c:v libx264 -f null -

In the output, locate:

  • Maximum resident set size (kbytes): Peak physical RAM usage.
  • Page faults (major/minor): Indicates whether memory paging or swapping to disk occurred.