anthwlock / untrunc

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

Multiple audio tracks broken #78

Closed platima closed 3 years ago

platima commented 3 years ago

Hey so I'll be honest I have no tested this with a WORKING file, and I would but I'm tired and running out of disk space, but what I am seeing here doesn't make a huge amount of sense and Iv'e done enough programming to think this is a bug.

Long story short, 2x OBS recordings with the same AV setup, being 1x 1080p video and 2x audio streams. Repairing one that ended prematurely (no moov atom) and I get this;

Info: version '8024f0c' using ffmpeg '3.3.4'
Info: reading .\KP 2020-09-04 20-33-41.mp4
Info: parsing healthy moov atom ...
Composition time offset atom found. Out of order samples possible.

Info: reading mdat from truncated file ...
Info: using 64-bit offsets for the broken file
[aac @ 00000000026a8cc0] Multiple frames in a packet.
Error: unable to find correct codec -> premature end (~100%)
       try '-s' to skip unknown sequences

Info: Found 1815790 packets ( mp4a: 1107188 mp4a: 0 avc1: 708602 avc1-keyframes: 2835 )
Info: Duration of mp4a: 7h 8min 28s 855ms  (25708855 ms)
Info: Duration of mp4a:  (0 ms)
Info: Duration of avc1: 3h 16min 50s 33ms  (11810033 ms)
Info: pruned empty 'mp4a' track
Info: saving .\2020-09-04 22-03-42.mp4_fixed.mp4
written length: 22521839630

The bits that interest me are that it picked up a 3h16m video, an empty audio track, then a 7h8m audio track. Playing it back, the audio was VERY slowed down, and I am fairly certain that I can hear both tracks in there, but they are interlaced in some way.

Using SuslikV/untrunc-w I managed to get both audio tracks, and am now just adding them back to the original video.

anthwlock commented 3 years ago

Interesting, I will try to investigate this once I have enough time. Would you mind sending me a small sample? You can generate a 200 MB file from a bigger file with with untrunc -sh big_file.mp4.

Do you get similar results when you use untrunc like this: untrunc good.mp4 good.mp4?

Meteoryte commented 3 years ago

I have been having this issue for a while now as well. Figured my container was just broken or something.

anthwlock commented 3 years ago

Should be fixed with b150ae5f701c85ad419c55de2617686ccda93d0a

untrunc-w seems to use a interleavingMask for this. That mask is similar to Mp4::track_order_. However for this purpose a (new) "simpler" version Mp4::track_order_simple_ suffices, which does take n_samples (per chunk) into account. I refactored the code a bit, so that it's possible to extract this new track order in case of duplicate tracks. Once extracted, the crucial change was this line.

platima commented 3 years ago

That's awesome, so if I run this again, I should get the multiple audio streams correctly now?

Edit: Yep this worked perfectly! Thanks a mil :)