summaryrefslogtreecommitdiff
path: root/libavcodec/dnxhdenc.c
diff options
context:
space:
mode:
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>2007-10-09 14:15:03 +0000
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>2007-10-09 14:15:03 +0000
commit45b8e9e507b2de2cf7707e3fd1c2aecaa9975012 (patch)
tree387f4ba6bcd9077f17008804a8d45bdca30a172e /libavcodec/dnxhdenc.c
parentd6c52130f75579885a0952fc07633a3955802330 (diff)
downloadffmpeg-45b8e9e507b2de2cf7707e3fd1c2aecaa9975012.tar.gz
better lambda search method
Originally committed as revision 10697 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/dnxhdenc.c')
-rw-r--r--libavcodec/dnxhdenc.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 3daa46b856..dc55ae0ef3 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -573,27 +573,23 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg)
static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
{
- unsigned lambda, up_lambda, down_lambda;
+ int lambda, up_step, down_step;
+ int last_lower = INT_MAX, last_higher = 0;
int x, y, q;
for (q = 1; q < avctx->qmax; q++) {
ctx->qscale = q;
avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count);
}
- up_lambda = avctx->qmax<<LAMBDA_FRAC_BITS;
- down_lambda = 1; // higher ?
+ up_step = down_step = 2<<LAMBDA_FRAC_BITS;
lambda = ctx->lambda;
for (;;) {
int bits = 0;
int end = 0;
- if (lambda == up_lambda) {
- lambda--;
- end = 1; // need to set final qscales/bits
- }
- if (lambda == down_lambda) {
+ if (lambda == last_higher) {
lambda++;
- end = 1;
+ end = 1; // need to set final qscales/bits
}
for (y = 0; y < ctx->m.mb_height; y++) {
for (x = 0; x < ctx->m.mb_width; x++) {
@@ -615,20 +611,35 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
if (bits > ctx->frame_bits)
break;
}
- //dprintf(ctx->m.avctx, "lambda %d, up %d, down %d, bits %d, frame %d\n", lambda, up_lambda, down_lambda, bits, ctx->frame_bits);
+ //dprintf(ctx->m.avctx, "lambda %d, up %u, down %u, bits %d, frame %d\n",
+ // lambda, last_higher, last_lower, bits, ctx->frame_bits);
if (end) {
if (bits > ctx->frame_bits)
return -1;
break;
}
if (bits < ctx->frame_bits) {
- up_lambda = lambda;
- lambda = (down_lambda+lambda)>>1;
+ last_lower = FFMIN(lambda, last_lower);
+ if (last_higher != 0)
+ lambda = (lambda+last_higher)>>1;
+ else
+ lambda -= down_step;
+ down_step *= 5; // XXX tune ?
+ up_step = 1<<LAMBDA_FRAC_BITS;
+ lambda = FFMAX(1, lambda);
+ if (lambda == last_lower)
+ break;
} else {
- down_lambda = lambda;
- lambda = (up_lambda+lambda)>>1;
+ last_higher = FFMAX(lambda, last_higher);
+ if (last_lower != INT_MAX)
+ lambda = (lambda+last_lower)>>1;
+ else
+ lambda += up_step;
+ up_step *= 5;
+ down_step = 1<<LAMBDA_FRAC_BITS;
}
}
+ //dprintf(ctx->m.avctx, "out lambda %d\n", lambda);
ctx->lambda = lambda;
return 0;
}