A/V sync with custom audio output

This forum is about all development around libVLC.
shavlo
New Cone
New Cone
Posts: 6
Joined: 24 Feb 2021 10:23

A/V sync with custom audio output

Postby shavlo » 24 Feb 2021 10:54

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.

Rémi Denis-Courmont
Developer
Developer
Posts: 15229
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: A/V sync with custom audio output

Postby Rémi Denis-Courmont » 24 Feb 2021 17:32

pts is the presentation timestamp of the (start of the) audio block.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

shavlo
New Cone
New Cone
Posts: 6
Joined: 24 Feb 2021 10:23

Re: A/V sync with custom audio output

Postby shavlo » 26 Feb 2021 17:09

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.

a4tech
Blank Cone
Blank Cone
Posts: 25
Joined: 14 Aug 2020 16:55

Re: A/V sync with custom audio output

Postby a4tech » 31 Mar 2021 00:26

@shavlo

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

monaghanwashere
New Cone
New Cone
Posts: 1
Joined: 15 Jun 2021 22:32

Re: A/V sync with custom audio output

Postby monaghanwashere » 15 Jun 2021 22:35

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...

Rémi Denis-Courmont
Developer
Developer
Posts: 15229
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: A/V sync with custom audio output

Postby Rémi Denis-Courmont » 16 Jun 2021 16:49

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

shavlo
New Cone
New Cone
Posts: 6
Joined: 24 Feb 2021 10:23

Re: A/V sync with custom audio output

Postby shavlo » 08 Dec 2022 20:23

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.

shavlo
New Cone
New Cone
Posts: 6
Joined: 24 Feb 2021 10:23

Re: A/V sync with custom audio output

Postby shavlo » 08 Dec 2022 20:25

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 15 guests