From 3fbd7ed97fef0d0548859ff14e9119c9bfa51d1d Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Wed, 25 May 2016 14:08:06 +0300 Subject: [PATCH] Add GOP layer weights for lowdelay-P When using ratecontrol with lowdelay-P, this improves BDRate by 1-25%. Strongest effect is when using 4 layers and multiple references. Also allow using 1 or 2 layers with ratecontrol. --- src/encoder.c | 70 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/src/encoder.c b/src/encoder.c index 2f7265fd..aafb3f6f 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -550,31 +550,61 @@ static int encoder_control_init_gop_layer_weights(encoder_control_t * const enco switch (num_layers) { case 0: + case 1: break; + // Use the first layers of the 4-layer weights. + case 2: case 3: + case 4: - // These weights were copied from http://doi.org/10.1109/TIP.2014.2336550 - if (encoder->target_avg_bpp <= 0.05) { - encoder->gop_layer_weights[0] = 30; - encoder->gop_layer_weights[1] = 8; - encoder->gop_layer_weights[2] = 4; - encoder->gop_layer_weights[3] = 1; - } else if (encoder->target_avg_bpp <= 0.1) { - encoder->gop_layer_weights[0] = 25; - encoder->gop_layer_weights[1] = 7; - encoder->gop_layer_weights[2] = 4; - encoder->gop_layer_weights[3] = 1; - } else if (encoder->target_avg_bpp <= 0.2) { - encoder->gop_layer_weights[0] = 20; - encoder->gop_layer_weights[1] = 6; - encoder->gop_layer_weights[2] = 4; - encoder->gop_layer_weights[3] = 1; + if (encoder->cfg->gop_lowdelay) { + // These weights are based on http://doi.org/10.1109/TIP.2014.2336550 + // They are meant for lp-g4d3r4t1 gop, but work ok for others. + if (encoder->target_avg_bpp <= 0.05) { + encoder->gop_layer_weights[0] = 14; + encoder->gop_layer_weights[1] = 3; + encoder->gop_layer_weights[2] = 2; + encoder->gop_layer_weights[3] = 1; + } else if (encoder->target_avg_bpp <= 0.1) { + encoder->gop_layer_weights[0] = 12; + encoder->gop_layer_weights[1] = 3; + encoder->gop_layer_weights[2] = 2; + encoder->gop_layer_weights[3] = 1; + } else if (encoder->target_avg_bpp <= 0.2) { + encoder->gop_layer_weights[0] = 10; + encoder->gop_layer_weights[1] = 3; + encoder->gop_layer_weights[2] = 2; + encoder->gop_layer_weights[3] = 1; + } else { + encoder->gop_layer_weights[0] = 6; + encoder->gop_layer_weights[1] = 3; + encoder->gop_layer_weights[2] = 2; + encoder->gop_layer_weights[3] = 1; + } } else { - encoder->gop_layer_weights[0] = 15; - encoder->gop_layer_weights[1] = 5; - encoder->gop_layer_weights[2] = 4; - encoder->gop_layer_weights[3] = 1; + // These weights are from http://doi.org/10.1109/TIP.2014.2336550 + if (encoder->target_avg_bpp <= 0.05) { + encoder->gop_layer_weights[0] = 30; + encoder->gop_layer_weights[1] = 8; + encoder->gop_layer_weights[2] = 4; + encoder->gop_layer_weights[3] = 1; + } else if (encoder->target_avg_bpp <= 0.1) { + encoder->gop_layer_weights[0] = 25; + encoder->gop_layer_weights[1] = 7; + encoder->gop_layer_weights[2] = 4; + encoder->gop_layer_weights[3] = 1; + } else if (encoder->target_avg_bpp <= 0.2) { + encoder->gop_layer_weights[0] = 20; + encoder->gop_layer_weights[1] = 6; + encoder->gop_layer_weights[2] = 4; + encoder->gop_layer_weights[3] = 1; + } else { + encoder->gop_layer_weights[0] = 15; + encoder->gop_layer_weights[1] = 5; + encoder->gop_layer_weights[2] = 4; + encoder->gop_layer_weights[3] = 1; + } } break;