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

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

Resolving Patch

  • libavformat/utils.c

    From aac495a25fc0ceb17eabbcd73c6519b7dcb9da30 Mon Sep 17 00:00:00 2001
    From: Heesuk Jung <heesuk.jung@lge.com>
    Date: Fri, 16 Nov 2012 16:26:04 +0900
    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 |   13 ++++++++++++-
     1 files changed, 12 insertions(+), 1 deletions(-)
    
    diff --git a/libavformat/utils.c b/libavformat/utils.c
    index 4072ac8..fb55477 100644
    a b static void estimate_timings_from_bit_rate(AVFormatContext *ic) 
    21612161 
    21622162#define DURATION_MAX_READ_SIZE 250000LL 
    21632163#define DURATION_MAX_RETRY 4 
     2164#define DURATION_MULTIPLE_LIMIT 8 
    21642165 
    21652166/* only usable for MPEG-PS streams */ 
    21662167static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    21702171    int read_size, i, ret; 
    21712172    int64_t end_time; 
    21722173    int64_t filesize, offset, duration; 
     2174    int64_t ref_duration, pre_duration; 
    21732175    int retry=0; 
    21742176 
    21752177    /* flush packet queue */ 
    static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    21902192    /* XXX: may need to support wrapping */ 
    21912193    filesize = ic->pb ? avio_size(ic->pb) : 0; 
    21922194    end_time = AV_NOPTS_VALUE; 
     2195    ref_duration = AV_NOPTS_VALUE; 
    21932196    do{ 
    21942197        offset = filesize - (DURATION_MAX_READ_SIZE<<retry); 
    21952198        if (offset < 0) 
    static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) 
    22192222                if (duration < 0) 
    22202223                    duration += 1LL<<st->pts_wrap_bits; 
    22212224                if (duration > 0) { 
    2222                     if (st->duration == AV_NOPTS_VALUE || st->duration < duration) 
     2225                    if (st->duration == AV_NOPTS_VALUE || st->duration < duration) { 
     2226                        pre_duration = st->duration; 
    22232227                        st->duration = duration; 
     2228                        if (ref_duration == AV_NOPTS_VALUE) { 
     2229                            ref_duration = st->duration; 
     2230                        } else if (st->duration/DURATION_MULTIPLE_LIMIT > ref_duration) { 
     2231                            st->duration = pre_duration; 
     2232                            break; 
     2233                        } 
     2234                    } 
    22242235                } 
    22252236            } 
    22262237            av_free_packet(pkt);