diff --git a/src/cfg.c b/src/cfg.c index efc58db9..f286fb99 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -42,6 +42,7 @@ int kvz_config_init(kvz_config *cfg) cfg->framerate_denom = 1; cfg->qp = 22; cfg->intra_qp_offset = 0; + cfg->intra_qp_offset_auto = false; cfg->intra_period = 64; cfg->vps_period = 0; cfg->deblock_enable = 1; @@ -1024,6 +1025,10 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) } else if OPT("intra-qp-offset") { cfg->intra_qp_offset = atoi(value); + if( cfg->intra_qp_offset == 0 && !strcmp( value, "auto" ) ) + { + cfg->intra_qp_offset_auto = true; + } } else if OPT("open-gop") { cfg->open_gop = (bool)atobool(value); diff --git a/src/encoder.c b/src/encoder.c index ffddfe02..b6c49a21 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -243,6 +243,10 @@ encoder_control_t* kvz_encoder_control_init(const kvz_config *const cfg) } } + if( encoder->cfg.intra_qp_offset_auto ) { + encoder->cfg.intra_qp_offset = encoder->cfg.gop_len > 1 ? -kvz_math_ceil_log2( encoder->cfg.gop_len ) + 1 : 0; + } + // Disable GOP and QP offset for all-intra coding if (encoder->cfg.intra_period == 1) { encoder->cfg.gop_len = 0; diff --git a/src/kvazaar.h b/src/kvazaar.h index 8792cbc6..83109559 100644 --- a/src/kvazaar.h +++ b/src/kvazaar.h @@ -387,6 +387,7 @@ typedef struct kvz_config /** \brief Offset to add to QP for intra frames */ int8_t intra_qp_offset; + uint8_t intra_qp_offset_auto; /** \brief Minimum QP that uses CABAC for residual cost instead of a fast estimate. */ int8_t fast_residual_cost_limit;