How This Video Repair Works

A plain-language look at what is inside an MP4 file, what goes wrong, and what the repair does step by step.

By Pritibhukhan Borah, Computer Science Engineer · Last updated: 2026-11-02

1. What is inside an MP4 or MOV file

MP4 and MOV files are built from "boxes". Each box has a size, a four-letter type and a payload. Three matter here:

  • ftyp: the file type and compatible brands (a few dozen bytes).
  • mdat: the media data, which is the compressed video and audio, usually 99.9% of the file.
  • moov: the movie box. It holds the codec settings (for H.264: the SPS and PPS parameter sets in an avcC box) and the sample tables: how many samples, how long each lasts, how big each is, which are keyframes, and where each sits in the file.

2. What goes wrong

Recording devices cannot know the final tables until recording ends, so most write moov last. If the recording ends abnormally, the file contains ftyp and mdat (sometimes with a placeholder size that was never updated) but no moov. Players cannot play data they cannot index.

3. What the repair does

  1. Read the referenceThe tool parses the healthy file's moov to get the codec settings, timescale, frame duration and track headers. It also samples the first frames to learn what this device's frames look like.
  2. Find the media dataIt locates the corrupted file's mdat, even if the size field is zero or wrong.
  3. Scan for framesVideo samples in H.264 and H.265 are made of length-prefixed NAL units. The tool walks the media data, recognises where each video frame starts and ends, and notes which are keyframes. The bytes between video frames are audio.
  4. Find audio frame boundariesAAC frames have no length markers, so the tool parses each frame's bitstream just far enough to learn where it ends. This does not decode sound.
  5. Write a new indexIt builds fresh sample tables and a new moov, reusing the reference's codec settings, and puts it after the media data.
  6. Assemble the fileThe output is the header, the original media data (not copied into memory) and the new index.

4. Why it runs in the browser

The repair never needs to change your video data, only to describe it. That makes it cheap enough to run on your own computer in a Web Worker. Streaming the data in slices means file size is not limited by memory, and nothing needs to be uploaded.

5. How AVI repair differs

AVI is a much older, simpler container (RIFF). The header at the start lists the streams and a frame count, then the media is stored as a plain sequence of labelled chunks (00dc for video frame, 01wb for audio), each stating its own length, and an idx1 index is added at the end. When recording stops early, the header still shows placeholder counts and sizes and the index is missing.

  1. Read the headerThe stream list (codecs, frame rate, audio format) is already in the file, so no reference is normally needed.
  2. Walk the chunksBecause every chunk carries its own length, every frame can be found exactly. If bytes are damaged, the tool skips ahead to the next chunk that checks out. A chunk cut off at the end of the file is dropped.
  3. Write a new header and indexFrame counts and sizes are corrected, keyframes are marked (known for Motion-JPEG, MPEG-4 and H.264), and a new idx1 is built. The video and audio data itself is copied unchanged, so any codec works.

Only if the AVI header itself is destroyed does the tool use a healthy AVI from the same device as a reference, to take the stream description from it.

6. Limitations

  • The reference must match the recording settings, because the codec setup comes from it.
  • Frame order for videos with B-frames is not reconstructed.
  • Audio is kept only for AAC-LC.
  • Variable-frame-rate recordings are rebuilt with the reference's dominant frame duration.
  • Corruption inside the picture data cannot be undone.
  • AVI files over 4 GB are repaired without an index, because the classic AVI index cannot address them; most players still play them.
  • MKV, WMV and MTS/M2TS files are not supported.

7. Open-source credits

The approach follows the principle of the open-source tool untrunc. AAC frame-length detection uses code derived from AAC.js by Devon Govett (Official.fm Labs), licensed under the GNU LGPL v3. The scripts on this site are served unminified so you can read them.

Ready to try it?

Open the video repair tool, or read about the "moov atom not found" error.

Frequently asked questions

Is this the same as untrunc?

It follows the same idea: use a healthy reference to rebuild the missing index of an MP4/MOV file. The code here is separate, written in JavaScript to run in a browser, and also repairs AVI files.

Why not just use FFmpeg?

FFmpeg reads the index, so it cannot open a file whose index is missing (the "moov atom not found" error). Rebuilding that index is what this tool does. For files that FFmpeg can already read, re-muxing with FFmpeg is a fine alternative.

Does the tool decode or re-encode my video?

No. It only finds where each frame starts and ends and writes a new index. The video and audio bytes are left untouched.