ponchio / untrunc

Restore a damaged (truncated) mp4, m4v, mov, 3gp video. Provided you have a similar not broken video.
GNU General Public License v2.0
1.64k stars 230 forks source link

Two audio streams are being combined into one #270

Closed TCDHughes closed 1 year ago

TCDHughes commented 1 year ago

Hi Ponchio,

Through your software (and other forks), I have been able to recover the video stream from a Shadowplay (H.264) MP4 that is otherwise unreadable -- thank you very much!

Unfortunately, when I try to recover the audio portion, I either get fragments of audio, or the two AAC audio streams AAC are merged, interleaving approximately every second or so. This seems a bit like issue #241, but unlike those users, Wondershare Recoverit cannot fix my file.

I tried breaking the file down into 1 second pieces and stitching each alternate piece together to recover the two streams, but fragments of the other audio channel would still get through, suggesting that the alternation time is not one second. I then tried to look at the waveform, but it's very difficult to see where one stream properly ends and another starts, much of the time.

I have the video and known good clip on Google drive (https://drive.google.com/drive/folders/1A0oywyMasSBCpZTeSZW8Kk9TKFbPN5lT?usp=drive_link). If you'd be willing to take a look, I'd appreciate it :)

Again, thanks for releasing the project to the public, it is much better than that repair_mp4 tool that's floating around.

Cheers.

ponchio commented 1 year ago

Ciao, the two audio seems to have the same AAC parameters, so I think the best bet is to use the ordering of the samples (which, in the good.mp4 movie, seems to be consistent. I will probably just make a custom version for you, hopefully it will be simple enough.

It will just take a while for me to download the 48GB file...

Federico

On Sun, Sep 10, 2023 at 5:48 AM TCDHughes @.***> wrote:

Hi Ponchio,

Through your software (and other forks), I have been able to recover the video stream from a Shadowplay (H.264) MP4 that is otherwise unreadable -- thank you very much!

Unfortunately, when I try to recover the audio portion, I either get fragments of audio, or the two AAC audio streams AAC are merged, interleaving approximately every second or so. This seems a bit like issue

241 https://github.com/ponchio/untrunc/issues/241, but unlike those

users, Wondershare Recoverit cannot fix my file.

I tried breaking the file down into 1 second pieces and stitching each alternate piece together to recover the two streams, but fragments of the other audio channel would still get through, suggesting that the alternation time is not one second. I then tried to look at the waveform, but it's very difficult to see where one stream properly ends and another starts, much of the time.

I have the video and known good clip on Google drive ( https://drive.google.com/drive/folders/1A0oywyMasSBCpZTeSZW8Kk9TKFbPN5lT?usp=drive_link). If you'd be willing to take a look, I'd appreciate it :)

Again, thanks for releasing the project to the public, it is much better than that repair_mp4 tool that's floating around.

Cheers.

— Reply to this email directly, view it on GitHub https://github.com/ponchio/untrunc/issues/270, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUDV26MO62WWXESGUBNCPDXZU2ADANCNFSM6AAAAAA4R4F3MQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ponchio commented 1 year ago

Ciao, i found a reliable way to recover the audio using the fact that the 2 tracks follow the same pattern and I can just split in half the packets and reassign them. The code is:

int start = -1;

for(int i = 0; i < matches.size(); i++) {

    MatchGroup &g = matches[i];

    Match &m = g.back();

    if(m.id != 0 && start == -1)

        start = i;

    if(m.id == 0) {

        if(start != -1) {

            int tot_audio = i - start;

            for(int k = start; k < start + tot_audio/2; k++) {

                assert(matches[k].back().id != 0);

                matches[k].back().id = 1;

            }

            for(int k = start + tot_audio/2; k < start + tot_audio; k++) {

                assert(matches[k].back().id != 0);

                matches[k].back().id = 2;

            }

        }

        start = -1;

    }

}

Around line 1318 of mp4.cpp (before copy matches into track)).

I teste it on recovering good.mp4 using good.mp4 and it seems to work.

I have problems recovering the large file. I don't know if I corrupted the file while downloading. If you could send me just the beginning (a few GB at most) I could unravel the mystery.

Ciao,

Federico

On Tue, Sep 12, 2023 at 2:16 AM Federico Ponchio @.***> wrote:

Ciao, the two audio seems to have the same AAC parameters, so I think the best bet is to use the ordering of the samples (which, in the good.mp4 movie, seems to be consistent. I will probably just make a custom version for you, hopefully it will be simple enough.

It will just take a while for me to download the 48GB file...

Federico

On Sun, Sep 10, 2023 at 5:48 AM TCDHughes @.***> wrote:

Hi Ponchio,

Through your software (and other forks), I have been able to recover the video stream from a Shadowplay (H.264) MP4 that is otherwise unreadable -- thank you very much!

Unfortunately, when I try to recover the audio portion, I either get fragments of audio, or the two AAC audio streams AAC are merged, interleaving approximately every second or so. This seems a bit like issue

241 https://github.com/ponchio/untrunc/issues/241, but unlike those

users, Wondershare Recoverit cannot fix my file.

I tried breaking the file down into 1 second pieces and stitching each alternate piece together to recover the two streams, but fragments of the other audio channel would still get through, suggesting that the alternation time is not one second. I then tried to look at the waveform, but it's very difficult to see where one stream properly ends and another starts, much of the time.

I have the video and known good clip on Google drive ( https://drive.google.com/drive/folders/1A0oywyMasSBCpZTeSZW8Kk9TKFbPN5lT?usp=drive_link). If you'd be willing to take a look, I'd appreciate it :)

Again, thanks for releasing the project to the public, it is much better than that repair_mp4 tool that's floating around.

Cheers.

— Reply to this email directly, view it on GitHub https://github.com/ponchio/untrunc/issues/270, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUDV26MO62WWXESGUBNCPDXZU2ADANCNFSM6AAAAAA4R4F3MQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

TCDHughes commented 1 year ago

Hi Federico,

I'm thrilled to hear that fixing this file fully may be possible.

I'd love to give you a trimmed version of the MP4, but I'm not sure how to do so. I've tried using ffmpeg but it rejects the request due to a lack of moov atom. I can't open the file in any video or audio editor either, so am not able to trim it that way. If you have a different method in mind, I'm happy to try it.

Otherwise, I think there are a few things we can try.

First, you suggested that the file might have downloaded wrong. Can we test that with a checksum? I'm tech literate but this is not my background, so I may be ignorant about what checksums actually do. The MD5 hash is: 1550bb4d4ab2f423715ddd522e9abf6d

Second, I have uploaded the interleaved audio file to the same google drive as the footage. Perhaps you would have better luck splitting out the audio packets from this file? It's an MP3 so I suspect it won't work, but I don't know how MP3 works in comparison to AAC. I may be able to get an AAC version, but I will have to check this.

Third, if neither of these options work, I am happy to try running what you've got so far on my PC, perhaps mine will have better luck.

Finally, if nothing works I can try to make a new, shorter corrupt file to work with. I'm not sure how the first file got corrupted, but I'm sure I can replicate it with a bit of work.

Thanks again for all the effort! I'm very excited to get this all fixed up :)

ponchio commented 1 year ago

Good news everyone!

       after confirming the md5, by trial and error manage to find a

starting point: untrunc -b 7285159 good.mp4 bad.mp4

The audio and video seems ok, the only problem is that the recovered file is only 36GB even though it processed 100% of the original file , I need to understand the reason.

You can find everything here: (bad_fixed.mp4 is the recovered file) It will take forever to download from my crappy countryside connection, I made a sample.mp4 10 sec long. You might want to consider waiting until Monday when I will copy this to my university machine.

http://78.134.70.236/TCDHughes/

Ciao,

Federico

On Sat, Sep 16, 2023 at 9:58 AM TCDHughes @.***> wrote:

Hi Federico,

I'm thrilled to hear that fixing this file fully may be possible.

I'd love to give you a trimmed version of the MP4, but I'm not sure how to do so. I've tried using ffmpeg but it rejects the request due to a lack of moov atom. I can't open the file in any video or audio editor either, so am not able to trim it that way. If you have a different method in mind, I'm happy to try it.

Otherwise, I think there are a few things we can try.

First, you suggested that the file might have downloaded wrong. Can we test that with a checksum? I'm tech literate but this is not my background, so I may be ignorant about what checksums actually do. The MD5 hash is: 1550bb4d4ab2f423715ddd522e9abf6d

Second, I have uploaded the interleaved audio file to the same google drive as the footage. Perhaps you would have better luck splitting out the audio packets from this file? It's an MP3 so I suspect it won't work, but I don't know how MP3 works in comparison to AAC.

Third, if neither of these options work, I am happy to try running what you've got so far on my PC, perhaps mine will have better luck.

Finally, if nothing works I can try to make a new, shorter corrupt file to work with. I'm not sure how the first file got corrupted, but I'm sure I can replicate it with a bit of work.

Thanks again for all the effort! I'm very excited to get this all fixed up :)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

TCDHughes commented 1 year ago

Hey Federico,

I took a look at the sample in my video editor and it looks amazing! Please let me know when would be a good time to download :)

Thanks for the amazing work! I'll send a tip your way -- you've definitely earned a few cold beers on me :)

Cheers, -Tom Hughes

ponchio commented 1 year ago

Ciao, you can find the video here:

http://pc-ponchio.isti.cnr.it/bad_fixed.mp4

(right click Save As.. in case it just shows the video) This should be way faster. Let me know if something is not ok in the video. I had no time to properly look all of it.

Thanks, that's a lot of beer :)

Federico

On Sat, Sep 16, 2023 at 12:30 PM TCDHughes @.***> wrote:

Hey Federico,

I took a look at the sample in my video editor and it looks amazing! Please let me know when would be a good time to download :)

Thanks for the amazing work! I'll send a tip your way -- you've definitely earned a few cold beers on me :)

Cheers, -Tom Hughes

— Reply to this email directly, view it on GitHub https://github.com/ponchio/untrunc/issues/270#issuecomment-1722198956, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUDV24LI3PHJGRPGHEMOJLX2V5SXANCNFSM6AAAAAA4R4F3MQ . You are receiving this because you commented.Message ID: @.***>

gonzalez-agirre commented 11 months ago

Hi Federico,

I have a file with the same problem but with 4 audio streams. Can you provide me with instructions to fix the audio? It's quite important recording that I would like to recover.

Best.

ponchio commented 11 months ago

Ciao, if the file can be recovered (without signal analysis) and how, it depends on the specific organization of the audio streams. If you can send me a couple of samples (same camera/recording device parameters), I can have a look and hopefully add this functionality at the code ( @.***).

Federico

On Fri, Dec 15, 2023 at 4:00 PM gonzalez-agirre @.***> wrote:

Hi Federico,

I have a file with the same problem but with 4 audio streams. Can you provide me with instructions to fix the audio? It's quite important recording that I would like to recover.

Best.

— Reply to this email directly, view it on GitHub https://github.com/ponchio/untrunc/issues/270#issuecomment-1858019126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUDV2ZT7P26L3ICCV6D73LYJRQYXAVCNFSM6AAAAAA4R4F3MSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJYGAYTSMJSGY . You are receiving this because you commented.Message ID: @.***>

gonzalez-agirre commented 11 months ago

Hello Ponchio,

I'm sharing with you a Google Drive folder with 3 files:

It would be incredible to recover the audio as we put a lot of effort into organizing the event's streaming. If you need anything else, please let me know.

Thank you very much for your help.

ponchio commented 11 months ago

Wasn't hard, the audio packet are just interleaved.

If you can compile the code just uncomment #define QUADAUDIO at line 1364 of mp4.cpp, otherwise send me the large file and I will run the code for you (my line is a tad slow, might take a while to reupload).

gonzalez-agirre commented 11 months ago

Dear Federico,

You're a genious, it worked!

I hope to see my donation promply converted into beer.

Thank you so much!