C.W.K.
Stream
Lesson 05 of 08 · published

Corrupt File Recovery

~10 min · recovery, corrupt, moov, untrunc

Level 0Viewer
0 XP0/73 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

The two common failure modes

  1. Truncated MP4 (no moov atom) — typically a recording that was Ctrl+C'd or a phone whose battery died mid-record. The file has data but no index. Many players show 'cannot open'.
  2. Bitstream corruption — bad sectors, partial download. Some frames decode, some don't.

Recovery tools

  • FFmpeg remux with -fflags +genpts — sometimes regenerates the moov atom.
  • untrunc — open-source tool specifically for truncated MP4 with moov missing. brew install untrunc. Needs a 'reference' file from the same camera.
  • FFmpeg -err_detect ignore_err — for corrupt bitstream, decode what's decodable and skip what isn't.

Code

Recovery attempts·bash
# Try a remux first
ffmpeg -fflags +genpts -i broken.mp4 -c copy fixed.mp4

# Skip errors and re-encode what's decodable
ffmpeg -err_detect ignore_err -i broken.mp4 \
  -c:v libx264 -crf 22 -preset fast \
  -c:a aac -b:a 192k \
  recovered.mp4

# untrunc: needs a reference (good) file from the same camera/source
untrunc reference_good.mp4 broken.mp4
# Outputs broken.mp4_fixed.mp4
Diagnose first·bash
# Check what's actually wrong
ffprobe -v error -show_error broken.mp4
# moov atom not found  → use untrunc
# Invalid NAL unit size → bitstream corruption, try ignore_err

# Estimate how much of the file is recoverable
ffmpeg -i broken.mp4 -f null - 2>&1 | grep -E 'frame=|error|Error'

External links

Exercise

Deliberately corrupt a video by truncating it: truncate -s 80% in.mp4. Try to play it (probably fails). Run the remux + genpts attempt. If that fails, brew install untrunc and try with the original file as reference. Note what fraction of the original is recoverable.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.