Measure FFmpeg Encoding Speed and Frame Rate in Real-Time
Monitoring the performance of an FFmpeg process is crucial for optimizing video processing pipelines. This article explains how to measure FFmpeg encoding speed and frame rate in real-time using built-in command-line outputs, progress logging flags, and terminal-based parsing to capture live performance metrics.
Method 1: Reading the Interactive Console Output
By default, when you run an FFmpeg command in your terminal, it displays a live-updating status line at the bottom of the console. This is the simplest way to monitor performance manually.
During an active encode, look for the following key metrics in the console output:
fps=: Indicates the current frame rate (frames processed per second).speed=: Indicates the processing speed relative to real-time. For example,2.0xmeans FFmpeg is encoding twice as fast as the video’s actual playback duration, while0.5xmeans it is encoding at half-speed.
Method
2: Using the -progress Flag for Programmatic
Monitoring
If you need to parse performance data programmatically using Python,
Node.js, or Bash, parsing the standard terminal output can be
unreliable. FFmpeg provides a dedicated -progress option
that outputs clean, machine-readable key-value pairs to a file, a pipe,
or the standard output.
To pipe the real-time progress metrics directly to your terminal output, use the following syntax:
ffmpeg -i input.mp4 -progress - output.mp4Using -progress - redirects the performance stream to
stdout. Every second, FFmpeg will output a block of text
containing specific metrics:
frame=1240
fps=59.8
stream_0_0_q=28.0
bitrate= 1850.4kbits/s
total_size=12582912
out_time_us=54000000
out_time_ms=54000000
out_time=00:00:54.000000
dup_frames=0
drop_frames=0
speed=2.15x
progress=continue
Method 3: Filtering Real-Time Metrics via Command Line
If you want to view only the speed and frame rate in your
terminal without the rest of the verbose FFmpeg output, you can combine
the -progress flag with command-line utilities like
grep or awk to filter the stream in
real-time.
Run the following command to filter and print only the
fps and speed values as they update:
ffmpeg -i input.mp4 -progress - output.mp4 2>&1 | grep -E "^(fps|speed)="Explanation of the command:
-progress -: Sends the clean metrics to standard output.2>&1: Redirects FFmpeg’s standard error (which contains the heavy stream information) to standard output so it can be filtered.grep -E "^(fps|speed)=": Filters the output line-by-line, displaying only the lines that start withfps=orspeed=.