[FFmpeg-devel] How to debug the audio can video synchonization problem

zhihang wang zhihang.wang
Sun Jun 27 10:58:34 CEST 2010

I transcode a mpeg-2 ts stream to a mp4 format with the x264 encoder. But
the audio and video can't be syncronized correctly. So I want to output the
input ts PTS info and the output PTS info to find the problem.

I opened some logging switch. But I can't understand all of them.
First I open the log info in output_packet.
                    printf("%d: got pts=%0.3f %0.3f\n", i,
                           (double)pkt->pts / AV_TIME_BASE,
                           ((double)ist->pts / AV_TIME_BASE) -
((double)ost->st->pts.val * ost->st->time_base.num /
What's the meaning of "  ((double)ist->pts / AV_TIME_BASE) -
((double)ost->st->pts.val * ost->st->time_base.num /

Then I opened log in the function av_interleaved_write_frame
av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %"PRId64"
%"PRId64"\n", pkt->size, pkt->dts, pkt->pts);

What's the pts info in this log mean?

And also I opened the log in compute_pkt_fields2

av_log(st->codec, AV_LOG_DEBUG, "av_write_frame: pts:%"PRId64" dts:%"PRId64"
cur_dts:%"PRId64" b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts,
delay, pkt->size, pkt->stream_index);


av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts2:%"PRId64"
dts2:%"PRId64"\n", pkt->pts, pkt->dts);

But now I can't understand the relationship between these PTS infor. Would
someone like to give me some help?
Best Regards
zhihang wang

More information about the ffmpeg-devel mailing list