[FFmpeg-devel] libavformat/utils.c/compute_pkt_fields2: calculate dts from pts

Dirk Musfeldt d.musfeldt
Tue Oct 9 08:59:18 CEST 2007


I'm using libavformat to re-mux an MPEG TS to PS. When feeding the PES into
av_write_frame() I'm getting log messages of "error, non monotone
timestamps" .

So I was thinking about compute_pkt_fields2(). Is the algorithm to compute
dts from pts really working as expected?

It will probably work fine if either no packet has a valid dts (i.e. every
packet has dts value AV_NOPTS_VALUE) or every packet has a valid dts value
(which is the trivial case).

But what if the I-frames and P-frames have valid dts but the B-frames don't?
In this case only the pts values from B-frames are stored into

Let's assume that the stream has packets P2 B0 B1 P5 B3 B4 where the digit
indicates the PTS value. P5 has dts value 2 while the B-frames don't have
dts values.

When computing dts for B3 the table st->pts_buffer will have the pts values
1 and 3, so that dts value for B3 becomes 1.

But we have already seen P2 so that st->cur_dts is already 2 which gives the
error message while the stream itself is perfectly valid.

What do you think?



More information about the ffmpeg-devel mailing list