Page 1 of 1

A/V sync with custom audio output

Posted: 24 Feb 2021 10:54
by shavlo
Hello,

I've recently started using libvlc and like it a lot - thanks for the devs for such a great work!

My question is: I use libvlc_audio_set_callbacks to organize custom audio output. But for some videos, there's a/v sync problem (audio comes about a second earlier). When played through VLC player, they play fine, and in the message log I see entries like

Code: Select all

main warning: playback way too early (-700451): playing silence
How can I detect such a situation from within my code?

I see there's "pts" parameter in libvlc_audio_play callback, but so far I've failed to understand how to use it. Comparing it to the value returned by "libvlc_clock" gives nothing as the difference is always about the same for videos with and without a/v sync problems.

Any help on the matter is appreciated.

Re: A/V sync with custom audio output

Posted: 24 Feb 2021 17:32
by Rémi Denis-Courmont
pts is the presentation timestamp of the (start of the) audio block.

Re: A/V sync with custom audio output

Posted: 26 Feb 2021 17:09
by shavlo
Thank you. Yes, I understand that. Does it mean I should use the pts value of the very first sample to calculate the a/v drift? I tried that and it appears to solve the problem for all videos. I want to verify that this solution is correct.

Re: A/V sync with custom audio output

Posted: 31 Mar 2021 00:26
by a4tech
@shavlo

Can You share Your patch for it ? I wish to test it as I face same issues.

Re: A/V sync with custom audio output

Posted: 15 Jun 2021 22:35
by monaghanwashere
Hi, is it possible to get any more info on this? I tried the same approach (using the very first delay value to set the A/V drift), however this doesn't work perfectly because the delay value is dynamic i.e. on every libvlc_audio_play callback, the delay value (calculated to the pts timestamp received in the callback) is slightly different...

Re: A/V sync with custom audio output

Posted: 16 Jun 2021 16:49
by Rémi Denis-Courmont
If your question is, can you handle long term drift with an initial playback delay/offset, then the answer is of course "no". I think you answered your own question.

Re: A/V sync with custom audio output

Posted: 08 Dec 2022 20:23
by shavlo
If your question is, can you handle long term drift with an initial playback delay/offset, then the answer is of course "no". I think you answered your own question.
What is the best solution to handle the drift? Is there a way to make libVLC video stream slower/faster? That is, I want audio stream to be the leading stream and sync video to it.

Re: A/V sync with custom audio output

Posted: 08 Dec 2022 20:25
by shavlo
Can You share Your patch for it ? I wish to test it as I face same issues.
It calculates the amount of audio drift and then either inserts appropriate amount of silence into the audio stream to delay it, or adjusts audio delay using libvlc_audio_set_delay if audio stream is ahead of video. But that doesn't work very good.