mpv icon indicating copy to clipboard operation
mpv copied to clipboard

A/V desync when switching audio tracks

Open mathstuf opened this issue 13 years ago • 15 comments

I'm seeing an A/V desync when switching audio tracks. Is there a way to avoid this (maybe seeking in the audio track when a switch happens)?

mathstuf avatar Oct 16 '13 02:10 mathstuf

The desync should be rather minimal, and should recover rather quickly (somewhat depends on audio out buffers).

We could do a seek on track switching to restore it perfectly, but I'd rather avoid triggering a seek, but I'd rather like to avoid implicitly initiating seeks on such an operation.

ghost avatar Oct 16 '13 17:10 ghost

I was seeing half second delays (well, A-V was .610 or so). Manually seeking back then forward fixed it.

mathstuf avatar Oct 16 '13 17:10 mathstuf

Problem is that it would depend on the computer and video you're playing.

LabMem765 avatar Oct 16 '13 23:10 LabMem765

Well, I'm not sure what to do. Personally, I would prefer to leave it as is, because it's actually somewhat more robust, and also faster.

ghost avatar Oct 19 '13 21:10 ghost

So, while I do not want a seek, we could still handle synchronization somehow. If audio comes too early, we could cut it. If audio comes too late, we could insert silence. Especially the silence thing might be annoying for users, though. What do you think?

ghost avatar Oct 26 '13 11:10 ghost

It might be fine. It being slightly off might hit something akin to the uncanny valley. I wonder if switching A/V tracks could pause playback, switch the stream, then restore the pause state. I'll test if the desync happens currently when paused when I'm in front of a real keyboard again.

mathstuf avatar Oct 26 '13 14:10 mathstuf

Nope, pausing doesn't prevent the desync.

mathstuf avatar Oct 26 '13 15:10 mathstuf

Sounds like a trival job for a lua script. Is this still a problem?

kevmitch avatar Apr 29 '14 17:04 kevmitch

Yes, if the audio buffers are large enough. I don't see how to fix this with a Lua script.

ghost avatar Apr 29 '14 22:04 ghost

well, not properly, but just rebind the audio track switching to seek back and forth afterwards.

kevmitch avatar Apr 30 '14 06:04 kevmitch

never mind, a much simpler solution for mathstuf would be to put in his input.conf

 SHARP cycle aid; seek 5; seek -5

Not sure if that would actually do the seek though or do it in the same way that solves the problem manually. It wouldn't somehow detect and nullify the noop would it? Anyway, I'm not seeing any problem with alsa, wasapi, or wasapi=exclusive on a 02:42:00 flim. Is this a pulse thing?

kevmitch avatar Apr 30 '14 10:04 kevmitch

Fixed.

ghost avatar Feb 14 '15 19:02 ghost

Fixed how? @kevmitch's suggestion? Also, yes I use pulse.

mathstuf avatar Feb 15 '15 03:02 mathstuf

If an audio track is enabled, the code for initial audio sync is run, which means no desync can happen (unless such a desync also happens on normal playback start, which means the audio output is behaving strangely/buggy). mpv has been doing this for a while, not sure when.

Also, a recent change makes audio stream switching relatively instant because it gets audio packets earlier.

ghost avatar Feb 15 '15 12:02 ghost

Also, a recent change makes audio stream switching relatively instant because it gets audio packets earlier.

That was f9f2e1cc4e80a66793249651b74d83c1c8f3a8d4. Isn't done for most file formats.

ghost avatar Feb 15 '15 12:02 ghost