What is the moov atom, and why does losing it break your video?
By the FixMP4 engineering team · · 6 min read
If you have ever seen the message "moov atom not found", you have met the most important and most fragile part of an MP4 file. This article explains, without jargon where possible, what the moov atom is, what it contains and why a video without it is like a book without page numbers or a table of contents, glued into one long strip.
MP4 files are made of boxes
MP4, MOV, M4A and M4V all share the same structure, inherited from Apple's QuickTime format and standardised as the ISO Base Media File Format. A file is a sequence of boxes (QuickTime calls them atoms). Every box starts with eight bytes: four bytes for its size and four letters for its type. Boxes can contain other boxes, like folders.
A typical file recorded by a phone looks like this:
ftyp: "file type", a few bytes that say which flavour of MP4 this is.mdat: "media data", the actual compressed video and audio frames. This is almost the entire file.moov: "movie", the index and description of everything inmdat.
Some files contain extra boxes such as free (padding), wide (a QuickTime leftover) or uuid (vendor data), but these three are what matter.
What is inside the moov atom
The moov atom contains one trak box per track, usually one video and one audio track, sometimes metadata tracks too. Each track describes:
- the codec and its settings in the sample description box
stsd. For H.264 video this includes theavcCrecord with the SPS and PPS parameter sets: resolution, profile, frame structure. For HEVC it ishvcC, and for AAC audio theesdsbox with the AudioSpecificConfig: sample rate, channels, profile. - the size of every sample (a sample is one video frame or one audio frame) in
stsz. - where samples are in the file: samples are grouped in chunks;
stcoorco64lists the byte offset of every chunk, andstscsays how many samples each chunk holds. - timing:
sttsgives each sample's duration,cttsthe reordering offset for B-frames. - keyframes:
stsslists frames that can be decoded on their own, which is what makes seeking work.
In other words, the moov atom tells a player: "the video is HEVC 1920x1080, frame 1 starts at byte 48 and is 112,431 bytes long, it is a keyframe, display it at time 0; frame 2 starts at byte 112,479..." for every single frame.
Why the mdat alone is not enough
Compressed video frames do not carry their own sizes or timestamps in a way that players read directly. Inside mdat, frames from the video and audio tracks are simply laid out one after another, interleaved in chunks. Without the index, a player cannot tell where one frame ends and the next begins, which bytes are audio and which are video, or how to decode them, because the codec settings live in the moov atom too.
That is why a file with an intact mdat and a missing moov is completely unplayable, even though 99.9% of the data is fine.
Why the moov atom is written last
Most recorders do not know the final number of frames or their sizes until the recording ends. So they write ftyp, open an mdat box, append frames as they arrive and, when you press stop, write the moov atom at the end and go back to fix up the size of mdat.
If the recording ends abruptly (battery, crash, full card), the last step never happens. You get a file whose mdat may even claim a size of zero, and no moov atom at all.
Files prepared for web streaming are often rewritten with the moov atom at the start ("fast start"), so that playback can begin before the whole file is downloaded. That happens after recording, so it does not help with crashes.
How a missing moov atom is rebuilt
Rebuilding the index means doing the recorder's last step after the fact:
- Get the codec settings. They were in the lost moov atom, but a healthy file recorded by the same device with the same settings has identical ones. This is the "reference file".
- Find every frame in mdat. H.264 and HEVC frames are stored as length-prefixed NAL units, so the video can be walked unit by unit, and the first slice of each picture marks where a new frame starts. AAC audio frames have no length prefix, so their size has to be found by parsing the AAC bitstream itself until the end-of-frame marker.
- Recover timing and order. Frame durations come from the reference (for example 1/30 s). For video with B-frames, the picture order count in each frame's slice header tells which frame is displayed when.
- Write a new moov atom with the sizes, offsets, timings and keyframes, and a fresh header.
This is exactly what the FixMP4 repair tool does in your browser.
Key takeaways
- An MP4 is boxes:
ftyp(header),mdat(the frames) andmoov(the index). - "moov atom not found" means the index is missing, usually because recording stopped abruptly.
- The frames are normally still there and can be re-indexed, often with the help of a reference file.
Read next: how to fix "moov atom not found" and how to choose a reference file.
Have a broken recording right now?
Diagnose it and hear or watch a free repaired preview. Nothing is uploaded.
Open the repair tool