[FFmpeg-devel] [PATCH, V2] avformat/concat: Fix wrong wrapped timestamp

Nicolas George george at nsup.org
Fri Dec 29 18:30:26 EET 2017


Wu Zhiqiang (2017-12-30):
> Normally pts_wrap_reference is based on the first packet when calling
> ff_read_packet,
> which will call  function update_wrap_reference , in libavformat/utils line
> 734:
> 
>     if (ref == AV_NOPTS_VALUE)
>         ref = pkt->pts;
>     if (st->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63
> || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow)
>         return 0;
>     ref &= (1LL << st->pts_wrap_bits)-1;
> 
>     // reference time stamp should be 60 s before first time stamp
>     pts_wrap_reference = ref - av_rescale(60, st->time_base.den,
> st->time_base.num);
> 
> Because  concat_read_header  and concat_seek do not call ff_read_packet and
> open_file does not copy pts_wrap_reference,
> it is constant value during playing.
> 
> If  demuxing packets like avformat_open_input => avformat_seek_file =>
> av_read_frame and seek time is larger than 60s,
> the constant reference time will be positive value and not  indicate the
> normal wrap margin.
> 
> Then seeking to time before pts_wrap_reference may generate huge timestamp,
> which  not expected.

Thanks for explaining, but it still does not address my concern. I
probably explained it badly. Let me try to rephrase.

When an application is reading directly from a file, if I understand
correctly, here is what happens:

1. file contains wrapped timestamps;
2. demuxer sets wrapping_bits to enable timestamps correction;
3. demuxer outputs packets with non-monotonic timestamps;
4. lavf sees non-monotonic timestamps;
5. lavf detects wrapping reference;
6. lavf fixes non-monotonic timestamps;
7. lavf returns packets with monotonic timestamps;
8. application sees packets with monotonic timestamps;
9. application has nothing to do at all about wrapping.

Is it right?

The concat demuxer behaves like any application. Therefore, I can
copy-paste and rename:

1. file contains wrapped timestamps;
2. slave demuxer sets wrapping_bits to enable timestamps correction;
3. slave demuxer outputs packets with non-monotonic timestamps;
4. lavf for slave demuxer sees non-monotonic timestamps;
5. lavf for slave demuxer detects wrapping reference;
6. lavf for slave demuxer fixes non-monotonic timestamps;
7. lavf for slave demuxer returns packets with monotonic timestamps;
8. concat sees packets with monotonic timestamps;
9. concat has nothing to do at all about wrapping.

And it should still be right. Note the conclusion: concat has nothing to
do at all about wrapping.

I will try to rephrase yet another way:

Wrapped timestamps should be de-wrapped even before concat sees them,
and thus no de-wrapping should be necessary after concat.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20171229/9c4d1c45/attachment.sig>


More information about the ffmpeg-devel mailing list