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:
stdin(Standard Input / File Descriptor 0): The stream used to send data to a program.stdout(Standard Output / File Descriptor 1): The stream where a program sends its normal operational data.stderr(Standard Error / File Descriptor 2): The stream reserved specifically for error messages and diagnostic data.
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.txtIf 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.txtRedirecting 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>&1In 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.txtLogging 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.txtFiltering 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.txtAvailable 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.