OSDN Git Service

avformat: Make duration estimation from pts more robust
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 4 Mar 2013 17:01:32 +0000 (18:01 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 4 Mar 2013 17:01:32 +0000 (18:01 +0100)
Ignore durations which differ significantly from the previous
Fixes Ticket2018

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/avformat.h
libavformat/utils.c

index 9b72279..d23d0e8 100644 (file)
@@ -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.
          */
index 1be391f..724cc05 100644 (file)
@@ -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);