FFMS / ffms2

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

Audio desync with certain MP4s #216

Closed Xenoveritas closed 9 years ago

Xenoveritas commented 9 years ago

When using ShadowPlay, the files it creates frequently have audio that desyncs from the video when run through AviSynth.

I finally have a sample file that's not several GBs, although it's a trimmed bit that's gone through Avidemux which screwed with the timing a bit. (Meaning that while there's still desync, it may be different from the ShadowPlay desync I'm used to seeing.)

Sample MP4 with audio desync

The audio should be in sync in most players. (Although it wasn't in Firefox when I tested the link.)

The test AVS script would look something like this:

file = "Test.mp4"
FFIndex(file)

v = FFVideoSource(file, fpsnum=60)
a = FFAudioSource(file)

AudioDub(v, a)

This has a noticeable desync where the fanfare plays early when running into the warrior woman at around 25 seconds. I can "fix" this by passing the audio through the FFMpeg aresample filter:

ffmpeg -i Test.mp4 -codec:a flac -vn -filter:a aresample=async=1000 Test.flac

Changing the FFAudioSource to point to this file generates audio that remains in sync with the video and plays the fanfare when expected.

myrsloik commented 9 years ago

Which version? does it work in 2.20?

Xenoveritas commented 9 years ago

As far as I know it's never worked. The specific example MP4 I tried against 2.21 ICL but I've seen similar behavior with 2.20 (also ICL) and "whatever version MeGUI bundles." (Which is apparently 2.20, who knows what compiler was used.)

tgoyne commented 9 years ago

The problem here is that there's sometimes a few samples missing between audio packets, and currently ffms2 always assumes that when there's a disagreement between the PTSes and the actual audio data, the PTSes are the one that's wrong (garbage timestamps for audio streams is bizarrely common). I think it'll be pretty straightforward to support gaps between packets without breaking anything else, though.