Commit b0bac9ba authored by alexc's avatar alexc

Turn on AAC rate control.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@19379 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent e48feb2a
...@@ -457,15 +457,6 @@ static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce ...@@ -457,15 +457,6 @@ static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce
} }
} }
static void encode_window_bands_info_fixed(AACEncContext *s,
SingleChannelElement *sce,
int win, int group_len,
const float lambda)
{
encode_window_bands_info(s, sce, win, group_len, 1.0f);
}
typedef struct TrellisPath { typedef struct TrellisPath {
float cost; float cost;
int prev; int prev;
...@@ -700,7 +691,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, ...@@ -700,7 +691,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
sce->ics.swb_sizes[g], sce->ics.swb_sizes[g],
sce->sf_idx[w*16+g], sce->sf_idx[w*16+g],
ESC_BT, ESC_BT,
1.0, lambda,
INFINITY, INFINITY,
&b); &b);
bb += b; bb += b;
...@@ -710,7 +701,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, ...@@ -710,7 +701,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
minbits = bb; minbits = bb;
} }
} }
dists[w*16+g] = mindist - minbits; dists[w*16+g] = (mindist - minbits) / lambda;
bits = minbits; bits = minbits;
if (prev != -1) { if (prev != -1) {
bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO]; bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
...@@ -870,12 +861,12 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, ...@@ -870,12 +861,12 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s,
sce->ics.swb_sizes[g], sce->ics.swb_sizes[g],
scf, scf,
ESC_BT, ESC_BT,
1.0, lambda,
INFINITY, INFINITY,
&b); &b);
dist -= b; dist -= b;
} }
dist *= 1.0f/512.0f; dist *= 1.0f / 512.0f / lambda;
quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]);
if (quant_max >= 8191) { // too much, return to the previous quantizer if (quant_max >= 8191) { // too much, return to the previous quantizer
sce->sf_idx[w*16+g] = prev_scf; sce->sf_idx[w*16+g] = prev_scf;
...@@ -1019,7 +1010,7 @@ static void search_for_ms(AACEncContext *s, ChannelElement *cpe, ...@@ -1019,7 +1010,7 @@ static void search_for_ms(AACEncContext *s, ChannelElement *cpe,
AACCoefficientsEncoder ff_aac_coders[] = { AACCoefficientsEncoder ff_aac_coders[] = {
{ {
search_for_quantizers_faac, search_for_quantizers_faac,
encode_window_bands_info_fixed, encode_window_bands_info,
quantize_and_encode_band, quantize_and_encode_band,
// search_for_ms, // search_for_ms,
}, },
......
...@@ -583,6 +583,7 @@ static int aac_encode_frame(AVCodecContext *avctx, ...@@ -583,6 +583,7 @@ static int aac_encode_frame(AVCodecContext *avctx,
if (!(avctx->flags & CODEC_FLAG_QSCALE)) { if (!(avctx->flags & CODEC_FLAG_QSCALE)) {
float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / avctx->frame_bits; float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / avctx->frame_bits;
s->lambda *= ratio; s->lambda *= ratio;
s->lambda = fminf(s->lambda, 65536.f);
} }
if (avctx->frame_bits > 6144*avctx->channels) if (avctx->frame_bits > 6144*avctx->channels)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment