untrunc icon indicating copy to clipboard operation
untrunc copied to clipboard

Failed to recover MP4 with audio stream

Open bczhc opened this issue 3 years ago • 2 comments

Hello! I just tried to restore my screen recording video but failed, not knowing the reason. I then tried so much and I've found that in my case it seems videos with audio have trouble being recovered, it fails even if broken.mp4 is directly truncated from ok.mp4, here's the details:

My screenrecords are done with:

parec --device=bluez-xxx.monitor | ffmpeg -f x11grab -framerate 30 -i "$DISPLAY" \
        -ar 44100 -ac 2 -f s16le -i pipe:0 \
        -c:v h264_nvenc \
        -profile:v high \
        -pix_fmt yuv420p \
        -b:v 0 \
        "$output_file"

It will record the display along with audio from parec stream. I just recorded a 20M sample video: here, let it be original.mp4. Then I made a broken video using: dd if=original.mp4 of=truncated.mp4 bs=1M count=10, and try to restore it:

untrunc original.mp4 truncated.mp4

Then I got these errors:

Reading: original.mp4
Repair: truncated.mp4
Mdat not found!
Processed: 4%
Backtracked enough!


Trying a different approach to locate mdat start
Repair: truncated.mp4
Processed: 4%
Processed: 51%
Backtracked enough!


Trying a different approach to locate mdat start
Repair: truncated.mp4
Mdat not found!
Processed: 43%
Backtracked enough!


Trying a different approach to locate mdat start
Repair: truncated.mp4
Mdat not found!
Processed: 4%
Processed: 51%
Backtracked enough!
Failed recovering the file
Saving to: truncated_fixed.mp4

Now with the mute video, untrunc can repair it:

ffmpeg -i original.mp4 -an -c:v copy original-an.mp4
dd if=original-an.mp4 of=truncated-an.mp4 bs=1M count=10
untrunc original-an.mp4 truncated-an.mp4

And I also tried another version of untrunc anthwlock/untrunc, but this can just repair my video.

Thanks

bczhc avatar May 29 '22 08:05 bczhc

Hi, it's a little weird: I tried the original -> truncated commands and the 99% of the video was recovered.

This might have something to do with the libav version (because I can't think of anything else). Which one are you using?

ponchio avatar May 31 '22 16:05 ponchio

Hi the libav submodule in this repo is pinned at the libav latest commit c464278, and I'm using this libav version.

But now I might have found the problem: I tried untrunc versions before submodule was added, using libav-v12.3 from https://libav.org/releases/libav-12.3.tar.xz but not the libav submodule, and it works. So it's really related to libav version, and the solution so far is to change libav submodule version from the latest c46427 to tag-v12.3 ...

bczhc avatar Jun 01 '22 03:06 bczhc

I agree, I just downloaded that libav-12.3, compiled it and dropped/replaced it into the untrunc source folder. Now I recovered a 3.8 GiB file with 59min with slight audio async (even with -d) that I don't mind right now. With included libav i got only a 1.4MiB/10sec file (using the absolute same parameters and sample file)

Hi the libav submodule in this repo is pinned at the libav latest commit c464278, and I'm using this libav version.

But now I might have found the problem: I tried untrunc versions before submodule was added, using libav-v12.3 from https://libav.org/releases/libav-12.3.tar.xz but not the libav submodule, and it works. So it's really related to libav version, and the solution so far is to change libav submodule version from the latest c46427 to tag-v12.3 ...

SpiritInAShell avatar Dec 09 '22 23:12 SpiritInAShell

Hey @ponchio, could you fix the submodule? Had the same problem as above and the workaround works.

melyux avatar Mar 12 '23 22:03 melyux

Thanks for spotting the submodule problem. I updated the submodule to version 12.3.

ponchio avatar Mar 12 '23 23:03 ponchio