diff options
author | Claudio Freire <klaussfreire@gmail.com> | 2015-09-23 02:13:56 -0300 |
---|---|---|
committer | Claudio Freire <klaussfreire@gmail.com> | 2015-09-23 02:33:44 -0300 |
commit | 7ec74ae4aaf50507c5da3dfbb7336e15f848b99b (patch) | |
tree | 2ff0ca4d23f852a61fc47c006b3cf2419eb48ba7 /libavcodec/aacpsy.c | |
parent | b01f3ddad31aba45254dfd553447c7952f86fd31 (diff) | |
download | ffmpeg-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.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c index 82b670d49d..af235c758c 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); } } |