What You Will Learn

  • The meaning and causes of the moov atom not found error
  • The basics of the moov / mdat structure inside an MP4 file
  • How to prevent the problem with -movflags faststart
  • How to repair a file from a recording that ended midway
  • How to use the qt-faststart tool

Tested with: FFmpeg 6.1 (verified against real FFmpeg)

Tested version: FFmpeg 6.1
Target OS: Windows / macOS / Linux


What moov atom not found Means

An MP4 file is built from several structural blocks called “atoms” (or “boxes”). Among them, two are especially important:

  • mdat (Media Data atom): the actual video and audio data
  • moov (Movie atom): the file’s index information (timestamps, sample positions, and so on)

Without the moov atom, neither a player nor FFmpeg can play back or process the file.

Example error:
moov atom not found
Invalid data found when processing input

Why the moov Atom Ends Up at the End of the File

By default, FFmpeg writes the moov atom at the end of the file once encoding is complete. The reason is that during encoding the size of mdat is unknown, so the contents of moov (the offset information for each frame) cannot be finalized.

[Default structure]
ftyp | mdat (huge video/audio data) | moov (index)

This structure causes two problems:

  1. Progressive download is impossible: the browser cannot start playback until the entire file has been downloaded.
  2. Recording crashes: if the process is terminated before moov is written, you end up with a broken file that has no moov atom at all.

Prevention: -movflags faststart

When creating a new MP4, using -movflags faststart moves the moov atom to the beginning of the file:

ffmpeg -i input.mp4 -c copy -movflags faststart output_fast.mp4

This places the moov atom at the start of the file, enabling streaming playback and early display on the web.

[faststart structure]
ftyp | moov (index) | mdat (video/audio data)

Specifying faststart During Encoding

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac -movflags faststart output.mp4

Optimizing an Existing File with qt-faststart

The qt-faststart tool bundled with FFmpeg can convert an existing MP4:

qt-faststart input.mp4 output_fast.mp4

qt-faststart does not re-encode the file; it simply moves the moov atom to the front (fast and lossless).


Repairing a File Broken by a Recording Crash

A file that crashed during recording (with no moov atom) cannot be repaired by FFmpeg alone. The following tools can help.

untruncate (requires mp4fragments)

mp4recovery input_broken.mp4 output_recovered.mp4

The recover_mp4 Script

Another option is to compile and use tools/recover_mp4.c, which is included in the FFmpeg source code.

Commercial Tools

  • Remo Video Repair
  • Stellar Video Repair

Fragmented MP4 for Better Crash Resilience

For recording use cases, a fragmented MP4 that updates the moov atom frequently is effective:

ffmpeg -i input.mp4 -c copy \
  -movflags frag_keyframe+empty_moov+default_base_moof \
  -frag_duration 4000000 \
  output_frag.mp4
  • frag_keyframe: creates a fragment at each keyframe
  • empty_moov: places an empty moov atom at the start of the file
  • default_base_moof: standard base media fragment
  • -frag_duration 4000000: targets 4-second fragments (microseconds)

This format remains partially playable even if a crash occurs partway through the MP4 (a structure close to HLS/DASH).


Measured Example

Adding -movflags faststart to an existing 2 GB MP4 does not re-encode video or audio:

ffmpeg -i input.mp4 -c copy -movflags +faststart output_fast.mp4

Processing time depends heavily on storage speed. On an SSD it may take a few to a dozen seconds; on a network drive or external HDD it can take longer. Output size is usually almost identical to the input, with only metadata layout differences.

If the file is missing the moov atom because recording crashed, this command cannot repair it. faststart optimizes a valid MP4; it is not a recovery method for a broken MP4. Results vary by environment.


How to Inspect the Atom Structure of an MP4

You can examine the atom structure with ffprobe:

ffprobe -v trace -i input.mp4 2>&1 | grep -E "^(ftyp|moov|mdat)"

Frequently Asked Questions

Q: Can I just re-encode a file that gives moov atom not found?

No. Without the moov atom, FFmpeg has no way to know where the frames are in the file, so reading it fails outright. You must use a repair tool first.

Q: Should I always use -movflags faststart?

It is recommended for web and streaming use. It is unnecessary for local-only playback. For recording purposes, however, frag_keyframe+empty_moov offers better crash resilience.

Q: How long does faststart take to process?

Since it does not re-encode the file, it is very fast (within a few seconds).



Primary sources: ffmpeg.org/ffmpeg-formats.html#mp4 / trac.ffmpeg.org/wiki/Seeking