diff options
Diffstat (limited to 'libavcodec/libmp3lame.c')
-rw-r--r-- | libavcodec/libmp3lame.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index ee76ff8812..e6cb64b876 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -2,20 +2,20 @@ * Interface to libmp3lame for mp3 encoding * Copyright (c) 2002 Lennert Buytenhek <buytenh@gnu.org> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -38,7 +38,7 @@ #include "mpegaudio.h" #include "mpegaudiodecheader.h" -#define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4) +#define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4+1000) // FIXME: Buffer size to small? Adding 1000 to make up for it. typedef struct LAMEContext { AVClass *class; @@ -48,6 +48,8 @@ typedef struct LAMEContext { int buffer_index; int buffer_size; int reservoir; + int joint_stereo; + int abr; float *samples_flt[2]; AudioFrameQueue afq; AVFloatDSPContext fdsp; @@ -95,8 +97,9 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) if ((s->gfp = lame_init()) == NULL) return AVERROR(ENOMEM); + lame_set_num_channels(s->gfp, avctx->channels); - lame_set_mode(s->gfp, avctx->channels > 1 ? JOINT_STEREO : MONO); + lame_set_mode(s->gfp, avctx->channels > 1 ? s->joint_stereo ? JOINT_STEREO : STEREO : MONO); /* sample rate */ lame_set_in_samplerate (s->gfp, avctx->sample_rate); @@ -109,12 +112,17 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) lame_set_quality(s->gfp, avctx->compression_level); /* rate control */ - if (avctx->flags & CODEC_FLAG_QSCALE) { + if (avctx->flags & CODEC_FLAG_QSCALE) { // VBR lame_set_VBR(s->gfp, vbr_default); lame_set_VBR_quality(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); } else { - if (avctx->bit_rate) - lame_set_brate(s->gfp, avctx->bit_rate / 1000); + if (avctx->bit_rate) { + if (s->abr) { // ABR + lame_set_VBR(s->gfp, vbr_abr); + lame_set_VBR_mean_bitrate_kbps(s->gfp, avctx->bit_rate / 1000); + } else // CBR + lame_set_brate(s->gfp, avctx->bit_rate / 1000); + } } /* do not get a Xing VBR header frame from LAME */ @@ -238,10 +246,8 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index); if (len <= s->buffer_index) { - if ((ret = ff_alloc_packet(avpkt, len))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, len)) < 0) return ret; - } memcpy(avpkt->data, s->buffer, len); s->buffer_index -= len; memmove(s->buffer, s->buffer + len, s->buffer_index); @@ -259,7 +265,9 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, #define OFFSET(x) offsetof(LAMEContext, x) #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { - { "reservoir", "Use bit reservoir.", OFFSET(reservoir), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE }, + { "reservoir", "use bit reservoir", OFFSET(reservoir), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE }, + { "joint_stereo", "use joint stereo", OFFSET(joint_stereo), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE }, + { "abr", "use ABR", OFFSET(abr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE }, { NULL }, }; |