[Libav-user] audio sync issues with h264

Gonzalo Garramuno ggarra13 at gmail.com
Thu Jun 12 20:08:23 CEST 2014

On 11/06/14 18:56, Gonzalo Garramuno wrote:
> I have written a viewer that allows writing h264 video with libx264. 
> However the audio (mp3, ac3 or aac) comes out of sync with the video.  
> The problem seems to be the first 20 frames or so that are not written 
> out to the file.
> I can reproduce the problem with the muxing.c example from the docs 
> when I modify it like the attached diff.
> In that case, I cannot tell that it starts early but the sound ends 20 
> frames before the end of the movie.
> Can someone suggest something to try?
Okay.  The problem is that video_time is calculated from 
AVStream->pts.val and that does not get updated in each frame with 
h264.  I switched to picture->pts for my timing calculations and all is 

More information about the Libav-user mailing list