How to Redirect FFmpeg Errors to a File in Linux

This article provides a quick overview and practical guide on how to capture and redirect FFmpeg error logs into a text file on a Linux filesystem. When running complex video or audio conversions, terminal output can quickly overflow, making troubleshooting difficult. By understanding how Linux handles standard streams, you can easily isolate error messages, separate them from standard output, or log both simultaneously to a designated text file for later analysis.

Understanding Linux Streams and FFmpeg Output

To redirect FFmpeg’s output correctly, it helps to understand how the utility communicates with the Linux operating system. Linux uses three standard data streams:

Crucially, **FFmpeg writes almost all of its console output—including configuration details, frame rates, and errors—to stderr**, not stdout. Because of this, a standard redirection command like ffmpeg ... > log.txt will fail to capture the log, as it only redirects stdout.

Redirecting Standard Error (stderr) to a File

If you want to capture only the error messages and diagnostic information while keeping any standard output separate, you must explicitly redirect file descriptor 2.

To overwrite the file every time you run the command, use the 2> operator:

ffmpeg -i input.mp4 output.mkv 2> error_log.txt

If you prefer to maintain a running log and append new errors to the end of an existing file, use the 2>> operator:

ffmpeg -i input.mp4 output.mkv 2>> error_log.txt

Redirecting Both stdout and stderr to the Same File

In some workflows, FFmpeg might be configured to output actual video or audio data stream to stdout (for example, when piping data to another tool). If you want to merge both normal output and error logs into a single text file, you can bind stderr to stdout using 2>&1.

Use the following command to redirect both streams into one file:

ffmpeg -i input.mp4 output.mkv > combined_log.txt 2>&1

In modern Linux shells like Bash (version 4.0+), you can use a shorter alternative to achieve the exact same result:

ffmpeg -i input.mp4 output.mkv &> combined_log.txt

Logging to a File While Watching the Output Live

When a conversion takes a long time, you might want to save the logs to a text file but still monitor the progress live in your terminal. The tee command is designed for this specific purpose, as it duplicates the stream it receives.

Because tee primarily accepts input from stdout, you must first redirect FFmpeg’s stderr to stdout, and then pipe it into tee:

ffmpeg -i input.mp4 output.mkv 2>&1 | tee live_error_log.txt

Filtering Log Levels for Cleaner Text Files

FFmpeg can be incredibly verbose. If your text files are growing too large or contain too much repetitive progress data, you can restrict the output to actual errors by utilizing the -loglevel flag.

To ignore routine frame updates and only write critical errors to your text file, structure your command like this:

ffmpeg -loglevel error -i input.mp4 output.mkv 2> critical_errors.txt

Available log levels include repeat (default verbose logging), info, warning, error, and fatal. Setting the flag to error ensures that your text file remains clean, readable, and strictly focused on what went wrong during the execution.