Ticket #1432: avi-mp3-v1.patch

File avi-mp3-v1.patch, 2.7 KB (added by mjs973, 4 years ago)
  • libavformat/avidec.c

    From 753f08447f3a7b5859366b9274cd07ed4cd23484 Mon Sep 17 00:00:00 2001
    From: Mike Scheutzow <mjs973@optonline.net>
    Date: Wed, 27 Jun 2012 11:28:07 -0400
    Subject: [PATCH] Fix timestamp calculation when demuxing MP3 frames in a .avi container.
     The bad code was using the frame byte length to calculate a timestamp,
     which is completely broken. Also set AVPacket.duration, since demux is
     already calculating it. The existing avi muxer already properly handles
     the muxing and index creation for MP3 audio frames.  Fixes the sample
     file in trac 1432.
    
    
    Signed-off-by: Mike Scheutzow <mjs973@optonline.net>
    ---
     libavformat/avidec.c |   18 ++++++++++++++++--
     1 files changed, 16 insertions(+), 2 deletions(-)
    
    diff --git a/libavformat/avidec.c b/libavformat/avidec.c
    index fea0694..4835750 100644
    a b static int guess_ni_flag(AVFormatContext *s); 
    116116           (tag >> 24) & 0xff,                          \ 
    117117           size) 
    118118 
     119/* calculate the duration of the current frame, in units of AVStream.time_base. 
     120 * For video, or audio frames with variable byte length, the output value 
     121 * is defined to be '1'. 
     122 */ 
    119123static inline int get_duration(AVIStream *ast, int len){ 
    120124    if(ast->sample_size){ 
    121125        return len; 
    static int avi_read_header(AVFormatContext *s) 
    655659                    ret = ff_get_wav_header(pb, st->codec, size); 
    656660                    if (ret < 0) 
    657661                        return ret; 
    658                     ast->dshow_block_align= st->codec->block_align; 
     662                    if (st->codec->codec_id == CODEC_ID_MP3) { 
     663                        /* this file assumes that a non-zero sample_size  
     664                         * means constant frame byte length; mp3 frames have  
     665                         * variable byte length */ 
     666                        ast->sample_size = 0; 
     667                        // must keep ast->dshow_block_align = 0 
     668                    } else { 
     669                        ast->dshow_block_align= st->codec->block_align; 
     670                    } 
    659671                    if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){ 
    660672                        av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align); 
    661673                        ast->sample_size= st->codec->block_align; 
    resync: 
    12041216            } else { 
    12051217                pkt->flags |= AV_PKT_FLAG_KEY; 
    12061218            } 
    1207             ast->frame_offset += get_duration(ast, pkt->size); 
     1219            /* pkt may contain multiple frames */ 
     1220            pkt->duration = get_duration(ast, pkt->size); 
     1221            ast->frame_offset += pkt->duration; 
    12081222        } 
    12091223        ast->remaining -= size; 
    12101224        if(!ast->remaining){