[Libav-user] DTS audio out of sync with video
kalileo at universalx.net
Wed Feb 8 00:33:53 CET 2012
On Feb 8, 2012, at 03:58 , Scott Brown wrote:
> Hey everyone,
> I'm using ffmpeg libraries to read from a UDP transport stream, and I've been working on handling short term signal loss if ffmpeg can no longer read from the UDP stream. Basically the call to av_read_frame() takes a long time (up to a minute or so) and then begins reading packets again.
> The trouble I have is with the PTS and DTS for the audio and video. Specifically, the audio and video are no longer in sync. The audio is about 2 seconds before the video. So if a video frame has the same PTS as a audio frame, during playback the video looks like it's behind the audio, even though the PTS is the same. Interestingly enough, this only happens after signal loss. If there is no signal loss, everything looks great.
> For a transport stream, is the PTS/DTS dependent on the packets before it? I've tried clearing out the AVFormatContext packet_buffer via calling the ff_frame_flush function, but this didn't help. Does anyone know why the audio and video get out of sync if packets are lost?
> Thanks for the help.
When you say "the audio and video are no longer in sync. The audio is about 2 seconds before the video." I assume you come to this conclusion when you play the stream. Does your player have any mechanism to synchronize based on DTS/PTS, or is it simply playing the audio/video frames as they come?
The streams I have worked with have always had a usable DTS/PTS, If there were frames missing/arriving corrupted then the DTS/PTS would show a "jump" and the player could sync back based on DTS/PTS.
Thus, to my experience, the answer is "No" to your question "For a transport stream, is the PTS/DTS dependent on the packets before it?".
What flags do you set when you open the stream? IIRC there is a flag to "fill in" corrected PTS values. I've never set such a flag.
More information about the Libav-user