anthwlock / untrunc

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

untrunc trouble with HVEC where moov refers to nonexistent frames? #68

Open slingyropert opened 4 years ago

slingyropert commented 4 years ago

I have a broken HVEC .MOV from a Fuji X-T3 camera that I think it should be possible to repair because virtualdub2 is able to parse the bad file and decode the frames before the truncation to zeros.

I have tried untrunc "-s", "-s -sm", "-sm" and "-sm -dyn" with the same result. The repair output from untrunc 644978f is not playable in virtualdub2 or vlc. The repair seems to have one key frame worth of hvc1 when I expect a few hundred frames. If I run untrunc -d on the repair file:

Info: version '644978f' using ffmpeg '3.3.4' Info: reading bad.MOV_fixed-s1.MOV Info: parsing healthy moov atom ...

Track 0 codec: hvc1

(0) Size: 5188875 offset: 178094080 / 183388904 begin: 004f2d07 28010081 end: 39e08d122f54ab1f detected size: 5188875 true: 5188875 detected keyframe: 1 true: 1 Track 1 codec: lpcm

Not an expert at this but I think the camera writes a moov with 20 minutes worth of hvc1 files at the beginning of file recording. Consequently, if the recording stops, the moov in bad.MOV refers to a bunch of hvc1 frames that do not exist and where the binary data in mdata is all zero.

It seems like untrunc is not picking up on which hvc1 frames are real and which are not real when it comes to output the repair. It seems like it should because if I do "untrunc -f

Maybe there is a way to search the mdat to figure out which are real? I'm not a C++ person but maybe I can help eventually.

Bad file truncated to first 240 MB (zeros are not visible since they occur at about 1.5 GB in) : https://drive.google.com/file/d/1uBpsJjvDZqXkHdLPGXOn3hV2RmQpTsXo/view?usp=sharing

Good file (131 MB): https://drive.google.com/file/d/1iQlIMcV18-5QdsanXZVm1v8DQxJ3Gryc/view?usp=sharing

Thanks,

anthwlock commented 4 years ago

It seems like untrunc is not picking up on which hvc1 frames are real and which are not

More like it didn't find the start of these hvc1 frames at all. And that was mainly because of the bad tmcd and lpmc prediction.The recent commits should improve on this, please give them a try.

Maybe there is a way to search the mdat to figure out which are real?

If you can figure this out with a hexeditor, you can tell untrunc where to start the recovery via -range <start_of_good_mdat_data>:.

Besides this: untrunc tries to combine all mdat atoms it finds. It does this by simply skipping the mdat header, see here