Ticket #738: vbr.2.diff

File vbr.2.diff, 3.3 KB (added by codon1@…, 20 years ago)

[PATCH] VBR durations

  • libavcodec/avcodec.h

     
    837837    int frame_size;
    838838    int frame_number;   ///< audio or video frame number
    839839    int real_pict_num;  ///< returns the real picture number of previous encoded frame
     840    int total_frames;   ///< Total number of frames provided by some VBR headers
    840841
    841842    /**
    842843     * number of frames the decoded output will be delayed relative to
  • libavcodec/mpegaudiodec.c

     
    169169    SCALE_GEN(4.0 / 9.0), /* 9 steps */
    170170};
    171171
     172static const int side_info_size[2][2] = {
     173    {32,17}, /* MPEG 1 */
     174    {17,9}   /* MPEG 2/2.5 */
     175};
     176
    172177static MPA_INT window[512] __attribute__((aligned(16)));
    173178
    174179/* layer 1 unscaling */
     
    25492554    MPADecodeContext *s = avctx->priv_data;
    25502555    uint32_t header;
    25512556    int out_size;
     2557    int offset;
    25522558    OUT_INT *out_samples = data;
    25532559
    25542560retry:
     
    25722578    avctx->channels = s->nb_channels;
    25732579    avctx->bit_rate = s->bit_rate;
    25742580    avctx->sub_id = s->layer;
     2581    avctx->total_frames=0;
    25752582    switch(s->layer) {
    25762583    case 1:
    25772584        avctx->frame_size = 384;
     
    25872594        break;
    25882595    }
    25892596
     2597        /* look for Xing or Info VBR header */
     2598    offset = HEADER_SIZE + side_info_size[s->lsf][s->mode == MPA_MONO ? 1 : 0];
     2599
     2600    if ((buf[offset]  == 'X' && buf[offset+1] == 'i' && buf[offset+2] == 'n' && buf[offset+3] == 'g') ||
     2601        (buf[offset]  == 'I' && buf[offset+1] == 'n' && buf[offset+2] == 'f' && buf[offset+3] == 'o')) {
     2602        uint32_t vbr_flags = (buf[offset+4] << 24) | (buf[offset+5] << 16) | (buf[offset+6] << 8) | buf[offset+7];
     2603
     2604        /* Look for frame count */
     2605        if (vbr_flags & 0x0001)
     2606            avctx->total_frames=(buf[offset+8] << 24) | (buf[offset+9] << 16) | (buf[offset+10] << 8) | buf[offset+11];
     2607    }
     2608
    25902609    if(s->frame_size<=0 || s->frame_size > buf_size){
    25912610        av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
    25922611        return -1;
  • libavformat/utils.c

     
    15501550                    st->start_time = 0;
    15511551                    st->duration = duration;
    15521552                }
     1553                if (st->codec->total_frames)
     1554                    st->duration = av_rescale(st->codec->total_frames * st->codec->frame_size / st->codec->sample_rate, st->time_base.den, st->time_base.num); 
    15531555            }
    15541556        }
    15551557    }
     
    16431645                if (st->duration == AV_NOPTS_VALUE ||
    16441646                    st->duration < duration)
    16451647                    st->duration = duration;
     1648                if (st->codec->total_frames)
     1649                    st->duration = av_rescale(st->codec->total_frames * st->codec->frame_size / st->codec->sample_rate, st->time_base.den, st->time_base.num); 
    16461650            }
    16471651        }
    16481652        av_free_packet(pkt);
     
    21102114    if (s->iformat) {
    21112115        /* no default bitrate if decoding */
    21122116        st->codec->bit_rate = 0;
     2117        st->codec->total_frames = 0;
    21132118    }
    21142119    st->index = s->nb_streams;
    21152120    st->id = id;