Measure CPU Times with FFmpeg Benchmark Mode
This article explains how to use FFmpeg’s built-in benchmarking features to measure CPU performance during media processing. You will learn the specific command-line flags required to trigger benchmark mode, how to read the resulting console output, and what the user and system CPU times mean for your system’s performance.
To run an FFmpeg command in benchmark mode, you need to add the
-benchmark option to your command. This flag instructs
FFmpeg to measure and display CPU usage and execution time once the
processing is complete.
The Benchmark Command
To measure CPU times, place the -benchmark flag before
or after your input, but before the output file. Here is a standard
template:
ffmpeg -benchmark -i input.mp4 -c:v libx264 -preset fast output.mp4For more detailed performance tracking across individual steps of the
pipeline (like decoding, filtering, and encoding), you can use the
-benchmark_all flag instead:
ffmpeg -benchmark_all -i input.mp4 -c:v libx264 -preset fast output.mp4Understanding the Benchmark Output
Once the FFmpeg process finishes, the terminal will display a summary block containing the benchmark results. The output looks similar to this:
bench: utime=12.450s stime=1.120s rtime=4.850s maxrss=148532KiB
These values represent the following metrics:
- utime (User CPU Time): The total amount of time the CPU spent executing FFmpeg code in “user mode” (outside the kernel). This includes heavy computational tasks like video decoding, filtering, and encoding.
- stime (System CPU Time): The total amount of time the CPU spent executing system calls within the kernel on behalf of FFmpeg. This typically involves disk I/O operations (reading the input file and writing the output file) and memory allocation.
- rtime (Real / Wall-clock Time): The actual elapsed physical time from the moment the command started to the moment it finished.
- maxrss (Maximum Resident Set Size): The peak physical memory (RAM) used by the FFmpeg process during execution, measured in kilobytes (KiB).
Analyzing the Results
To determine how efficiently FFmpeg is utilizing your CPU, compare
the sum of the CPU times (utime + stime) against the real
elapsed time (rtime).
If your system has a multi-core processor and FFmpeg is utilizing
multiple threads, the combined CPU time (utime + stime) can
be significantly higher than the real time (rtime). For
example, if utime is 20 seconds and rtime is 5
seconds, FFmpeg successfully parallelized the workload across an average
of 4 CPU cores.