Dear FFmpeg developers,

I would like to propose an improvement to FFmpeg's exit code behavior.

Problem

When encoding fails partway through (e.g., due to a corrupted input frame), 
FFmpeg still returns exit code 0. The output file exists with non-zero size, 
but is incomplete. This makes it impossible for programs calling FFmpeg to 
reliably detect encoding failure.

Current workarounds and their limitations:
Method
Problem

Exit code
Returns 0 even on incomplete output

Output file exists
File exists even when incomplete

File size > 0
File has content even when incomplete

Duration comparison
Unreliable when -t, -ss, or trimming is used

stderr parsing
Different encoders produce different summary lines (e.g., "Qavg" for AAC, 
"muxing overhead" for muxer, "frame=" for video). The output order is also 
inconsistent across modules.


Example: encoding a corrupted input file produces an incomplete output with 
exit code 0:
ffmpeg -i corrupted_input.mp4 -c:v libx264 -c:a aac output.mp4 echo $?   # 
returns 0, but output.mp4 is incomplete 


Proposal

Return a non-zero exit code when encoding does not complete as expected (e.g., 
end of input stream not reached, or the duration specified by -t not achieved).

This would make exit code a reliable indicator of encoding completeness, 
consistent with standard CLI conventions where exit code 0 means "the task 
completed successfully."

Additional Observation

The stderr output order is inconsistent across modules. For example:
[out#0/mp4 ...] muxing overhead: 0.326370%     ← muxer finishes first 
frame=64238 fps=484 ... time=00:42:49.55 ...   ← then frame summary [aac @ ...] 
Qavg: 65531.836                     ← then encoder summary 


There is no unified, ordered, machine-readable completion indicator in stderr 
either.

I understand this may be a design choice rather than a bug, but I believe 
reliable exit codes would greatly improve FFmpeg's usability as a programmatic 
tool.

Thank you for your time and consideration.
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to