Commit 0a2adf0f authored by Rostislav Pehlivanov's avatar Rostislav Pehlivanov

vc2enc: carry over quantization index across frames as a starting point

Previously a global average was used. Using the previous quantizer
resulted in a fairly significant speedup as slice size selection settled
down quicker.
Signed-off-by: 's avatarRostislav Pehlivanov <atomnuker@gmail.com>
parent fc1d3cbf
...@@ -132,7 +132,7 @@ typedef struct VC2EncContext { ...@@ -132,7 +132,7 @@ typedef struct VC2EncContext {
int slice_max_bytes; int slice_max_bytes;
int slice_min_bytes; int slice_min_bytes;
int q_ceil; int q_ceil;
int q_start; int q_avg;
/* Options */ /* Options */
double tolerance; double tolerance;
...@@ -675,7 +675,7 @@ static int rate_control(AVCodecContext *avctx, void *arg) ...@@ -675,7 +675,7 @@ static int rate_control(AVCodecContext *avctx, void *arg)
const int sx = slice_dat->x; const int sx = slice_dat->x;
const int sy = slice_dat->y; const int sy = slice_dat->y;
int bits_last = INT_MAX, quant_buf[2] = {-1, -1}; int bits_last = INT_MAX, quant_buf[2] = {-1, -1};
int quant = s->q_start, range = s->q_start/3; int quant = slice_dat->quant_idx, range = quant/5;
const int top = slice_dat->bits_ceil; const int top = slice_dat->bits_ceil;
const int bottom = slice_dat->bits_floor; const int bottom = slice_dat->bits_floor;
int bits = count_hq_slice(s, slice_dat->cache, &slice_dat->cached_results, int bits = count_hq_slice(s, slice_dat->cache, &slice_dat->cached_results,
...@@ -791,7 +791,7 @@ static int encode_slices(VC2EncContext *s) ...@@ -791,7 +791,7 @@ static int encode_slices(VC2EncContext *s)
for (slice_x = 0; slice_x < s->num_x; slice_x++) { for (slice_x = 0; slice_x < s->num_x; slice_x++) {
SliceArgs *args = &enc_args[s->num_x*slice_y + slice_x]; SliceArgs *args = &enc_args[s->num_x*slice_y + slice_x];
init_put_bits(&args->pb, buf + skip, args->bytes); init_put_bits(&args->pb, buf + skip, args->bytes);
s->q_start = (s->q_start + args->quant_idx)/2; s->q_avg = (s->q_avg + args->quant_idx)/2;
skip += args->bytes; skip += args->bytes;
} }
} }
...@@ -839,8 +839,6 @@ static int encode_slices(VC2EncContext *s) ...@@ -839,8 +839,6 @@ static int encode_slices(VC2EncContext *s)
* of levels. The rest of the areas can be thought as the details needed * of levels. The rest of the areas can be thought as the details needed
* to restore the image perfectly to its original size. * to restore the image perfectly to its original size.
*/ */
static int dwt_plane(AVCodecContext *avctx, void *arg) static int dwt_plane(AVCodecContext *avctx, void *arg)
{ {
TransformArgs *transform_dat = arg; TransformArgs *transform_dat = arg;
...@@ -996,7 +994,7 @@ static av_cold int vc2_encode_end(AVCodecContext *avctx) ...@@ -996,7 +994,7 @@ static av_cold int vc2_encode_end(AVCodecContext *avctx)
int i; int i;
VC2EncContext *s = avctx->priv_data; VC2EncContext *s = avctx->priv_data;
av_log(avctx, AV_LOG_INFO, "Qavg: %i\n", s->q_start); av_log(avctx, AV_LOG_INFO, "Qavg: %i\n", s->q_avg);
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
ff_vc2enc_free_transforms(&s->transform_args[i].t); ff_vc2enc_free_transforms(&s->transform_args[i].t);
...@@ -1031,6 +1029,8 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx) ...@@ -1031,6 +1029,8 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx)
s->base_vf = -1; s->base_vf = -1;
s->strict_compliance = 1; s->strict_compliance = 1;
s->q_avg = 0;
/* Mark unknown as progressive */ /* Mark unknown as progressive */
s->interlaced = !((avctx->field_order == AV_FIELD_UNKNOWN) || s->interlaced = !((avctx->field_order == AV_FIELD_UNKNOWN) ||
(avctx->field_order == AV_FIELD_PROGRESSIVE)); (avctx->field_order == AV_FIELD_PROGRESSIVE));
......
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