[FFmpeg-devel] [PATCH] mp3dec: Fix VBR bit rate parsing

Alexander Kojevnikov alexander at kojevnikov.com
Wed Feb 27 07:30:52 CET 2013


On Tue, Feb 26, 2013 at 10:28 PM, Alexander Kojevnikov
<alexander at kojevnikov.com> wrote:
> Attached patch should fix it.

Re-attaching as .txt, sorry about the noise.
-------------- next part --------------
From 56341406d39716a1424a72fd8aa24334d9821e8c Mon Sep 17 00:00:00 2001
From: Alexander Kojevnikov <alexander at kojevnikov.com>
Date: Tue, 26 Feb 2013 21:47:11 -0800
Subject: [PATCH] mp3dec: Fix VBR bit rate parsing

When parsing the Xiph/Info tag, don't set the stream size (and as a
result, the bit rate) if it's an Info tag.

When parsing the stream, don't override the bit rate if it's already
set. This way, the bit rate will be set correctly both for CBR and VBR
streams.

Signed-off-by: Alexander Kojevnikov <alexander at kojevnikov.com>
---
 libavcodec/mpegaudio_parser.c | 3 ++-
 libavformat/mp3dec.c          | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 5f97d71..8869eb0 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -81,7 +81,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
                         avctx->sample_rate= sr;
                         avctx->channels   = channels;
                         s1->duration      = frame_size;
-                        avctx->bit_rate   = bit_rate;
+                        if (!avctx->bit_rate)
+                            avctx->bit_rate = bit_rate;
                     }
                     break;
                 }
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index c6d6987..a6132e4 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -120,6 +120,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_xing;
 
     v = avio_rb32(s->pb);
     if(ff_mpa_check_header(v) < 0)
@@ -135,11 +136,13 @@ 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_xing = v == MKBETAG('X', 'i', 'n', 'g');
+    if (is_xing || v == MKBETAG('I', 'n', 'f', 'o')) {
         v = avio_rb32(s->pb);
         if(v & XING_FLAG_FRAMES)
             frames = avio_rb32(s->pb);
-        if(v & XING_FLAG_SIZE)
+        /* Don't set size/bitrate for CBR streams */
+        if (v & XING_FLAG_SIZE && is_xing)
             size = avio_rb32(s->pb);
         if (v & XING_FLAG_TOC && frames)
             read_xing_toc(s, size, av_rescale_q(frames, (AVRational){spf, c.sample_rate},
-- 
1.8.1.3


More information about the ffmpeg-devel mailing list