From f28ebbcd415c6b169bd8c27dcd07b328c8fba15f Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Mon, 30 Mar 2015 09:54:22 +0300 Subject: [PATCH] Moved GOP defining to config.c and added parameter --gop * Checking that intra period and gop_len match --- README.md | 1 + src/config.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/encmain.c | 36 +------------------------------- 3 files changed, 58 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 89c095f8..0b85663e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ http://github.com/ultravideo/kvazaar/wiki/List-of-suggested-topics for a list of 0: 64x64, 1: 32x32, 2: 16x16, 3: 8x8 --pu-depth-intra - : Range for sizes of intra prediction units to try. 0: 64x64, 1: 32x32, 2: 16x16, 3: 8x8, 4: 4x4 + --gop : Length of Group of Pictures, must be 8 or 0 [0] Video Usability Information: --sar : Specify Sample Aspect Ratio diff --git a/src/config.c b/src/config.c index 34a9f493..8e7ac6ec 100644 --- a/src/config.c +++ b/src/config.c @@ -88,6 +88,7 @@ int config_init(config_t *cfg) cfg->cqmfile = NULL; cfg->ref_frames = DEFAULT_REF_PIC_COUNT; cfg->seek = 0; + cfg->gop_len = 0; cfg->tiles_width_count = 0; cfg->tiles_height_count = 0; @@ -344,8 +345,13 @@ static int config_parse(config_t *cfg, const char *name, const char *value) cfg->frames = atoi(value); else if OPT("qp") cfg->qp = atoi(value); - else if OPT("period") + else if OPT("period") { cfg->intra_period = atoi(value); + if (cfg->gop_len && cfg->intra_period && cfg->intra_period%cfg->gop_len != 0) { + fprintf(stderr, "Input error: Intra period (%d) not equal to goplen (%d)\n", cfg->intra_period, atoi(value)); + return 0; + } + } else if OPT("vps-period") cfg->vps_period = atoi(value); else if OPT("ref") { @@ -505,6 +511,54 @@ static int config_parse(config_t *cfg, const char *name, const char *value) } } } + else if OPT("gop") { + // ToDo: Defining the whole GOp structure via parameters + + // Check for intra period, must be equal to goplen + if (atoi(value) && cfg->intra_period && cfg->intra_period%atoi(value) != 0) { + fprintf(stderr, "Input error: Intra period (%d) not equal to goplen (%d)\n", cfg->intra_period, atoi(value)); + return 0; + } + + if(atoi(value) == 8) { + // GOP + cfg->gop_len = 8; + cfg->gop[0].poc_offset = 8; cfg->gop[0].qp_offset = 1; cfg->gop[0].layer = 1; cfg->gop[0].qp_factor = 0.442; cfg->gop[0].is_ref = 1; + cfg->gop[0].ref_pos_count = 0; + cfg->gop[0].ref_neg_count = 3; cfg->gop[0].ref_neg[0] = 8; cfg->gop[0].ref_neg[1] = 12; cfg->gop[0].ref_neg[2] = 16; + + cfg->gop[1].poc_offset = 4; cfg->gop[1].qp_offset = 2; cfg->gop[1].layer = 2; cfg->gop[1].qp_factor = 0.3536; cfg->gop[1].is_ref = 1; + cfg->gop[1].ref_neg_count = 2; cfg->gop[1].ref_neg[0] = 4; cfg->gop[1].ref_neg[1] = 8; + cfg->gop[1].ref_pos_count = 1; cfg->gop[1].ref_pos[0] = 4; + + cfg->gop[2].poc_offset = 2; cfg->gop[2].qp_offset = 3; cfg->gop[2].layer = 3; cfg->gop[2].qp_factor = 0.3536; cfg->gop[2].is_ref = 1; + cfg->gop[2].ref_neg_count = 2; cfg->gop[2].ref_neg[0] = 2; cfg->gop[2].ref_neg[1] = 6; + cfg->gop[2].ref_pos_count = 2; cfg->gop[2].ref_pos[0] = 2; cfg->gop[2].ref_pos[1] = 6; + + cfg->gop[3].poc_offset = 1; cfg->gop[3].qp_offset = 4; cfg->gop[3].layer = 4; cfg->gop[3].qp_factor = 0.68; cfg->gop[3].is_ref = 0; + cfg->gop[3].ref_neg_count = 1; cfg->gop[3].ref_neg[0] = 1; + cfg->gop[3].ref_pos_count = 3; cfg->gop[3].ref_pos[0] = 1; cfg->gop[3].ref_pos[1] = 3; cfg->gop[3].ref_pos[2] = 7; + + cfg->gop[4].poc_offset = 3; cfg->gop[4].qp_offset = 4; cfg->gop[4].layer = 4; cfg->gop[4].qp_factor = 0.68; cfg->gop[4].is_ref = 0; + cfg->gop[4].ref_neg_count = 2; cfg->gop[4].ref_neg[0] = 1; cfg->gop[4].ref_neg[1] = 3; + cfg->gop[4].ref_pos_count = 2; cfg->gop[4].ref_pos[0] = 1; cfg->gop[4].ref_pos[1] = 5; + + cfg->gop[5].poc_offset = 6; cfg->gop[5].qp_offset = 3; cfg->gop[5].layer = 3; cfg->gop[5].qp_factor = 0.3536; cfg->gop[5].is_ref = 1; + cfg->gop[5].ref_neg_count = 2; cfg->gop[5].ref_neg[0] = 2; cfg->gop[5].ref_neg[1] = 6; + cfg->gop[5].ref_pos_count = 1; cfg->gop[5].ref_pos[0] = 2; + + cfg->gop[6].poc_offset = 5; cfg->gop[6].qp_offset = 4; cfg->gop[6].layer = 4; cfg->gop[6].qp_factor = 0.68; cfg->gop[6].is_ref = 0; + cfg->gop[6].ref_neg_count = 2; cfg->gop[6].ref_neg[0] = 1; cfg->gop[6].ref_neg[1] = 5; + cfg->gop[6].ref_pos_count = 2; cfg->gop[6].ref_pos[0] = 1; cfg->gop[6].ref_pos[1] = 3; + + cfg->gop[7].poc_offset = 7; cfg->gop[7].qp_offset = 4; cfg->gop[7].layer = 4; cfg->gop[7].qp_factor = 0.68; cfg->gop[7].is_ref = 0; + cfg->gop[7].ref_neg_count = 3; cfg->gop[7].ref_neg[0] = 1; cfg->gop[7].ref_neg[1] = 3; cfg->gop[7].ref_neg[2] = 7; + cfg->gop[7].ref_pos_count = 1; cfg->gop[7].ref_pos[0] = 1; + } else if(atoi(value)) { + fprintf(stderr, "Input error: goplen must be 8\n"); + return 0; + } + } else return 0; #undef OPT @@ -566,6 +620,7 @@ int config_read(config_t *cfg,int argc, char *argv[]) { "cpuid", required_argument, NULL, 0 }, { "pu-depth-inter", required_argument, NULL, 0 }, { "pu-depth-intra", required_argument, NULL, 0 }, + { "gop", required_argument, NULL, 0 }, {0, 0, 0, 0} }; diff --git a/src/encmain.c b/src/encmain.c index 24f60fcb..e6a5000b 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -136,6 +136,7 @@ int main(int argc, char *argv[]) " 0: 64x64, 1: 32x32, 2: 16x16, 3: 8x8\n" " --pu-depth-intra - : Range for sizes of intra prediction units to try.\n" " 0: 64x64, 1: 32x32, 2: 16x16, 3: 8x8, 4: 4x4\n" + " --gop : Length of Group of Pictures, must be 8 or 0 [0]\n" "\n" " Video Usability Information:\n" " --sar : Specify Sample Aspect Ratio\n" @@ -267,41 +268,6 @@ int main(int argc, char *argv[]) goto exit_failure; } - // GOP - cfg->gop_len = 8; - cfg->gop[0].poc_offset = 8; cfg->gop[0].qp_offset = 1; cfg->gop[0].layer = 1; cfg->gop[0].qp_factor = 0.442; cfg->gop[0].is_ref = 1; - cfg->gop[0].ref_pos_count = 0; - cfg->gop[0].ref_neg_count = 3; cfg->gop[0].ref_neg[0] = 8; cfg->gop[0].ref_neg[1] = 12; cfg->gop[0].ref_neg[2] = 16; - - cfg->gop[1].poc_offset = 4; cfg->gop[1].qp_offset = 2; cfg->gop[1].layer = 2; cfg->gop[1].qp_factor = 0.3536; cfg->gop[1].is_ref = 1; - cfg->gop[1].ref_neg_count = 2; cfg->gop[1].ref_neg[0] = 4; cfg->gop[1].ref_neg[1] = 8; - cfg->gop[1].ref_pos_count = 1; cfg->gop[1].ref_pos[0] = 4; - - cfg->gop[2].poc_offset = 2; cfg->gop[2].qp_offset = 3; cfg->gop[2].layer = 3; cfg->gop[2].qp_factor = 0.3536; cfg->gop[2].is_ref = 1; - cfg->gop[2].ref_neg_count = 2; cfg->gop[2].ref_neg[0] = 2; cfg->gop[2].ref_neg[1] = 6; - cfg->gop[2].ref_pos_count = 2; cfg->gop[2].ref_pos[0] = 2; cfg->gop[2].ref_pos[1] = 6; - - cfg->gop[3].poc_offset = 1; cfg->gop[3].qp_offset = 4; cfg->gop[3].layer = 4; cfg->gop[3].qp_factor = 0.68; cfg->gop[3].is_ref = 0; - cfg->gop[3].ref_neg_count = 1; cfg->gop[3].ref_neg[0] = 1; - cfg->gop[3].ref_pos_count = 3; cfg->gop[3].ref_pos[0] = 1; cfg->gop[3].ref_pos[1] = 3; cfg->gop[3].ref_pos[2] = 7; - - cfg->gop[4].poc_offset = 3; cfg->gop[4].qp_offset = 4; cfg->gop[4].layer = 4; cfg->gop[4].qp_factor = 0.68; cfg->gop[4].is_ref = 0; - cfg->gop[4].ref_neg_count = 2; cfg->gop[4].ref_neg[0] = 1; cfg->gop[4].ref_neg[1] = 3; - cfg->gop[4].ref_pos_count = 2; cfg->gop[4].ref_pos[0] = 1; cfg->gop[4].ref_pos[1] = 5; - - cfg->gop[5].poc_offset = 6; cfg->gop[5].qp_offset = 3; cfg->gop[5].layer = 3; cfg->gop[5].qp_factor = 0.3536; cfg->gop[5].is_ref = 1; - cfg->gop[5].ref_neg_count = 2; cfg->gop[5].ref_neg[0] = 2; cfg->gop[5].ref_neg[1] = 6; - cfg->gop[5].ref_pos_count = 1; cfg->gop[5].ref_pos[0] = 2; - - cfg->gop[6].poc_offset = 5; cfg->gop[6].qp_offset = 4; cfg->gop[6].layer = 4; cfg->gop[6].qp_factor = 0.68; cfg->gop[6].is_ref = 0; - cfg->gop[6].ref_neg_count = 2; cfg->gop[6].ref_neg[0] = 1; cfg->gop[6].ref_neg[1] = 5; - cfg->gop[6].ref_pos_count = 2; cfg->gop[6].ref_pos[0] = 1; cfg->gop[6].ref_pos[1] = 3; - - cfg->gop[7].poc_offset = 7; cfg->gop[7].qp_offset = 4; cfg->gop[7].layer = 4; cfg->gop[7].qp_factor = 0.68; cfg->gop[7].is_ref = 0; - cfg->gop[7].ref_neg_count = 3; cfg->gop[7].ref_neg[0] = 1; cfg->gop[7].ref_neg[1] = 3; cfg->gop[7].ref_neg[2] = 7; - cfg->gop[7].ref_pos_count = 1; cfg->gop[7].ref_pos[0] = 1; - - if (!encoder_control_init(&encoder, cfg)) { goto exit_failure; }