There are several signs that an MP4 file may be corrupted. Unplayability, corrupted frames, and damaged metadata; you’ll notice one or more when you try to open the file with a video player.
FFmpeg is a solution you may have seen floating around on the internet, and for good reason. It’s a very powerful tool that can fix corrupted video files, as well as perform a host of other tasks. There are a couple of ways you can do this, and I’ll demonstrate some proven ways that FFmpeg can repair MP4 videos.
Getting Started With FFmpeg
FFmpeg is an open-source tool widely used for handling multimedia files. It can decode, encode, transcode, combine (mux) or split (demux) streams, filter, and play almost any multimedia file that exists. Its versatility allows for a range of applications, including extracting audio from video, stabilizing footage, and re-encoding video files. It’s even used by popular platforms and applications like Google Chrome, VLC, and Discord.
We’re going to be using FFmpeg to repair corrupted video files. To get started, download FFmpeg. Officially, only the source code is available for download on the FFmpeg website, but you’ll also find links to third-party compiled versions (like the FFmpeg builds by gyan.dev). ‘Vanilla’ FFmpeg does not have a graphical user interface (GUI), so it operates through a command-line interface (CLI) like Command Prompt, PowerShell, or Terminal. However, there are some GUI-based tools that make use of FFmpeg under the hood, such as Handbrake and Shutter Encoder, which may be able to do the trick.
FFmpeg Installation Guide
Here’s what you need to do to install FFmpeg. For reference, I’m using the full build by gyan.dev:
- After downloading FFmpeg, extract it somewhere on your computer.
- Click Start and search “Environment Variables”. Click Edit the system environment variables.
- Click Environment Variables.
- Locate the Path variable under your user profile and click Edit.
- Click Browse and select the bin folder that contains ffmpeg.exe.
- Click OK to close the window, then OK again to close the other window.
How to Repair Corrupted MP4 Video Files With FFmpeg
File corruption can happen on any device, especially on dashcams and drones that crash or run out of battery mid-recording, but also in less common cases like when parts of an MP4 file fail to copy correctly to a disk with bad sectors. I’m familiar with three ways that FFmpeg can fix MP4 files, each working a little bit differently.
If you plug your device into the computer and can’t see any video files, try scanning it with the data recovery tool Disk Drill. Sometimes the files are hidden from normal view because they weren’t finished saving, but Disk Drill can find and recover these files for you to repair.
Method 1: Container Rebuild
In MP4 files, atoms – such as ftyp, moov, and mdat – contain essential information pertaining to the structure of the video file. If an atom is misplaced, the file may become truncated, preventing video players from correctly locating the start and end points of the file. This is a fairly common cause of corruption that is relatively easy to fix. To do so, you will need to copy the video to a fresh container. This will fix misplaced atoms, rewrite metadata, and maintain the original quality.
FFmpeg cannot replace missing atoms, so this method is only viable for video files that contain misplaced moov or ftyp atoms.
This solution also allows you to change containers (e.g. MP4 to AVI), as recommended here on Reddit, though it’s not necessary. Here are some instructions on how to use FFmpeg to fix a broken MP4 file by rebuilding its container:
- Open the folder that contains the corrupted video. Right-click an empty space in File Explorer, then click Open in Terminal.
- Enter the following command in Terminal, replacing video_corrupted.mp4 with the name of your corrupted video file and video_fixed.mp4 with your preferred output name. Press Enter.
ffmpeg -i video_corrupted.mp4 -c copy video_fixed.mp4
Method 2: Error Detection
If a container rebuild didn’t work, you can use FFmpeg to scan the file for errors within the video file and force it to discard any corrupt frames or sections it discovers. Keep in mind that this means the final result may include frame skips in parts where corruption has been removed.
Using FFmpeg to detect and remove corrupted frames is easy and only requires one command:
- Open the folder that contains the corrupted video. Right-click an empty space in File Explorer, then click Open in Terminal.
- Enter this command.
ffmpeg -err_detect aggressive -fflags discardcorrupt -i video_corrupted.mp4 video_fixed.mp4
Method 3: Re-encode the Video File
There’s another, more advanced method for using FFmpeg to fix a corrupted MP4 video. It involves completely re-encoding the video. This method is more time-consuming and results in a much larger file size due to the flags used, but it has proven successful for users on Stack Exchange.
This is how you re-encode a corrupted video file with FFmpeg:
- Open the folder that contains the corrupted video. Right-click an empty space in File Explorer, then click Open in Terminal.
- Enter the following command, replacing video_corrupted.mp4 with your corrupted video file and video_fixed.mp4 with the preferred output name. Press Enter.
ffmpeg -vcodec mpeg4 -b:v 7561k -qscale:v 2 -acodec aac -ac 2 -async 1 -strict experimental ./video_fixed.mp4 -threads 0 -i video_corrupted.mp4
- Enter the following command to re-encode into H.264, again, replacing the necessary filenames with your own. Press Enter.
ffmpeg.exe -i "video_fixed.mp4" -c:v libx264 -crf 22 -preset slow video_fixed_h264.mp4
FFmpeg Alternatives for Corrupted Video Repair
The power of FFmpeg is undisputed. However, the tool itself is quite a challenge to install and use, especially if you’re not familiar with using a CLI. If you’re open to exploring alternatives, I’ve tried a range of software- and browser-based video repair tools that are useful alternatives to FFmpeg, in the sense that they can repair corrupted videos. Additionally, check out our list of the best video repair software for even more options.
- Clever Online Video Repair – A free and online-based video repair tool that specializes in fixing truncated files using the MP4 container, which is commonly manifests in the form of a “Moov atom not found” message. It’s relatively new in comparison to other online tools, but it’s quick, easy, and completely free with sign-up.
- Handbrake – An open-source video transcoder and a very good option for fixing corrupted MP4 files (among other formats). With Handbrake, you can re-encode the video using a GUI. Re-encoding the file has a chance of fixing it.
- Treasured by Aero Quartet – For tough cases where software can’t do the job, Treasured is a video repair service that involves having your videos manually fixed by an expert.
These options can save time and effort if you find FFmpeg too challenging to navigate. Despite its difficulty, I think learning how to use FFmpeg can be truly valuable in a lot of cases, so it’s worth sticking with it if you’ve already started.
But for the sake of exploring an easier alternative, I’ll briefly show you how to repair a corrupted video file using Clever Online Video Repair.
Here’s how:
- Visit repair.cleverfiles.com and upload your corrupted file.
- Choose the type of device the video was recorded on, or click Unknown device.
- Upload a healthy sample file. Information from this file will be used to repair the corrupted one.
- Create an account and download the repaired file for free.
Conclusion
FFmpeg can fix corrupted videos, sometimes even in cases where you thought the video was irreparable. Although it does come with a learning curve, once you have a basic grasp of how to use the tool, you’ll be surprised at how versatile it is – especially considering it’s free.
There are probably more, but I’m familiar with three ways you can use FFmpeg to fix corrupt video: (1) moving the video contents to a new, healthy container, (2) error detection, and (3) re-encoding the video. Should you find FFmpeg isn’t the best fit for you, consider some alternatives like Clever Online Video Repair or Handbrake.
FAQ
What is FFmpeg, and why is it useful for repairing video files?
FFmpeg is a free, open-source tool used for a range of tasks involving multimedia files. Because of its versatility, FFmpeg can fix video files that have been corrupted, either by moving them to a new container or re-encoding them to remove or repair the corrupted areas.
How do I know if my video file is corrupted?
A corrupted file can show one or several signs of corruption. Usually, the video file will prompt an error code stating that the file is unplayable. Other times the file may contain frame skips or audio-video sync issues.
Can FFmpeg repair severely corrupted video files?
Sure, but there’s always an extent to how much can be done. I’d say re-encoding the video is enough most of the time, and there are so many ways you can do it with FFmpeg. However, maintain realistic expectations knowing that FFmpeg, while well-equipped to handle many types of corruption, is not a fix-all solution.
What should I do if FFmpeg cannot repair my corrupted video file?
If FFmpeg or any other software solution hasn’t worked, you can try using the specialized video repair service offered by Aero Quartet. This involves having an expert manually repair the footage for you. In most cases, this is the costliest option, but it is worth the investment if you’re in a bind.
How long does it take to repair a video with FFmpeg?
It depends on many factors, but mainly the length of the video and the repair method used. If you’re simply copying the video to a container, it’s often very quick since not a lot of processing needs to be done. However, if you re-encode the file, it will take some time as it’s reprocessing the entire video, frame by frame.
Does repairing a video with FFmpeg affect its quality?
Not if you’re simply copying the video to a new container. Re-encoding the video can affect the quality, depending on the new settings that you use. However, if you keep the same settings, there should be no loss of quality.
This article was written by Jordan Jamieson-Mane, a Staff Writer at Handy Recovery Advisor. It was also verified for technical accuracy by Andrey Vasilyev, our editorial advisor.
Curious about our content creation process? Take a look at our Editor Guidelines.