aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/mp3enc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-11-14 20:57:30 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-11-14 20:59:28 +0100
commit40176fc3149bc72c1309f93989a57aec2322e626 (patch)
tree1b58503a5d2e605b0fc239aee39d798c3fbff712 /libavformat/mp3enc.c
parent1fea432b7a6957b800006fd7c4bd9b4076b0cc06 (diff)
downloadffmpeg-40176fc3149bc72c1309f93989a57aec2322e626.tar.gz
mp3enc: Try to use a matching bitrate in the xing header.
Might Fix Ticket431 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/mp3enc.c')
-rw-r--r--libavformat/mp3enc.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 3f2f02b943..1200d0f297 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -156,7 +156,9 @@ static int mp3_write_xing(AVFormatContext *s)
{
AVCodecContext *codec = s->streams[0]->codec;
MP3Context *mp3 = s->priv_data;
- int bitrate_idx = 3;
+ int bitrate_idx;
+ int best_bitrate_idx;
+ int best_bitrate_error= INT_MAX;
int64_t xing_offset;
int32_t mask, header;
MPADecodeHeader c;
@@ -185,7 +187,17 @@ static int mp3_write_xing(AVFormatContext *s)
header |= (srate_idx << 2) << 8;
header |= channels << 6;
- for (;; bitrate_idx++) {
+ for (bitrate_idx=1; bitrate_idx<15; bitrate_idx++) {
+ int error;
+ avpriv_mpegaudio_decode_header(&c, header | (bitrate_idx << (4+8)));
+ error= FFABS(c.bit_rate - codec->bit_rate);
+ if(error < best_bitrate_error){
+ best_bitrate_error= error;
+ best_bitrate_idx = bitrate_idx;
+ }
+ }
+
+ for (bitrate_idx= best_bitrate_idx;; bitrate_idx++) {
if (15 == bitrate_idx)
return -1;