FFMS / ffms2

An FFmpeg based source library and Avisynth/VapourSynth plugin for easy frame accurate access
Other
576 stars 104 forks source link

Writing index to disc occasionally inflated NumSamples #339

Closed CoffeeFlux closed 2 years ago

CoffeeFlux commented 5 years ago

Originally reported in Aegisub.

For some reason, when you open certain files, of which I have two examples, the process of saving the index to disc and then reloading it causes additional samples to be added to the audio track. The factor by which it's stretched is inconsistent across the two files, and for one of the files remuxing fixes the issue and on the other it does not. SampleRate, FirstTime, and LastTime appear to all be consistent with the original index, but NumSamples is not.

This doesn't occur with 2.23.1-3 but does with git master, in both cases using FFmpeg 4.1.

I used this script to test: https://gist.github.com/CoffeeFlux/d1702c0df6cc39b04f94f2bf25a8bd7a

If you swap out index2 for index on lines 42 and 47, which makes the script use the original index in memory, you'll see the issue goes away.

The files are reasonably large and I'd rather not link them here, but I can provide them on IRC upon request. I haven't been able to identify what about them causes this, so I can't produce a minimal example file.

dwbuiten commented 5 years ago

After having looked at this, I see a number of places that cause the inconsistency, however, it's not clear which of the two values I should keep as 'correct', since one of them is a the sum of samples coded in the AAC frames (1024 per frame), and the other is based on the PTS (via gap filling code), and is different due to wonky oscillating timestamps in the matroska file (probably because of its fixed time base).

I'll think a bit on this... but it all screams "yay infintie edge cases" to me. Some formats like FLV, require you to silence-fil gaps, while others like WMV expect you to massage the timestamps instead... Not keen on adding a giant block of that sort of thing... :/

myrsloik commented 2 years ago

The index files are no longer written with the audio gap filling/padding applied, instead it can be optionally applied when decoding