From 8da0a6cda1bd59471df6a4a18988c2381c05cee7 Mon Sep 17 00:00:00 2001 From: Tobias Rapp Date: Mon, 7 May 2012 11:55:05 +0200 Subject: mp3enc: Fix Xing tag identification string for CBR files Fixes the Xing tag identification string to be "Info" for MP3 files with constant bitrate. The previous "Xing" caused some decoders to recognize the file as VBR. Signed-off-by: Michael Niedermayer --- libavformat/mp3enc.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'libavformat/mp3enc.c') diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 29c0780b90..415fdba79f 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -94,6 +94,8 @@ typedef struct MP3Context { uint32_t seen; uint32_t pos; uint64_t bag[VBR_NUM_BAGS]; + int initial_bitrate; + int has_variable_bitrate; /* index of the audio stream */ int audio_stream_idx; @@ -238,6 +240,16 @@ static void mp3_fix_xing(AVFormatContext *s) int i; avio_flush(s->pb); + + /* replace "Xing" identification string with "Info" for CBR files. */ + if (!mp3->has_variable_bitrate) { + int64_t tag_offset = mp3->frames_offset + - 4 // frames/size/toc flags + - 4; // xing tag + avio_seek(s->pb, tag_offset, SEEK_SET); + avio_wb32(s->pb, MKBETAG('I', 'n', 'f', 'o')); + } + avio_seek(s->pb, mp3->frames_offset, SEEK_SET); avio_wb32(s->pb, mp3->frames); avio_wb32(s->pb, mp3->size); @@ -260,12 +272,21 @@ static int mp3_write_packet_internal(AVFormatContext *s, AVPacket *pkt) return ff_raw_write_packet(s, pkt); else { MP3Context *mp3 = s->priv_data; -#ifdef FILTER_VBR_HEADERS MPADecodeHeader c; +#ifdef FILTER_VBR_HEADERS int base; +#endif + + avpriv_mpegaudio_decode_header(&c, AV_RB32(pkt->data)); - ff_mpegaudio_decode_header(&c, AV_RB32(pkt->data)); + if (!mp3->initial_bitrate) + mp3->initial_bitrate = c.bit_rate; + if (!mp3->has_variable_bitrate) { + if ((c.bit_rate == 0) || (mp3->initial_bitrate != c.bit_rate)) + mp3->has_variable_bitrate = 1; + } +#ifdef FILTER_VBR_HEADERS /* filter out XING and INFO headers. */ base = 4 + xing_offtbl[c.lsf == 1][c.nb_channels == 1]; -- cgit v1.2.3