Revision 49d7ef28 libavformat/mp3.c

View differences:

libavformat/mp3.c
84 84
{
85 85
    uint32_t v, spf;
86 86
    int frames = -1; /* Total number of frames in file */
87
    unsigned size = 0; /* Total number of bytes in the stream */
87 88
    const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
88 89
    MPADecodeHeader c;
89 90
    int vbrtag_size = 0;
......
104 105
        v = get_be32(s->pb);
105 106
        if(v & 0x1)
106 107
            frames = get_be32(s->pb);
108
        if(v & 0x2)
109
            size = get_be32(s->pb);
107 110
    }
108 111

  
109 112
    /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
......
112 115
    if(v == MKBETAG('V', 'B', 'R', 'I')) {
113 116
        /* Check tag version */
114 117
        if(get_be16(s->pb) == 1) {
115
            /* skip delay, quality and total bytes */
116
            url_fseek(s->pb, 8, SEEK_CUR);
118
            /* skip delay and quality */
119
            url_fseek(s->pb, 4, SEEK_CUR);
117 120
            frames = get_be32(s->pb);
121
            size = get_be32(s->pb);
118 122
        }
119 123
    }
120 124

  
121
    if(frames < 0)
125
    if(frames < 0 && !size)
122 126
        return -1;
123 127

  
124 128
    /* Skip the vbr tag frame */
125 129
    url_fseek(s->pb, base + vbrtag_size, SEEK_SET);
126 130

  
127 131
    spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
128
    st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
129
                                st->time_base);
132
    if(frames >= 0)
133
        st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
134
                                    st->time_base);
135
    if(size)
136
        st->codec->bit_rate = av_rescale(size, 8 * c.sample_rate, frames * (int64_t)spf);
137

  
130 138
    return 0;
131 139
}
132 140

  

Also available in: Unified diff