summaryrefslogtreecommitdiffstats
path: root/libavcodec/aacpsy.c
diff options
context:
space:
mode:
authorClaudio Freire <klaussfreire@gmail.com>2015-09-23 02:13:56 -0300
committerClaudio Freire <klaussfreire@gmail.com>2015-09-23 02:33:44 -0300
commit7ec74ae4aaf50507c5da3dfbb7336e15f848b99b (patch)
tree2ff0ca4d23f852a61fc47c006b3cf2419eb48ba7 /libavcodec/aacpsy.c
parentb01f3ddad31aba45254dfd553447c7952f86fd31 (diff)
downloadffmpeg-streaming-7ec74ae4aaf50507c5da3dfbb7336e15f848b99b.zip
ffmpeg-streaming-7ec74ae4aaf50507c5da3dfbb7336e15f848b99b.tar.gz
AAC encoder: tweak rate-distortion logic
This patch modifies the encode frame function to retry encoding the frame when the resulting bit count is too far off target, but only adjusting lambda in small, incremental step. It also makes the logic more conservative - otherwise it will contend with bit reservoir-related variations in bit allocation, and result in artifacts when frame have to be truncated (usually at high bit rates transitioning from low complexity to high complexity).
Diffstat (limited to 'libavcodec/aacpsy.c')
-rw-r--r--libavcodec/aacpsy.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 82b670d..af235c7 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -87,6 +87,7 @@ enum {
};
#define PSY_3GPP_BITS_TO_PE(bits) ((bits) * 1.18f)
+#define PSY_3GPP_PE_TO_BITS(bits) ((bits) / 1.18f)
/* LAME psy model constants */
#define PSY_LAME_FIR_LEN 21 ///< LAME psy model FIR order
@@ -687,6 +688,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel,
desired_pe *= av_clipf(pctx->pe.previous / PSY_3GPP_BITS_TO_PE(ctx->bitres.bits),
0.85f, 1.15f);
pctx->pe.previous = PSY_3GPP_BITS_TO_PE(desired_bits);
+ ctx->bitres.alloc = desired_bits;
if (desired_pe < pe) {
/* 5.6.1.3.4 "First Estimation of the reduction value" */
@@ -788,6 +790,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel,
psy_band->threshold = band->thr;
psy_band->energy = band->energy;
psy_band->spread = band->active_lines * 2.0f / band_sizes[g];
+ psy_band->bits = PSY_3GPP_PE_TO_BITS(band->pe);
}
}
OpenPOWER on IntegriCloud