[FFmpeg-devel] [PATCH] Wrong duration in TS container (Ticket #1836)

Hee Suk Jung heesuk.jung at lge.com
Sun Nov 11 08:19:53 CET 2012


>From 25afab03b00a822421d07da2330483809f179506 Mon Sep 17 00:00:00 2001
From: Heesuk Jung <heesuk.jung at lge.com>
Date: Sat, 10 Nov 2012 23:02:21 -0800
Subject: [PATCH] Wrong duration in TS container (Ticket #1836)

Sometimes TS container file has unreasonbly big PTS in last frame.
In this case, we use previous last PTS value to decide stream dueation.

Fix 2nd promlematic file cas in Ticket #1836
link : https://docs.google.com/open?id=0B6r7ZfWFIypCNFVuWHowMFBBN0E
---
 libavformat/utils.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 0240b0c..6d953ed 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2157,6 +2157,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)

 #define DURATION_MAX_READ_SIZE 250000LL
 #define DURATION_MAX_RETRY 4
+#define DURATION_MULTIPLE_LIMIT 8

 /* only usable for MPEG-PS streams */
 static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
@@ -2166,6 +2167,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
     int read_size, i, ret;
     int64_t end_time;
     int64_t filesize, offset, duration;
+    int64_t ref_duration, pre_duration;
     int retry=0;

     /* flush packet queue */
@@ -2186,6 +2188,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
     /* XXX: may need to support wrapping */
     filesize = ic->pb ? avio_size(ic->pb) : 0;
     end_time = AV_NOPTS_VALUE;
+    i = 0;
     do{
         offset = filesize - (DURATION_MAX_READ_SIZE<<retry);
         if (offset < 0)
@@ -2215,8 +2218,19 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
                 if (duration < 0)
                     duration += 1LL<<st->pts_wrap_bits;
                 if (duration > 0) {
-                    if (st->duration == AV_NOPTS_VALUE || st->duration < duration)
+                    if (st->duration == AV_NOPTS_VALUE || st->duration < duration) {
+                        pre_duration = st->duration;
                         st->duration = duration;
+                        i++;
+                        if (i == 1) {
+                            ref_duration = st->duration;
+                        } else {
+                            if (st->duration > ref_duration*DURATION_MULTIPLE_LIMIT) {
+                                st->duration = pre_duration;
+                                break;
+                            }
+                        }
+                    }
                 }
             }
             av_free_packet(pkt);
--
1.7.9.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Wrong-duration-in-TS-container-Ticket-1836.patch
Type: application/octet-stream
Size: 2653 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121111/6c50c472/attachment.obj>


More information about the ffmpeg-devel mailing list