I have an mp4 file that seems to have gotten corrupted somehow:

$ file HDV_1042.MP4
HDV_1042.MP4: data

$ mediainfo HDV_1042.MP4
Complete name                            : HDV_1042.MP4
File size                                : 1.72 GiB

$ ffprobe HDV_1042.MP4 
avprobe version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2007-2013 the Libav developers
  built on Apr  2 2013 17:02:36 with gcc 4.6.3
HDV_1042.MP4: Invalid data found when processing input

$ AtomicParsley HDV_1042.MP4 -T 1

AtomicParsley error: bad mpeg4 file (ftyp atom missing or alignment error).

I tried recovering it with 'untrunc' using a working file from the same camera, but that didn't work:

$ ./untrunc HDV_1041.MP4 HDV_1042.MP4 Reading: HDV_1041.MP4
Composition time offset atom found. Out of order samples possible.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'HDV_1041.MP4':
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    creation_time   : 1947-10-13 12:23:13
  Duration: 00:21:20.25, start: 0.000000, bitrate: 12131 kb/s
    Stream #0.0(eng): Video: h264 (Main), yuv420p, 1280x720, 11988 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 180k tbc
      creation_time   : 1947-10-13 12:23:13
    Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 128 kb/s
      creation_time   : 1947-10-13 12:23:13
Failed to parse atoms in truncated file

Also tried ffmpeg/avconv without success:

$ avconv -f h264 -i HDV_1042.MP4 -c:a copy -c:v copy HDV_1042.mp4 
avconv version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:02:36 with gcc 4.6.3
[h264 @ 0x1359ac0] non-existing PPS referenced
[h264 @ 0x1359ac0] non-existing PPS 0 referenced
[h264 @ 0x1359ac0] decode_slice_header error
[h264 @ 0x1359ac0] non-existing PPS 1 referenced
[h264 @ 0x1359ac0] decode_slice_header error
[h264 @ 0x1359ac0] no frame!
[h264 @ 0x134f9e0] Estimating duration from bitrate, this may be inaccurate
Input #0, h264, from 'HDV_1042.MP4':
  Duration: N/A, bitrate: N/A
    Stream #0.0: Video: h264, 25 fps, 25 tbr, 1200k tbn, 2400k tbc
Output #0, mp4, to 'HDV_1042.mp4':
Output file #0 does not contain any stream

Here's example of a working file from the same camera:

$ mediainfo HDV_1041.MP4
Complete name                            : HDV_1041.MP4
Format                                   : MPEG-4
Format profile                           : JVT
Codec ID                                 : avc1
File size                                : 1.81 GiB
Duration                                 : 21mn 20s
Overall bit rate                         : 12.1 Mbps
Writing library                          : SEC 

ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 21mn 20s
Bit rate mode                            : Variable
Bit rate                                 : 12.0 Mbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Frame rate                               : 59.940 fps
Minimum frame rate                       : 59.920 fps
Maximum frame rate                       : 59.960 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.217
Stream size                              : 1.79 GiB (99%)
Title                                    : HMX-H300
Language                                 : English

ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 21mn 20s
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Stream size                              : 19.5 MiB (1%)
Title                                    : HMX-H300
Language                                 : English
  • BTW, I don't need to recover audio, just video. Not sure if that makes recovery easier..
    – user145664
    Oct 14, 2013 at 17:02
  • mp4repair.org claims it can repair but wants $60. Not sure this clip is worth that to me. :-)
    – user145664
    Oct 15, 2013 at 0:34
  • Looks like there are a number of commercial tools that claim to be able to repair. Repair also seems possible with free tools, for instance using a hex editor. I tried using 'wxhexeditor' on Linux to add missing data from a working file to a non-working file, then converting to binary using 'xxd -r' but couldn't get the 'fixed' file to play. Clearly skill, and understanding of the mp4 file structure is required. :-)
    – user145664
    Oct 19, 2013 at 6:07
  • "tried using 'wxhexeditor' .. Clearly skill, and understanding of the mp4 file structure is required." FWIW, I made a video recently in which I repair a broken mov (same structure as mp4) using a hex editor + some minimal required knowledge: youtube.com/watch?v=-4X-zpotg2M Oct 23, 2023 at 20:39

5 Answers 5


I have Video Repair Tool and untill now i have managed to fix most of the corupted MP4 files. At least you can try it as trial will repair half of your file, so you can see if it works. Downside is that it's not free and it's a little bit expensive for ocassional usage

  • Thanks for the tip. Tried a demo version of the tool but it wasn't able to repair.
    – user145664
    Oct 14, 2013 at 20:36
  • 1
    Actually, I ran this tool again and it worked. It's Win/Mac only, but works fine under Wine on Linux as well.
    – user145664
    Oct 19, 2013 at 5:58

You might try this:

Here's an alternative for those of you that need to recover MP4 AVC: Mega Download.

This utility can recover H.264/AVC streams from unfinalized MP4/MOV files without (or empty) header.  You may got the unfinalized file in case of damaging camcorder during recording or such.  This utility has been tested with files recorded by GoPro, but it may work with other camcorders too.

  recover_mp4_to_h264 in_good_similar.mp4 --avcc
  recover_mp4_to_h264 in_corrupted.mp4 out_video.h264 [out_audio.aac | out_audio.wav | out_audio.mp3] [<recorder>]
  recover_mp4_to_h264 in_corrupted.mp4 out_video.h264 [--aac | --pcm | --mp3] [<recorder>]

Supported recorders:
  Default is Ambarella (used in GoPro, etc.)
  Specify --eos in case of Canon EOS
  Specify --apple in case of some Apple software encoder
  Specify --htc in case of HTC smartphone
  Specify --motorola in case of Motorola smartphone
  Specify --samsung in case of Samsung camcorder

Step 1: Use any good previous file with the same resolution and bitrate to generate the AVC configuration record; for example,

recover_mp4_to_h264.exe GOPR0346.MP4 --avcc

Note: It will create the file 'avcc.hdr' in the current directory.

Step 2: Recover the H.264 stream from the corrupted file; for example,

recover_mp4_to_h264.exe GOPR0347.MP4 GOPR0347.h264 GOPR0347.aac

Note: The file 'avcc.hdr' must exist. Note: Specify --pcm or the WAV file name in case of recovering MOV file written by Canon EOS.

Step 3: Use any other utility (Yamb or FFmpeg, for example) to recreate the MP4/MOV file from the H.264 stream (GOPR0347.h264). Note MP4 does not support PCM sound; you must create MOV in this case:

ffmpeg.exe -r 30 -i recovered.h264 -i recovered.wav -vcodec copy -acodec copy result.mov
  • Worked for me, thanks. Also mentioned on stackoverflow: stackoverflow.com/questions/23202611/… Dec 28, 2014 at 17:26
  • Would this fix videos recorded with Lumia camera?
    – RogUE
    Jul 9, 2015 at 1:18
  • I don't see why it wouldn't if it records to an mp4 format.
    – Andrew
    Mar 17, 2016 at 21:27
  • Windows only :( Nov 6, 2020 at 1:23
  • It seems to work fine for me utilizing wine on Linux.
    – Andrew
    Nov 7, 2020 at 17:37

In response to comment: "Looks like there are a number of commercial tools that claim to be able to repair. Repair also seems possible with free tools, for instance using a hex editor. I tried using 'wxhexeditor' on Linux to add missing data from a working file to a non-working file, then converting to binary using 'xxd -r' but couldn't get the 'fixed' file to play. Clearly skill, and understanding of the mp4 file structure is required. :-)"

Using a hex editor to repair corrupt MOV/MP4 videos

Using a hex editor + minimal amount of knowledge can sometimes help you repair unplayable MP4 (or MOV) videos.

Atoms and offsets

A valid MP4/MOV video ate least consists of these three atoms (sections):

  • ftyp: (often if people talk about repairing the header, they mean this atom.
  • mdat: This is the actual video & audio data
  • moov: You could regard this the 'index' of the file. As the video data is compressed and different parts of the videos result in different compression ratios an index is kept to keep track of chunks of video data.

These are what I call 'root' atoms, atoms themselves can consist of several sub atoms or branches. But in general you want to check if these three root atoms are present.

Each atom is preceded by a 4 byte size + marker, so for example x x x x f t y p. Because of this if we find start of an atom we can use size to determine where next atom should start. If it does not start at that location, we have a problem. Something like may already explain why the file does not play.

enter image description here

Usually the first atom is ftyp at offset 4 into the file. Four bytes preceding (big endian) are the size of the atom, I prefer using a hex editor that does the hex > decimal conversion automatically (many actually do). So then 00 00 00 1C gets us 28. So at offset 4 + 28 we should find next atom, which seems we do:

enter image description here

we can then apply same logic to find the location for the next atom. So every time we simply take offset to the atom + size of atom = offset next atom.

Examining a corrupt file (MP4 or MOV)

This particular file does unexpectedly not start with an ftyp atom. So what we can do is search the file for the lower case string 'ftyp':

enter image description here

We could them apply information from the first paragraph and see that we find next atom (moov). If we take size for moov atom we find a free atom, if we again take size for that we find a mdat atom. At the end of this atom we find zeros, so it seems all our value result in a complete file:

enter image description here

If we copy all data from offset ftyp - 4 to end of mdat we may end up with a playable file.

Excavating atoms

Basically if I examine this file I get following layout:

  • 0000 - block of zeros
  • mdat - an mdat atom (file 2 using untrunc)
  • 0000 - more zeros
  • .... - 'random' data
  • ....
  • ftyp - (file 1)
  • moov - (file 1)
  • free - (file 1)
  • mdat - (file 1)

File 1: The ftyp, moov,free,mdat atoms result in a playable file. The entire block is simply selected and copied into a new file that is then saved with a .mov extension.

File 2: The orphaned mdat atom can be made playable using Untrunc and by using the first 'recovered' video as a reference (Untrunc requires a working reference file from same camera). For this we select the mdat atom and export it to a new file we save with a .mov extension. Untrunc syntax is untrunc goodfile brokenfile

enter image description here

Admittedly not every broken MP4 video can be repaired this way, but it may give you guidance, some idea of what can be achieved using a hex editor.

I also made a video guide based on this same corrupt MOV file: https://youtu.be/-4X-zpotg2M


I installed untrunc via docker and followed the instructions and it works for me.

Before untrunc, I tried ffmpeg docs and it not worked for me
ffmpeg -r 30 -i recovered.mp4 -vcodec copy -acodec copy fixed.mp4

  • The instruction steps need to be listed here in this post in order for it to qualify as an answer and not just a link. The link should be kept for attribution and further research, but the steps themselves must be here in this post. Oct 23, 2023 at 19:31
  • untrunc was already tried by OP? Oct 23, 2023 at 20:34

I have seen and used many tools myself, and lately I've been using some common free tools that are working way better than paid tools. If your video still hasn't been repaired, you may also try the following tool: https://www.datarepairtools.com/blog/video-repair/

This tool is available in a free and paid version. You can use whatever suits you. Thank me later...


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .