Redirect ffmpeg stderr to file keeping stdout
This article provides a straightforward guide on how to redirect FFmpeg’s standard error (stderr) stream to a text file while keeping the standard output (stdout) stream intact. By default, FFmpeg outputs its logs, configuration banner, and progress reports to stderr, which can interfere with pipe operations. Below, you will find the command-line techniques used to isolate these streams for clean logging and data piping.
In Unix-like operating systems and Windows Command Prompt, file
descriptor 1 represents stdout (the main data
stream) and file descriptor 2 represents
stderr (the error and log stream). To redirect only the log
output of FFmpeg to a text file, you must use the 2>
operator.
Piping stdout while saving stderr to a file
If you are piping the output video of FFmpeg to another utility
(using - to direct the output container to stdout) and want
to save the logs to a file, use the following command structure:
ffmpeg -i input.mp4 -f mpegts - 2> ffmpeg_log.txt | next_commandIn this command: * -f mpegts - forces the output format
to MPEG-TS and directs the output data stream to stdout
(-). * 2> ffmpeg_log.txt redirects all log
data and errors (stderr) into a file named ffmpeg_log.txt.
* | next_command pipes the clean stdout data stream to the
next program without any log text corrupting the media data.
Redirecting stdout and stderr to separate files
If you want to write the output file via stdout redirection and capture the logs simultaneously, you can explicitly define the destination for both streams:
ffmpeg -i input.mp4 -f mp4 - 2> error.log > output.mp4In this example: * 2> error.log sends the log stream
to error.log. * > output.mp4 (which is
shorthand for 1> output.mp4) redirects the video data
stream to output.mp4.