From d30a8beb99caad9738fc17ca36ad19b545c911c4 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Wed, 27 Jan 2010 19:37:52 +0000
Subject: [PATCH] Fix duration calculation in the presence of a single wraping
 of the timeline. Fixes issue1714.

Originally committed as revision 21485 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavformat/utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 64c5ec492bd..c15b5f1cf05 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1823,6 +1823,8 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
             start_time[pkt->stream_index] != AV_NOPTS_VALUE) {
             end_time = pkt->pts;
             duration = end_time - start_time[pkt->stream_index];
+            if (duration < 0)
+                duration += 1LL<<st->pts_wrap_bits;
             if (duration > 0) {
                 if (st->duration == AV_NOPTS_VALUE ||
                     st->duration < duration)
-- 
GitLab