anthwlock / untrunc

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

Stuttery video (guessed frame durations of 'avc1' will probably be wrong!) #56

Closed sentience closed 3 years ago

sentience commented 4 years ago

Running master via Docker on macOS.

Info: version '56aee28-dirty' using ffmpeg '3.4.6-0ubuntu0.18.04.1' Info: reading /mnt/ok.mp4 Info: parsing healthy moov atom ... Composition time offset atom found. Out of order samples possible.

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 (~100%) try '-s' to skip unknown sequences

Warning: guessed frame durations of 'avc1' will probably be wrong! Info: Found 142090 packets ( mp4a: 86640 avc1: 55450 avc1-keyframes: 617 ) Info: Duration of mp4a: 30min 48s 320ms (1848320 ms) Info: Duration of avc1: 30min 48s 374ms (1848374 ms) Info: saving /mnt/broken.mp4_fixed.mp4

2 warnings were hidden!

The broken.mp4_fixed.mp4 file plays, but stutters throughout in QuickTime Player. VLC plays it more smoothly, but with occasional pauses in the video and the audio is a little out-of-sync.

I'm guessing the “Warning: guessed frame durations of 'avc1' will probably be wrong!” is at the heart of the issue, here.

sentience commented 4 years ago

Tried -a to analyze the file:

Info: version '56aee28-dirty' using ffmpeg '3.4.6-0ubuntu0.18.04.1' Info: reading /mnt/ok.mp4 Info: parsing healthy moov atom ... Composition time offset atom found. Out of order samples possible.

Track 0 codec: mp4a

(0) Size: 684 offset: 241621 / 241669 begin: 211a9495 baa8c640 end: ed3bbbf0211a94cd Info: Muted ffmpeg to reduce redundant warnings/errors. Use '-do' to see them. detected size: 684 true: 684 detected duration: 1024 true: 684 <- WRONG

(1) Size: 668 offset: 242305 / 242353 begin: 211a94cd ba8b61a3 end: 200dcc4e00000002 detected size: 668 true: 668 detected duration: 1024 true: 668 <- WRONG

(701) Size: 733 offset: 4304242 / 4304290 begin: 211a8fff 37700001 end: a77777e000000002 detected size: 733 true: 733 detected duration: 1024 true: 733 <- WRONG

(702) Size: 614 offset: 4305038 / 4305086 begin: 211a8ff9 fff80001 end: 7c80e1c000005b9d detected size: 614 true: 614 detected duration: 1024 true: 614

Track 1 codec: avc1

(0) Size: 241621 offset: 0 / 48 begin: 00000002 09100000 end: 0000049d211a9495 detected size: 241621 true: 241621 detected keyframe: 1 true: 1

(1) Size: 6132 offset: 242973 / 243021 begin: 00000002 09300000 end: 32966ba0211a94dd detected size: 6132 true: 6132

(448) Size: 58 offset: 4303355 / 4303403 begin: 00000002 09500000 end: 000011f1211a8fbf detected size: 58 true: 58

(449) Size: 63 offset: 4304975 / 4305023 begin: 00000002 09300000 end: 030065c0211a8ff9 detected size: 63 true: 63

sentience commented 4 years ago

Uploaded the files in case you need to take a look: https://we.tl/t-wQj90Je7uN

anthwlock commented 4 years ago

Here I explained the meaning/reason of guessed frame durations [..] will probably be wrong!.

One idea I had was to measure the playback length of each frame. Don't expect a fix in the near future.

Btw, have you also used ffmpeg to save the stream? If not, what have you used instead?

sentience commented 4 years ago

Yes, I used ffmpeg to save the stream. I truncated the file by accident by hitting Ctrl-C twice, at which point ffmpeg exited immediately.

anthwlock commented 4 years ago

Interesting. I guess it would be worth digging into ffmpeg's source, to find out what's the cause for these non-constant durations, and to reason about if recovery is possible. Specifically, its hls protocol demuxer implementation.

Btw, in case you haven't seen it, there is a simple trick to avoid corrupt files while streaming with ffmpeg.

cbenhagen commented 4 years ago

@anthwlock Could be the same issue or completely unrelated. I also get a stuttery result in QuickTime Player but am missing the "..guessed frame durations.." warning. Playing back in ffplay and VLC works normally. Any ideas? Do you want me to open a new issue as the warning is not present in my case?

Here is a sample: https://we.tl/t-hsqhlZeGYs

anthwlock commented 4 years ago

@cbenhagen yes, open another issue. Please include a working reference file, a longer video (>10s), and a detailed description on what you mean by "stuttery result". Try if using ffmpeg -c copy helps. I assume the working file plays fine with QuickTime Player?

cbenhagen commented 4 years ago

Will do. Yes the working file plays well. ffmpeg -c copy does not help. Unfortunately I can't provide a bigger sample as it is not my footage. By stuttery, I mean it looks like a key frame keeps being repeated. Hard to explain. Do you have access to a macOS machine? Maybe I can provide a screen recording.

anthwlock commented 3 years ago

This issues consisted of two issues:

To avoid confusion, I think it is better close this issue, since the "stuttery video" part has been dealt with.