[libav-api] Synchronizing audio and video; meanings of pts

Jieyun Fu jieyunfu at mit.edu
Sat Mar 19 21:33:09 CET 2011


I have a potentially dumb question about synchronizing audio and video using
libav. I saw this piece of code in output-example.c, looks like users sync
audio and video up by comparing audio_pts and video_pts. I have a few

1. what do audio_st->pts and video_st->pts stand for?

2. what do audio_pts and video_pts stand for, how is it different,  if we
compute audio_pts and video_pts by doing

audio_pts = (double)audio_st->pts.val * audio_st->time_base.num /
video_pts = (double)video_st->pts.val * video_st->time_base.num /

3. I can understand video_st->time_base, which would directly relate to the
frame rate. How about audio_st->time_base then? How is this defined?

Appreciate all the help!

    for(;;) {
        /* compute current audio and video time */
        if (audio_st)
            audio_pts = (double)audio_st->pts.val * audio_st->time_base.num
/ audio_st->time_base.den;
            audio_pts = 0.0;

        if (video_st)
            video_pts = (double)video_st->pts.val * video_st->time_base.num
/ video_st->time_base.den;
            video_pts = 0.0;

        if ((!audio_st || audio_pts >= STREAM_DURATION) &&
            (!video_st || video_pts >= STREAM_DURATION))

        /* write interleaved audio and video frames */
        if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
            write_audio_frame(oc, audio_st);
        } else {
            write_video_frame(oc, video_st);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libav.org/pipermail/libav-api/attachments/20110319/353eb4fe/attachment.htm>

More information about the libav-api mailing list