Fix Corrupted MP4 Header Using FFmpeg Faststart

This guide explains how to repair a corrupted MP4 file header using the -movflags faststart option in FFmpeg. When an MP4 video recording is interrupted—due to a sudden power outage, crash, or camera disconnection—the file’s metadata index (known as the moov atom) is often left incomplete or misplaced at the end of the file, making it unplayable. By using FFmpeg to restructure the container and relocate this header to the beginning of the file, you can restore playability to your damaged video.

Understanding the Problem

In a healthy MP4 container, the moov atom acts as the index for the video and audio streams. Most media players need to read this index first to understand how to play the file.

If a recording terminates abnormally, this index is either missing or corrupted. The -movflags faststart option in FFmpeg is designed to shift this index to the very beginning of the file. While typically used to optimize videos for web streaming, this process can also reconstruct and finalize a damaged or poorly structured header.

How to Fix the MP4 Header with FFmpeg

To run this process, you will need FFmpeg installed on your system and access to a command-line interface (Terminal on macOS/Linux or Command Prompt/PowerShell on Windows).

Step 1: Open Your Command Line

Navigate to the folder containing your corrupted MP4 file using the cd command. For example:

cd /path/to/your/video/folder

Step 2: Run the FFmpeg Command

Execute the following command to process the file:

ffmpeg -i corrupted.mp4 -c copy -movflags faststart fixed.mp4

Step 3: Command Breakdown

Troubleshooting: What to Do If It Fails

If the file is so severely corrupted that FFmpeg cannot read the input file at all (returning a “moov atom not found” error), a simple copy command may not work. In this scenario, you have two options:

1. Remux the Streams into a New Container

If the header is missing entirely, you can force FFmpeg to ignore the container structure and read the raw packets to remux them into a fresh container:

ffmpeg -err_detect ignore_err -i corrupted.mp4 -c copy -movflags faststart fixed.mp4

2. Use a Reference File (For Missing Moov Atoms)

If the moov atom is completely missing, FFmpeg cannot guess the parameters of the video. You will need a “reference file”—a working video recorded with the exact same camera, resolution, and frame rate settings.

In these extreme cases, command-line utilities like untrunc are required alongside FFmpeg to clone the working header structure from the healthy video and apply it to the corrupted one.