[FFmpeg-cvslog] avformat: Make duration estimation from pts more robust

Michael Niedermayer git at videolan.org
Mon Mar 4 18:09:17 CET 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Mar  4 18:01:32 2013 +0100| [faa0068a8755ff44908974293acc1a0a7fdae9be] | committer: Michael Niedermayer

avformat: Make duration estimation from pts more robust

Ignore durations which differ significantly from the previous
Fixes Ticket2018

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=faa0068a8755ff44908974293acc1a0a7fdae9be
---

 libavformat/avformat.h |    2 ++
 libavformat/utils.c    |    4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

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);



More information about the ffmpeg-cvslog mailing list