Monitoring FFmpeg CPU Usage with Linux Tools

This article provides a practical guide on how to monitor the CPU usage of an active FFmpeg process using native Linux command-line utilities. You will learn how to use real-time interactive tools like top and htop, extract precise snapshots using ps, and log performance data over time with pidof and awk. Whether you need a quick glance at system resources or a automated script for performance logging, these standard tools have you covered.

Real-Time Monitoring with Top and Htop

The most straightforward way to check resource consumption is through dynamic system monitors. They provide a live, updating view of exactly how much processing power FFmpeg is consuming.

Capturing Single Snapshots with Ps

When you need a quick, static measurement—or want to pass the data to another script—the ps tool is highly effective. It allows you to customize the output format to grab exactly what you need.

To view the PID, command, and exact CPU utilization of all running FFmpeg processes, use:

ps -C ffmpeg -o pid,%cpu,cmd

The %cpu value returned represents the CPU time used divided by the time the process has been running, expressed as a percentage. On multi-core systems, highly parallelized FFmpeg tasks can easily exceed 100%, as each fully utilized core adds an additional 100% to the total.

Logging CPU Usage Over Time

If you are running a long encoding job and want to track its performance history, you can combine standard tools into a simple loop to log data to a file.

The following bash one-liner captures the CPU usage of FFmpeg every second and appends it to a text file with a timestamp:

while pgrep -x ffmpeg > /dev/null; do ps -C ffmpeg -o %cpu= | awk '{print strftime("%Y-%m-%d %H:%M:%S"), $1"%"}'; sleep 1; done > ffmpeg_cpu_log.txt

This script monitors the process implicitly. As soon as the FFmpeg encoding job finishes, the loop terminates automatically, leaving you with a clean dataset ready for analysis or graphing.