From c57c770db3c41ac4caea8379c4053489bffeb032 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 21 Aug 2005 20:27:00 +0000 Subject: [PATCH] vbr audio encode patch by (Justin Ruggles: jruggle, earthlink net) with changes by me int->float as video uses float too remove silent cliping to some per codec range, this should result in an error instead remove change to utils.c as its inconsistant with video Originally committed as revision 4533 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffmpeg.c | 7 +++++++ libavcodec/faac.c | 6 +++++- libavcodec/mp3lameaudio.c | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ffmpeg.c b/ffmpeg.c index 945a81d257..d3e59a7be8 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -217,6 +217,8 @@ static int gop_size = 12; static int intra_only = 0; static int audio_sample_rate = 44100; static int audio_bit_rate = 64000; +#define QSCALE_NONE -99999 +static float audio_qscale = QSCALE_NONE; static int audio_disable = 0; static int audio_channels = 1; static int audio_codec_id = CODEC_ID_NONE; @@ -3501,6 +3503,10 @@ static void new_audio_stream(AVFormatContext *oc) audio_enc->codec_id = codec_id; audio_enc->bit_rate = audio_bit_rate; + if (audio_qscale > QSCALE_NONE) { + audio_enc->flags |= CODEC_FLAG_QSCALE; + audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale; + } audio_enc->strict_std_compliance = strict; audio_enc->thread_count = thread_count; /* For audio codecs other than AC3 or DTS we limit */ @@ -4348,6 +4354,7 @@ const OptionDef options[] = { /* audio options */ { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", }, + { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", }, { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" }, diff --git a/libavcodec/faac.c b/libavcodec/faac.c index a65bdefae5..a49cce968f 100644 --- a/libavcodec/faac.c +++ b/libavcodec/faac.c @@ -56,7 +56,11 @@ static int Faac_encode_init(AVCodecContext *avctx) faac_cfg->mpegVersion = MPEG4; faac_cfg->useTns = 0; faac_cfg->allowMidside = 1; - faac_cfg->bitRate = avctx->bit_rate; + faac_cfg->bitRate = avctx->bit_rate / avctx->channels; + if(avctx->flags & CODEC_FLAG_QSCALE) { + faac_cfg->bitRate = 0; + faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA; + } faac_cfg->outputFormat = 0; faac_cfg->inputFormat = FAAC_INPUT_16BIT; diff --git a/libavcodec/mp3lameaudio.c b/libavcodec/mp3lameaudio.c index 3f10a1025c..26764fcc88 100644 --- a/libavcodec/mp3lameaudio.c +++ b/libavcodec/mp3lameaudio.c @@ -53,6 +53,11 @@ static int MP3lame_encode_init(AVCodecContext *avctx) /* lame 3.91 doesn't work in mono */ lame_set_mode(s->gfp, JOINT_STEREO); lame_set_brate(s->gfp, avctx->bit_rate/1000); + if(avctx->flags & CODEC_FLAG_QSCALE) { + lame_set_brate(s->gfp, 0); + lame_set_VBR(s->gfp, vbr_default); + lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); + } lame_set_bWriteVbrTag(s->gfp,0); if (lame_init_params(s->gfp) < 0) goto err_close;