Browse code

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

Justin Ruggles authored on 2005/08/22 05:27:00
Showing 3 changed files
... ...
@@ -217,6 +217,8 @@ static int gop_size = 12;
217 217
 static int intra_only = 0;
218 218
 static int audio_sample_rate = 44100;
219 219
 static int audio_bit_rate = 64000;
220
+#define QSCALE_NONE -99999
221
+static float audio_qscale = QSCALE_NONE;
220 222
 static int audio_disable = 0;
221 223
 static int audio_channels = 1;
222 224
 static int audio_codec_id = CODEC_ID_NONE;
... ...
@@ -3501,6 +3503,10 @@ static void new_audio_stream(AVFormatContext *oc)
3501 3501
         audio_enc->codec_id = codec_id;
3502 3502
         
3503 3503
         audio_enc->bit_rate = audio_bit_rate;
3504
+        if (audio_qscale > QSCALE_NONE) {
3505
+            audio_enc->flags |= CODEC_FLAG_QSCALE;
3506
+            audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
3507
+        }
3504 3508
         audio_enc->strict_std_compliance = strict;
3505 3509
         audio_enc->thread_count = thread_count;
3506 3510
         /* For audio codecs other than AC3 or DTS we limit */
... ...
@@ -4348,6 +4354,7 @@ const OptionDef options[] = {
4348 4348
 
4349 4349
     /* audio options */
4350 4350
     { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", },
4351
+    { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
4351 4352
     { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
4352 4353
     { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
4353 4354
     { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" },
... ...
@@ -56,7 +56,11 @@ static int Faac_encode_init(AVCodecContext *avctx)
56 56
     faac_cfg->mpegVersion = MPEG4;
57 57
     faac_cfg->useTns = 0;
58 58
     faac_cfg->allowMidside = 1;
59
-    faac_cfg->bitRate = avctx->bit_rate;
59
+    faac_cfg->bitRate = avctx->bit_rate / avctx->channels;
60
+    if(avctx->flags & CODEC_FLAG_QSCALE) {
61
+        faac_cfg->bitRate = 0;
62
+        faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA;
63
+    }
60 64
     faac_cfg->outputFormat = 0;
61 65
     faac_cfg->inputFormat = FAAC_INPUT_16BIT;
62 66
 
... ...
@@ -53,6 +53,11 @@ static int MP3lame_encode_init(AVCodecContext *avctx)
53 53
 	/* lame 3.91 doesn't work in mono */
54 54
 	lame_set_mode(s->gfp, JOINT_STEREO);
55 55
 	lame_set_brate(s->gfp, avctx->bit_rate/1000);
56
+    if(avctx->flags & CODEC_FLAG_QSCALE) {
57
+        lame_set_brate(s->gfp, 0);
58
+        lame_set_VBR(s->gfp, vbr_default);
59
+        lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA);
60
+    }
56 61
         lame_set_bWriteVbrTag(s->gfp,0);
57 62
 	if (lame_init_params(s->gfp) < 0)
58 63
 		goto err_close;