Ticket #1836: 0001-Wrong-duration-in-TS-container-Ticket-1836.4.patch

File 0001-Wrong-duration-in-TS-container-Ticket-1836.4.patch, 2.6 KB (added by Heesuk Jung, 4 years ago)

Resolving Patch

  • libavformat/utils.c

    From 25afab03b00a822421d07da2330483809f179506 Mon Sep 17 00:00:00 2001
    From: Heesuk Jung <heesuk.jung@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 b static void estimate_timings_from_bit_rate(AVFormatContext *ic) 
    21572157 
    21582158#define DURATION_MAX_READ_SIZE 250000LL 
    21592159#define DURATION_MAX_RETRY 4 
     2160#define DURATION_MULTIPLE_LIMIT 8 
    21602161 
    21612162/* only usable for MPEG-PS streams */ 
    21622163static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    21662167    int read_size, i, ret; 
    21672168    int64_t end_time; 
    21682169    int64_t filesize, offset, duration; 
     2170    int64_t ref_duration, pre_duration; 
    21692171    int retry=0; 
    21702172 
    21712173    /* flush packet queue */ 
    static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    21862188    /* XXX: may need to support wrapping */ 
    21872189    filesize = ic->pb ? avio_size(ic->pb) : 0; 
    21882190    end_time = AV_NOPTS_VALUE; 
     2191    i = 0; 
    21892192    do{ 
    21902193        offset = filesize - (DURATION_MAX_READ_SIZE<<retry); 
    21912194        if (offset < 0) 
    static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    22152218                if (duration < 0) 
    22162219                    duration += 1LL<<st->pts_wrap_bits; 
    22172220                if (duration > 0) { 
    2218                     if (st->duration == AV_NOPTS_VALUE || st->duration < duration) 
     2221                    if (st->duration == AV_NOPTS_VALUE || st->duration < duration) { 
     2222                        pre_duration = st->duration; 
    22192223                        st->duration = duration; 
     2224                        i++; 
     2225                        if (i == 1) { 
     2226                            ref_duration = st->duration; 
     2227                        } else { 
     2228                            if (st->duration > ref_duration*DURATION_MULTIPLE_LIMIT) { 
     2229                                st->duration = pre_duration; 
     2230                                break; 
     2231                            } 
     2232                        } 
     2233                    } 
    22202234                } 
    22212235            } 
    22222236            av_free_packet(pkt);