Skip to content

Commit 526c8db

Browse files
committed
Merge branch 'intra-bit-allocation'
2 parents e651195 + 931a9ed commit 526c8db

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/cfg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,10 +793,12 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
793793
if (sscanf(value, "%d/%d", &fps_num, &fps_denom) == 2) {
794794
cfg->framerate_num = fps_num;
795795
cfg->framerate_denom = fps_denom;
796+
cfg->framerate = (double)fps_num / fps_denom;
796797
} else {
797798
// Accept decimal notation, making sure not to round 0 to 1.
798799
cfg->framerate_num = (int)(atof(value) * 1000 + 0.49);
799800
cfg->framerate_denom = 1000;
801+
cfg->framerate = atof(value);
800802
}
801803
}
802804
else if OPT("qp")

src/rate_control.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,12 @@ static double pic_allocate_bits(encoder_state_t * const state)
369369
else {
370370
alpha = 0.3;
371371
}
372-
return MIN(MAX(100, alpha*pow(state->frame->icost * 4 / bits, beta)*bits), encoder->cfg.gop_len >= 2 ? 0.85 * state->frame->cur_gop_target_bits : state->frame->cur_gop_target_bits);
372+
373+
double low_limit = (encoder->cfg.rc_algorithm == KVZ_LAMBDA && encoder->cfg.rdo < 2 ? 1.0 : 1.2) * pow(state->encoder_control->cfg.framerate, -0.873) * state->encoder_control->cfg.target_bitrate;
374+
double high_limit = (encoder->cfg.rdo < 2 ? (encoder->cfg.rc_algorithm == KVZ_LAMBDA ? 1.1 : 3.5) : 2.25) * pow(state->encoder_control->cfg.framerate, -0.61) * state->encoder_control->cfg.target_bitrate;
375+
double original_bits = alpha * pow(state->frame->icost * 4 / bits, beta) * bits;
376+
double limited = MIN(MAX(low_limit, original_bits), high_limit);
377+
return limited;
373378
}
374379

375380
if (encoder->cfg.gop_len <= 0) {
@@ -381,7 +386,8 @@ static double pic_allocate_bits(encoder_state_t * const state)
381386
const double pic_target_bits =
382387
state->frame->cur_gop_target_bits * pic_weight - pic_header_bits(state);
383388
// Allocate at least 100 bits for each picture like HM does.
384-
return MAX(100, pic_target_bits);
389+
const double intra_bits = state->frame->is_irap ? (encoder->cfg.rdo < 2 ? 4 : 6) * state->encoder_control->target_avg_bppic : pic_target_bits;
390+
return MAX(MAX(100, pic_target_bits), intra_bits);
385391
}
386392

387393
static int8_t lambda_to_qp(const double lambda)

0 commit comments

Comments
 (0)