[Libav-user] How to perform drift compensation in MPEG-2 recorder

Mike Versteeg mike at mikeversteeg.com
Wed Dec 19 14:07:01 CET 2012

Found another thread with similar question:

Again, not answered.

I do not think no one has ever considered video and audio clocks can
slightly drift away from each other, so the lack of feedback is likely
because the questions are wrong. I am therefore trying to rephrase my,
and all these similar questions, as follows..

Using the sample code referred to, there is a direct connection
between a video frame (lasting 1/fps) and an audio frame (fixed length
lasting length/samplerate). This works fine as long as the audio and
video clock are in perfect sync. However when has only the smallest
difference from the other, after a while (could be hours) an error
accumulates resulting in a slight AV sync problem. Obviously this
problem can be fixed by monitoring this difference and resampling the
audio data, but it uses resources. Changing the audio packet size
dynamically seems a solution, but it does not seem possible. Is there
another way, like "modulating" some time stamp and if so, how?


More information about the Libav-user mailing list