gstavdemux: wrong first buffer pts because of rounding in timestamp conversion
To reproduce:
- Take my patches from !12 (closed) to enable the CDG demuxer
- Download bug.cdg
- Run this pipeline with attached file:
gst-launch-1.0 filesrc location=bug.cdg ! avdemux_cdg ! fakesink silent=false -v
- As you can see the pts of the first buffer is wrong:
/GstPipeline:pipeline0/GstFakeSink:fakesink0: last-message = chain ******* (fakesink0:sink) (24 bytes, dts: none, pts: 5124095:34:33.709551283, duration: none, offset: -1, offset_end: -1, flags: 00000040 discont , meta: none) 0x7f5c58006490
/GstPipeline:pipeline0/GstFakeSink:fakesink0: last-message = chain ******* (fakesink0:sink) (24 bytes, dts: none, pts: 0:00:00.003333000, duration: none, offset: -1, offset_end: -1, flags: 00002000 delta-unit , meta: none) 0x7f5c580065a0
/GstPipeline:pipeline0/GstFakeSink:fakesink0: last-message = chain ******* (fakesink0:sink) (24 bytes, dts: none, pts: 0:00:00.006666333, duration: none, offset: -1, offset_end: -1, flags: 00000000 , meta: none) 0x7f5c58006490
When receiving a buffer from libav we substract the start_time from it.
The start_time is supposed to be the ts of the first buffer But in this case the start_time is higher than the ts of the first buffer.
0:00:00.051697960 29116 0x7b8230 DEBUG libav gstavdemux.c:1262:gst_ffmpegdemux_open:<avdemux_cdg0> start time: 0:00:00.026667000
(...)
0:00:00.051936425 29116 0x7b8230 DEBUG libav gstavdemux.c:1468:gst_ffmpegdemux_loop:<avdemux_cdg0> pkt pts:0:00:00.026666667 / size:24 / stream_index:0 / flags:1 / duration:99:99:99.99999>
This difference is because of a round up error when translating libav timestamps.
start_time is computed using:
gst_util_uint64_scale_int (26667, GST_SECOND, AV_TIME_BASE) = 26667000
while the frame ts is computed using the stream time base (1/300): av_rescale_q (8, base, bq) = 26666667
Does that makes sense? What would be the proper way to fix this? Truncate the ts precision to μs? Is ffmpeg actually precised to the ns?