anthwlock / untrunc

Restore a truncated mp4/mov. Improved version of ponchio/untrunc
GNU General Public License v2.0
1.87k stars 182 forks source link

GoPro Recovery Unable to Find Correct Codec -> Premature End #110

Open garageavow opened 2 years ago

garageavow commented 2 years ago

Hi, I seem to have essentially the same issue as Gavia did a few days ago: https://github.com/anthwlock/untrunc/issues/108

I was recording with my GoPro in cold weather when my GoPro decided to glitch and shut off during recording, corrupting my SD card. The GoPro said that my only option was to reformat the card and my computer did not mount/read the card when I inserted it. I installed Untrunc using the docker method and so far I have achieved the following:

I used PhotoRec to recover 73 .mp4 files from the card. These are not all from the same recording session and none of them play in any media player including VLC but I know that there is data there because the size of the files makes sense. I also looked at some of them using a hex editor where they look very similar to good files except that there are a bunch of 00s at the end of the files.

When I use Untrunc without any options I get something like this:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55dd47be33a0] Using non-standard frame rate 59/1 Info: version '' using ffmpeg '3.4.8-0ubuntu0.2' Info: reading /mnt/ok.mp4 Info: parsing healthy moov atom ... Info: special track found (tmcd, 'GoPro TCD') Info: special track found (meta, 'GoPro MET') Info: special track found (meta, 'GoPro SOS')

Info: reading mdat from truncated file ... Info: Muted ffmpeg to reduce redundant warnings/errors. Use '-do' to see them. Error: unable to find correct codec -> premature end (~0.1447%) try '-s' to skip unknown sequences

Info: Found 205 packets ( gpmd: 0 fdsc: 103 mp4a: 44 avc1: 57 avc1-keyframes: 1 tmcd: 1 ) Info: Duration of gpmd: (0 ms) Info: Duration of mp4a: 938ms (938 ms) Info: Duration of avc1: 950ms (950 ms) Info: pruned empty 'gpmd' track Info: saving /mnt/broken.mp4_fixed.mp4

This results in a file which appears to be fixed but only plays for one or two seconds.

I then tried with the -s option which resulted in this:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55e042d2b3a0] Using non-standard frame rate 59/1 WARNING: Because of internal decoder changes, using ffmpeg '3.4.8-0ubuntu0.2' with '-s' can be slow! You are advised to compile untrunc against ffmpeg 3.3! See the README.md on how to do that. Info: version '' using ffmpeg '3.4.8-0ubuntu0.2' Info: reading /mnt/ok.mp4 Info: parsing healthy moov atom ... Info: special track found (tmcd, 'GoPro TCD') Info: special track found (meta, 'GoPro MET') Info: special track found (meta, 'GoPro SOS')

Info: reading mdat from truncated file ... Info: Muted ffmpeg to reduce redundant warnings/errors. Use '-do' to see them. Warning: Codec::wasbad = 1 Warning: NOT skipping moov atom: 1252562 (at 4004233387 / 4004233415) Warning: Skipping mvhd atom: 108 Warning: Skipping udta atom: 26421 Warning: Skipping iods atom: 24 Warning: NOT skipping trak atom: 342801 (at 4004259948 / 4004259976) Warning: Skipping tkhd atom: 92 Warning: Skipping tref atom: 20 Warning: Skipping edts atom: 36 Warning: NOT skipping mdia atom: 342645 (at 4004260104 / 4004260132) Warning: Skipping mdhd atom: 32 Warning: Skipping hdlr atom: 44 Warning: NOT skipping minf atom: 342561 (at 4004260188 / 4004260216) Warning: Skipping vmhd atom: 20 Warning: Skipping dinf atom: 36 Warning: NOT skipping stbl atom: 342497 (at 4004260252 / 4004260280) Warning: Skipping stsd atom: 197 Warning: Skipping stts atom: 24 Warning: Skipping stsc atom: 28 Warning: NOT skipping stsz atom: 169700 (at 4004260509 / 4004260537) Info: Found 264719 packets ( gpmd: 1395 fdsc: 132289 mp4a: 57487 avc1: 73547 avc1-keyframes: 4122 tmcd: 1 ) Info: Duration of gpmd: 23min 16s 395ms (1396395 ms) Info: Duration of mp4a: 20min 26s 389ms (1226389 ms) Info: Duration of avc1: 20min 27s 9ms (1227009 ms) Warning: Unknown sequences: 1320 Warning: Bytes NOT matched: 39.2MiB (1.025%) Info: saving /mnt/broken.mp4_fixed-s1.mp4

21 warnings were hidden!

This results in a really glitchy .mp4 which seems to lag every few seconds where the sound repeats itself, the video glitches and a lot of pixels turn green and other colors.

I'm not that good with Linux and I don't really understand what the program is doing but here are my thoughts:

  1. The SD card corrupted all of my videos not only the video that was in progress so maybe the SD card just got so corrupted that the files are simply not recoverable because they have a load of random data or a pattern of random data injected into them.

  2. I don't have a good file from the same recording session but I do have different files from the same camera. I think that the frame rate and resolution are the same but if I try different 'good' files the output of untrunc is slightly different and the % of bytes unmatched changes slightly so maybe the problem has something to do with the quality of the good file I am using or some automatic camera settings.

  3. It says that it is using ffmpeg 3.4.8, maybe the problem is as simple as it needs to use 3.3.9 but I am not sure how to do this. I installed it with this argument so I am not really sure why it is using 3.4.8, and I don't know how to force it to use a different version:

docker build --build-arg FF_VER=3.3.9 -t untrunc .

I have also tried Untrunc on Windows and get the exact same results so I don't actually think it is very likely that the problem is with ffmpeg, but if it is not a problem with ffmpeg I don't know what the codec error means. Could it be something simple like the fact that my videos are shot in 60fps and the program doesn't handle this framerate properly?

I have accepted the fact that I will probably not be able to recover these videos but any help would be appreciated anyways, and I am also happy to share files if you are interested. Thanks!

anthwlock commented 2 years ago

Feel free to send me some samples. Maybe I will be able to refine the relevant matching patterns a bit, which could improve your results a bit.

The SD card corrupted all of my videos not only the video that was in progress

It could also be that the "random data injected into them" are just caused be the file fragmentation which is normal for filesystems after a certain amount of use. It probably is rare that a big file gets stored in one sequence. This comment on #108 also describes this theory a bit. PhotoRec doesn't take this into account, as it operates on the raw block level, not on logical file level. What filesystem does your SD use?

but if I try different 'good' files the output of untrunc is slightly different

Yes, it is oftentimes a good idea to try a few different healthy samples. But in this case I don't think that it would produce "perfect" recovered files, even if you give it "perfect" reference file.

It says that it is using ffmpeg 3.4.8, maybe the problem is as simple as it needs to use 3.3.9 [..] I have also tried Untrunc on Windows and get the exact same results

Since the automated windows build uses a version < 3.4, and you get the same results there, I don't think this will make much of a difference.

and I don't know how to force it to use a different version

What is the problem? Does it still use another ffmpeg version even after you passed FF_VER=3.3.9? Maybe you have to delete the previous container/image (docker rmi untrunc)?

I don't know what the codec error means

It just means that untrunc was not able to guess the codec. Either because untrunc has incorrect / incomplete matching-logic, or because there is "junk data".

garageavow commented 2 years ago

Thanks for the answers I appreciate it. Yes it seems to be using a newer version of FFMPEG even though I pass FF_VER=3.3.9 but like you say I have tried it on Windows and the results were identical. I also have now confirmed that I used a reference file with the correct framerate.

It sounds like the files are all just too fragmented but I will try to send you a broken file and a good file if you'd like to take a look at it.

clort81 commented 1 year ago

Try manually truncating a healthy file and see if untrunc handles that. If it does, the problem stems from the files corrupted during your photorec recovery.