From faa0068a8755ff44908974293acc1a0a7fdae9be Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 4 Mar 2013 18:01:32 +0100 Subject: avformat: Make duration estimation from pts more robust Ignore durations which differ significantly from the previous Fixes Ticket2018 Signed-off-by: Michael Niedermayer --- libavformat/avformat.h | 2 ++ libavformat/utils.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 9b72279..d23d0e8 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -759,6 +759,8 @@ typedef struct AVStream { int64_t codec_info_duration_fields; int found_decoder; + int64_t last_duration; + /** * Those are used for average framerate estimation. */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 1be391f..724cc05 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2342,8 +2342,10 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) else duration -= st->first_dts; if (duration > 0) { - if (st->duration == AV_NOPTS_VALUE || st->duration < duration) + if (st->duration == AV_NOPTS_VALUE || st->info->last_duration<=0 || + (st->duration < duration && FFABS(duration - st->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) st->duration = duration; + st->info->last_duration = duration; } } av_free_packet(pkt); -- cgit v1.1