How Does mpv Handle Corrupted Media Files?

When mpv encounters a corrupted media file, its default behavior is to aggressively attempt playback by skipping damaged frames, ignoring non-fatal stream errors, and relying on its robust FFmpeg backend to decode as much data as possible. Instead of immediately crashing or throwing a blocking error dialog, mpv logs the corruption to the terminal and tries to maintain synchronization between the audio and video tracks. If the file is completely unreadable or the container headers are destroyed, mpv will gracefully terminate the playback session and output a failure message to the console.

The Role of FFmpeg Demuxing and Decoding

Because mpv uses FFmpeg libavcodec and libavformat under the hood, it inherits highly resilient decoding capabilities. When a file contains bad sectors or missing packets:

Terminal Output and Error Codes

When running mpv from the command line, you will see real-time feedback regarding the file’s integrity. If the corruption is minor, playback continues despite the warnings. However, if the file is severely broken, mpv will halt and return specific exit codes:

Customizing the Default Behavior

If you want to alter how mpv reacts to corrupted files, you can modify its behavior using specific command-line flags or by adding them to your mpv.conf file:

Halting on Errors

If you prefer mpv to stop playing immediately when an error is detected rather than trying to power through it, you can use:

--stop-on-playback-errors=yes

Adjusting Demuxer Cache

For files with corrupted indices or timestamps, increasing the demuxer cache can sometimes help mpv bridge the gap during playback:

--demuxer-max-bytes=500MiB