Ticket #1755: avidec.patch

File avidec.patch, 3.3 KB (added by Heesuk Jung, 4 years ago)

git format-patch file

  • libavformat/avidec.c

    From 7a4de1cae459fab89b84ab172f7112a6cd544664 Mon Sep 17 00:00:00 2001
    From: Heesuk Jung <heesuk.jung@lge.com>
    Date: Wed, 10 Oct 2012 05:35:41 -0700
    Subject: [PATCH] Use sample size in case incorrect timestamps for aac in AVI
     (Ticket #1755)
    
    In some case for aac in AVI, avidec extracts wrong PTS value.
    (www.ffmpeg.org/trac/ffmpeg/ticket/1755)
    In getDuration function, I suggest using sample size instead of len.
    
    I have done regression test in our media pool.
    
    Test result of 11 problematic files is ok after patch apply.
    (11 files have fixed sample size in AVI Stream Header)
    
    Regression test reseult of 4 non-problematic files is ok after patch apply.
    (4 files have variable sample size in AVI Stream Header)
    ---
     libavformat/avidec.c |   16 ++++++++++------
     1 file changed, 10 insertions(+), 6 deletions(-)
    
    diff --git a/libavformat/avidec.c b/libavformat/avidec.c
    index b4c5fe8..43d80ce 100644
    a b static int guess_ni_flag(AVFormatContext *s); 
    115115           (tag >> 24) & 0xff,                          \ 
    116116           size) 
    117117 
    118 static inline int get_duration(AVIStream *ast, int len){ 
     118static inline int get_duration(AVIStream *ast, int len, enum AVCodecID codecId) { 
    119119    if(ast->sample_size){ 
    120         return len; 
     120        if (codecId == AV_CODEC_ID_AAC) { 
     121            return ast->sample_size; 
     122        } else { 
     123            return len; 
     124        } 
    121125    }else if (ast->dshow_block_align){ 
    122126        return (len + ast->dshow_block_align - 1)/ast->dshow_block_align; 
    123127    }else 
    static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ 
    208212            if(last_pos != pos && (len || !ast->sample_size)) 
    209213                av_add_index_entry(st, pos, ast->cum_len, len, 0, key ? AVINDEX_KEYFRAME : 0); 
    210214 
    211             ast->cum_len += get_duration(ast, len); 
     215            ast->cum_len += get_duration(ast, len, st->codec->codec_id); 
    212216            last_pos= pos; 
    213217        }else{ 
    214218            int64_t offset, pos; 
    start_sync: 
    990994               /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering 
    991995               || st->discard >= AVDISCARD_ALL){ 
    992996                if (!exit_early) { 
    993                     ast->frame_offset += get_duration(ast, size); 
     997                    ast->frame_offset += get_duration(ast, size, st->codec->codec_id); 
    994998                } 
    995999                avio_skip(pb, size); 
    9961000                goto start_sync; 
    resync: 
    12061210            } else { 
    12071211                pkt->flags |= AV_PKT_FLAG_KEY; 
    12081212            } 
    1209             ast->frame_offset += get_duration(ast, pkt->size); 
     1213            ast->frame_offset += get_duration(ast, pkt->size, st->codec->codec_id); 
    12101214        } 
    12111215        ast->remaining -= err; 
    12121216        if(!ast->remaining){ 
    static int avi_read_idx1(AVFormatContext *s, int size) 
    13011305            av_add_index_entry(st, pos, ast->cum_len, len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0); 
    13021306            last_idx= pos; 
    13031307        } 
    1304         ast->cum_len += get_duration(ast, len); 
     1308        ast->cum_len += get_duration(ast, len, st->codec->codec_id); 
    13051309        last_pos= pos; 
    13061310        anykey |= flags&AVIIF_INDEX; 
    13071311    }