Fixing and repairing MP4 videos recursively
This script is a robust automation tool designed to bulk-repair MP4 files across your directory and its subfolders. It leverages FFmpeg to fix container issues without degrading video quality.
Here is exactly how it handles the workflow:
-
Smart Recursive Scanning
The script starts by mapping the current directory tree. It looks for every.mp4file but applies an intelligent filter: it automatically ignores files that have already been repaired (ending in_fixed) or marked as corrupt (_BROKEN), preventing duplicate work. -
Non-Destructive Repair
Instead of re-encoding the video—which takes time and lowers quality—the script uses theffmpeg -c copycommand. This simply copies the video and audio streams into a fresh container, effectively rebuilding the file structure and fixing common header errors instantly. -
Safety and Verification
It operates with a “safety-first” logic. The original file is renamed to_BROKENonly if the FFmpeg repair process returns a success code. If the repair fails, your original file remains untouched, ensuring you never lose data due to a script error.