“moov atom not found” in FFmpeg, Python and Node.js: causes and fixes for developers

When FFmpeg, ffprobe, OpenCV, MoviePy or a Node.js library reports moov atom not found on a file your own code produced or received, the MP4 is usually not "corrupted" in the camera sense. Far more often your program opened it too early (it was still being written or downloaded), read it from a pipe that cannot seek, received a truncated or empty upload, or is not looking at an MP4 at all (an HTML error page saved as .mp4 is common). Check the size and the first bytes, make sure the writer has finished, and give FFmpeg a seekable file instead of a pipe. Only a recording that was genuinely cut off needs its index rebuilt.

This page is for developers and scripts. If you just have a personal video that will not open, go to fix "moov atom not found" instead.

What the error actually means

An MP4 or MOV is a sequence of boxes. ftyp names the format, mdat holds the audio and video frames, and moov is the index: codec settings, timestamps and the byte offset of every frame. A demuxer cannot decode anything without moov. FFmpeg's mov demuxer walks the top-level boxes and, if it reaches the end of the readable data without finding moov, prints:

`` [mov,mp4,m4a,3gp,3g2,mj2 @ 0x...] moov atom not found input.mp4: Invalid data found when processing input ``

Recorders and most encoders write moov last, after all frames are known. So any reader that only sees the first part of the file, or cannot seek to the end, hits this error even when the file will be perfect a moment later.

The six real-world causes (and how to tell them apart)

CauseTypical signFix
File still being written (recorder, encoder, ffmpeg job)Size keeps growing; error goes away laterWait for the writer to exit; write to a temp name and rename when done
Incomplete download or uploadSize smaller than Content-Length or the sourceVerify size or checksum; retry the transfer
Reading from a pipe or stream with moov at the endWorks on a file, fails on stdin: moov atom not found if the stream ends early, or stream 0, offset 0x30: partial fileSave to a seekable file first, or produce files with -movflags +faststart
Not an MP4 at allFirst bytes are <!DOCTYPE, {"error", or 1A 45 DF A3 (Matroska)Fix the URL or auth; use the right demuxer
Empty fileSize 0Nothing to parse; fix the producer
Recording really cut off (crash, power loss)mdat present, file stops mid-frameRebuild the index with a reference file

Check the size and the first bytes

`` ls -l input.mp4 xxd -l 16 input.mp4 ``

A real MP4 shows the ASCII ftyp at offset 4 (for example 00 00 00 20 66 74 79 70). If you see <!DO or {", your HTTP client saved an error page. If you see 1a45 dfa3, it is an MKV/WebM file with the wrong extension; FFmpeg will read it fine once it is not forced into the MP4 demuxer.

List the top-level boxes

A ten-line script shows whether moov exists and where:

`` import struct, sys f = open(sys.argv[1], 'rb'); pos = 0; size_total = f.seek(0, 2); f.seek(0) while pos + 8 <= size_total: f.seek(pos); size, kind = struct.unpack('>I4s', f.read(8)) if size == 1: size = struct.unpack('>Q', f.read(8))[0] elif size == 0: size = size_total - pos print(kind.decode('latin1'), pos, size) if size < 8: break pos += size ``

ftyp, mdat and no moov means the file was cut off or is still being written. An mdat whose size runs past the end of the file confirms truncation. Our browser-based MP4 file checker shows the same information without code.

Python: OpenCV, MoviePy, ffmpeg-python, PyAV

  • OpenCV: cv2.VideoCapture('input.mp4').isOpened() returns False, and the FFmpeg backend logs moov atom not found to stderr. OpenCV gives you no exception, so check isOpened() and the file size before processing.
  • MoviePy / imageio-ffmpeg: raises OSError: MoviePy error: failed to read the duration of file with the FFmpeg log containing the error.
  • ffmpeg-python / subprocess: you get a non-zero exit code; read stderr.
  • PyAV: av.open() raises av.error.InvalidDataError.

A safe pattern before handing a file to any of them:

``` import os, subprocess, json

def probe(path): if os.path.getsize(path) == 0: raise ValueError('empty file') with open(path, 'rb') as fh: head = fh.read(12) if head[4:8] != b'ftyp': raise ValueError(f'not an MP4/MOV (starts with {head[:8]!r})') r = subprocess.run(['ffprobe', '-v', 'error', '-show_format', '-show_streams', '-of', 'json', path], capture_output=True, text=True) if r.returncode != 0: raise ValueError(r.stderr.strip() or 'ffprobe failed') return json.loads(r.stdout) ```

If you process files dropped into a folder by a recorder or an upload handler, do not start on the file's creation event. Wait until the size has been stable for a few seconds, or have the producer write name.mp4.part and rename it when it is complete.

Node.js, fluent-ffmpeg and uploads

The most common Node.js cause is piping an upload stream straight into FFmpeg:

`` // fails for most phone and camera files: moov is at the end and stdin cannot seek ffmpeg(req).ffprobe(...) ``

FFmpeg cannot seek in a pipe. With the index at the end it has to read past all the frames to find moov and then cannot go back to them, so you get stream 0, offset 0x30: partial file and Invalid data found when processing input; if the client aborts the upload before the end, you get moov atom not found. The file itself may be fine. Write the upload to a temporary file first (multer disk storage, busboy to fs.createWriteStream), wait for the finish event, then run FFmpeg on the path.

For chunked or resumable uploads, assemble every chunk in order and compare the final size with what the client sent. A missing last chunk removes exactly the part that contains moov.

Producing files that never hit this error

  • Put the index first for anything that will be streamed or read progressively: ffmpeg -i in.mp4 -c copy -movflags +faststart out.mp4. See MP4 faststart explained.
  • Record to fragmented MP4 when the process might be killed: -movflags frag_keyframe+empty_moov+default_base_moof writes small self-contained fragments, so a crash loses seconds, not the whole file. See fragmented MP4 explained.
  • Stop FFmpeg gracefully: send q on stdin or SIGINT, never SIGKILL, so it can write moov. In Python, proc.communicate(b'q'); in Node.js, proc.stdin.write('q').
  • Browser recordings: MediaRecorder in Chrome produces WebM, and in Safari a fragmented MP4. Neither has a trailing moov to lose, but both lack duration metadata; remux with -c copy before serving.

When the file really was cut off

If the producer died mid-recording, the frames are in mdat and only the index is gone. -c copy, -movflags faststart and -err_detect ignore_err cannot help, because FFmpeg has no index to read. You need a tool that scans the raw frames and writes a new moov, using a reference file from the same encoder for the codec settings:

  • untrunc on the command line: untrunc reference.mp4 broken.mp4. See untrunc online.
  • The FixMP4 repair tool in the browser for H.264 or HEVC with AAC: drop the broken file and a reference, check the free preview, then export.

To test your error handling, download our corrupted MP4 sample files: each one triggers a specific failure, including moov atom not found.

FixMP4 compared with other options

FeatureFixMP4Desktop repair suitesuntrunc (CLI)VLC
Runs whereBrowser, on your deviceDesktop appCommand lineDesktop player
Keeps your file on your device✓✓✓✓
Nothing to install✓✕✕✕
Rebuilds a missing MP4/MOV index✓✓✓✕
Preview of your own repaired file before paying✓Trial (varies)Free tooln/a
Voice Memos / AAC without a referenceUsuallyVaries✕✕
Formats beyond MP4/MOV/M4A✕✓Many (FFmpeg)Plays many

Try it on your file

Free diagnosis and 15-second preview. Nothing is uploaded.

Open the repair tool

Frequently asked questions

Why does FFmpeg say moov atom not found?

FFmpeg could not find the MP4 index (the moov box). Usually the file is still being written, the download or upload is incomplete, the file is empty or not an MP4, or the recording was cut off before the index was written.

Why does OpenCV fail to open my MP4?

cv2.VideoCapture uses FFmpeg underneath. If isOpened() is False and the log shows moov atom not found, the file has no readable index; check its size and first bytes and make sure the writer has finished.

Can I read an MP4 from a pipe or stdin with FFmpeg?

Only if the index is at the front (a faststart file) or the file is fragmented MP4. Phone and camera files keep the index at the end, so save them to a seekable file first.

Does -movflags faststart fix moov atom not found?

No. Faststart moves an existing index to the front. It cannot create one that is missing.

How do I prevent moov atom not found when FFmpeg is killed?

Stop FFmpeg gracefully by sending q on stdin or SIGINT so it can write the index, or record to fragmented MP4 with -movflags frag_keyframe+empty_moov.