From: Michael Niedermayer Date: Wed, 4 Dec 2013 01:00:23 +0000 (+0100) Subject: avformat/utils: correct for timestamp wrap earlier X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=394b0c830a21e6fa343053d3b8fa92b9b08fd380;p=ffmpeg avformat/utils: correct for timestamp wrap earlier This uses dts & pts as reference instead of first_dts Signed-off-by: Michael Niedermayer --- diff --git a/libavformat/utils.c b/libavformat/utils.c index 69938460a56..f33704d4c6e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -55,6 +55,8 @@ * various utility functions for use within FFmpeg */ +static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt); + unsigned avformat_version(void) { av_assert0(LIBAVFORMAT_VERSION_MICRO >= 100); @@ -709,6 +711,17 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) } st= s->streams[pkt->stream_index]; + + if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { + // correct first time stamps to negative values + if (!is_relative(st->first_dts)) + st->first_dts = wrap_timestamp(st, st->first_dts); + if (!is_relative(st->start_time)) + st->start_time = wrap_timestamp(st, st->start_time); + if (!is_relative(st->cur_dts)) + st->cur_dts = wrap_timestamp(st, st->cur_dts); + } + pkt->dts = wrap_timestamp(st, pkt->dts); pkt->pts = wrap_timestamp(st, pkt->pts); @@ -868,13 +881,20 @@ static AVPacketList *get_next_pkt(AVFormatContext *s, AVStream *st, AVPacketList return NULL; } -static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index) +static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) { + int64_t ref = pkt->dts; + + if (ref == AV_NOPTS_VALUE) + ref = pkt->pts; + if (ref == AV_NOPTS_VALUE) + return 0; + ref &= (1LL<pts_wrap_bits)-1; + if (s->correct_ts_overflow && st->pts_wrap_bits < 63 && - st->pts_wrap_reference == AV_NOPTS_VALUE && st->first_dts != AV_NOPTS_VALUE) { + st->pts_wrap_reference == AV_NOPTS_VALUE) { int i; - int64_t ref = st->first_dts & ((1LL<pts_wrap_bits)-1); // reference time stamp should be 60 s before first time stamp int64_t pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset @@ -972,16 +992,6 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, } } - if (update_wrap_reference(s, st, stream_index) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { - // correct first time stamps to negative values - st->first_dts = wrap_timestamp(st, st->first_dts); - st->start_time = wrap_timestamp(st, st->start_time); - st->cur_dts = wrap_timestamp(st, st->cur_dts); - pkt->dts = wrap_timestamp(st, pkt->dts); - pkt->pts = wrap_timestamp(st, pkt->pts); - pts = wrap_timestamp(st, pts); - } - if (st->start_time == AV_NOPTS_VALUE) st->start_time = pts; }