aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kojevnikov <alexander@kojevnikov.com>2013-02-26 21:47:11 -0800
committerMichael Niedermayer <michaelni@gmx.at>2013-03-20 22:02:28 +0100
commit7cb24ecd4c41d3e31dd5d5f56e0f5bfa081ac5a7 (patch)
tree6e4ecda4519414e3b28e47be0c58da6759e2fe49
parent9faf323d7ed177d19005b66debba39b10930042a (diff)
downloadffmpeg-7cb24ecd4c41d3e31dd5d5f56e0f5bfa081ac5a7.tar.gz
mp3dec: Fix VBR bit rate parsing
When parsing the Xing/Info tag, don't set the bit rate if it's an Info tag. When parsing the stream, don't override the bit rate if it's already set, otherwise calculate the mean bit rate from parsed frames. This way, the bit rate will be set correctly both for CBR and VBR streams. Signed-off-by: Alexander Kojevnikov <alexander@kojevnikov.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 29d8cd265a536063420afe78375b2176a9e1abc5) Conflicts: tests/ref/lavf-fate/mp3 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/mpegaudio_parser.c10
-rw-r--r--libavformat/mp3dec.c6
-rw-r--r--tests/ref/lavf-fate/mp34
3 files changed, 13 insertions, 7 deletions
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 6ceca83e04..83dbca0e04 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -29,6 +29,7 @@ typedef struct MpegAudioParseContext {
int frame_size;
uint32_t header;
int header_count;
+ int no_bitrate;
} MpegAudioParseContext;
#define MPA_HEADER_SIZE 4
@@ -73,15 +74,18 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
s->header_count= -3;
s->header= state;
- s->header_count++;
s->frame_size = ret-4;
- if (s->header_count > 1) {
+ if (s->header_count > 0) {
avctx->sample_rate= sr;
avctx->channels = channels;
s1->duration = frame_size;
- avctx->bit_rate = bit_rate;
+ if (s->no_bitrate || !avctx->bit_rate) {
+ s->no_bitrate = 1;
+ avctx->bit_rate += (bit_rate - avctx->bit_rate) / s->header_count;
+ }
}
+ s->header_count++;
break;
}
}
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 61405f71b7..87b3bb62ca 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -88,6 +88,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
MPADecodeHeader c;
int vbrtag_size = 0;
+ int is_cbr;
v = avio_rb32(s->pb);
if(ff_mpa_check_header(v) < 0)
@@ -101,7 +102,8 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
/* Check for Xing / Info tag */
avio_skip(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1]);
v = avio_rb32(s->pb);
- if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) {
+ is_cbr = v == MKBETAG('I', 'n', 'f', 'o');
+ if (v == MKBETAG('X', 'i', 'n', 'g') || is_cbr) {
v = avio_rb32(s->pb);
if(v & 0x1)
frames = avio_rb32(s->pb);
@@ -132,7 +134,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
if(frames)
st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
st->time_base);
- if(size && frames)
+ if (size && frames && !is_cbr)
st->codec->bit_rate = av_rescale(size, 8 * c.sample_rate, frames * (int64_t)spf);
return 0;
diff --git a/tests/ref/lavf-fate/mp3 b/tests/ref/lavf-fate/mp3
index 48a5476f8a..1af3652d3a 100644
--- a/tests/ref/lavf-fate/mp3
+++ b/tests/ref/lavf-fate/mp3
@@ -1,3 +1,3 @@
-67cbcc79f018afb68f7d81625bfa234c *./tests/data/lavf-fate/lavf.mp3
-97230 ./tests/data/lavf-fate/lavf.mp3
+0f7b603ab305759ea4e853326f77da60 *./tests/data/lavf-fate/lavf.mp3
+96366 ./tests/data/lavf-fate/lavf.mp3
./tests/data/lavf-fate/lavf.mp3 CRC=0x6c9850fe