Step 5: Truncate the File (If Corruption is at the End)
If corruption is near the end, truncate the file:
bash
# Find the last valid timestamp from Step 2 (e.g., 00:05:30.000)
ffmpeg -i corrupt_video.mp4 -c copy -t 00:05:30 fixed_truncated.mp4
Step 6: Use untrunc (For MP4/MOV Files)
Repair MP4/MOV files by comparing with a known-good reference file:
bash
# Install untrunc (compile from source if needed)
git clone https://github.com/ponchio/untrunc.git
cd untrunc && make
# Run repair (requires a working reference file)
./untrunc good_video.mp4 corrupt_video.mp4 -o fixed_untrunc.mp4
Step 7: Extract and Re-mux Streams
If audio/video streams are intact but misaligned:
bash
# Extract audio and video separately
ffmpeg -i corrupt_video.mp4 -vn -acodec copy audio.aac
ffmpeg -i corrupt_video.mp4 -an -c:v copy video.h264
# Re-mux into a new container
ffmpeg -i video.h264 -i audio.aac -c copy fixed_remux.mp4
Step 8: Re-encode as Last Resort
If corruption is in the video stream, re-encode (quality loss possible):
bash
ffmpeg -i corrupt_video.mp4 -c:v libx264 -preset medium -c:a aac fixed_reencoded.mp4
Step 9: Check Storage Health
Rule out hardware issues:
bash
# Check disk health (replace /dev/sdX with your drive)
sudo smartctl -a /dev/sdX | grep -i "reallocated\|pending\|uncorrectable"
# Check filesystem errors
sudo fsck /dev/sdX
Step 10: Data Recovery Tools
If the file is severely corrupted, attempt recovery:
bash
# Install TestDisk/PhotoRec
sudo apt install testdisk
# Run PhotoRec to scan for recoverable video fragments
sudo photorec
Notes:
Success depends on corruption type/location (e.g., header damage vs. random frames).
Always work on a copy of the original file.
For professional workflows, consider paid tools like ** Grau GmbH Video Repair Tool** (cross-platform).