diff --git a/src/config.c b/src/config.c index 3c850988..e2535e91 100644 --- a/src/config.c +++ b/src/config.c @@ -53,6 +53,7 @@ int config_init(config *cfg) cfg->width = 320; cfg->height = 240; cfg->qp = 32; + cfg->intra_period = 0; return 1; } @@ -118,6 +119,9 @@ int config_read(config *cfg,int argc, char *argv[]) case 'q': // QP cfg->qp = atoi(argv[arg]); break; + case 'p': // Intra period + cfg->intra_period = atoi(argv[arg]); + break; default: // Unknown command, print error message and ignore fprintf(stderr, "%c is not a known option\r\n", option); diff --git a/src/config.h b/src/config.h index 2adfc8c5..74e09fa9 100644 --- a/src/config.h +++ b/src/config.h @@ -37,6 +37,7 @@ typedef struct char *output; /*!< \brief Pointer to output filename */ char *debug; /*!< \brief Pointer to debug output */ int8_t qp; /*!< \brief Quantization parameter */ + int16_t intra_period; /*!< \brief the period of intra frames in stream */ int32_t frames; /*!< \brief Number of frames to decode */ int32_t width; /*!< \brief frame width */ int32_t height; /*!< \brief frame height */ diff --git a/src/encmain.c b/src/encmain.c index 6aca976f..3c9f9a01 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) if (!config_init(cfg) || !config_read(cfg,argc,argv)) { fprintf(stderr, "/***********************************************/\r\n"); fprintf(stderr, " * HEVC Encoder v. " VERSION_STRING "*\r\n"); - fprintf(stderr, " * Tampere University of Technology 2013 *\r\n"); + fprintf(stderr, " * Tampere University of Technology 2014 *\r\n"); fprintf(stderr, "/***********************************************/\r\n\r\n"); fprintf(stderr, "Usage:\r\n"); @@ -81,6 +81,10 @@ int main(int argc, char *argv[]) fprintf(stderr, "Optional parameters:\r\n"); fprintf(stderr, " -n : number of frames to decode\r\n"); fprintf(stderr, " -q : Quantization Parameter, default 32\r\n"); + fprintf(stderr, " -p : Period of intra pictures, default 0\r\n"); + fprintf(stderr, " 0: only first picture is intra\r\n"); + fprintf(stderr, " 1: all pictures are intra\r\n"); + fprintf(stderr, " 2-N: every Nth picture is intra\r\n"); config_destroy(cfg); return EXIT_FAILURE; @@ -225,6 +229,7 @@ int main(int argc, char *argv[]) MOVE_POINTER(encoder->in.cur_pic->pred_v,encoder->ref->pics[0]->pred_v); encoder->frame++; + encoder->poc++; } // Coding finished fgetpos(output,(fpos_t*)&curpos); diff --git a/src/encoder.c b/src/encoder.c index f3575add..19543735 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -280,8 +280,15 @@ void init_encoder_input(encoder_input *input, FILE *inputfile, void encode_one_frame(encoder_control* encoder) { - // output parameters before first frame - if (encoder->frame == 0) { + /** IDR picture when: period == 0 and frame == 0 + * period == 1 && frame%2 == 0 + * period != 0 && frame%period == 0 + **/ + if ( (encoder->cfg->intra_period == 0 && encoder->frame == 0) || + (encoder->cfg->intra_period && encoder->frame % encoder->cfg->intra_period == 0 && + (encoder->cfg->intra_period != 1 || encoder->frame % 2 == 0 ) ) ) { + encoder->poc = 0; + // Video Parameter Set (VPS) encode_vid_parameter_set(encoder); bitstream_align(encoder->stream); @@ -324,7 +331,8 @@ void encode_one_frame(encoder_control* encoder) bitstream_clear_buffer(encoder->stream); } else { cabac_start(&cabac); - encoder->in.cur_pic->slicetype = SLICE_P; + // When intra period == 1, all pictures are intra + encoder->in.cur_pic->slicetype = encoder->cfg->intra_period==1 ? SLICE_I : SLICE_P; encoder->in.cur_pic->type = NAL_TRAIL_R; scalinglist_process(); search_slice_data(encoder); @@ -754,7 +762,7 @@ void encode_slice_header(encoder_control* encoder) int j; int ref_negative = 1; int ref_positive = 0; - WRITE_U(encoder->stream, encoder->frame&0xf, 4, "pic_order_cnt_lsb"); + WRITE_U(encoder->stream, encoder->poc&0xf, 4, "pic_order_cnt_lsb"); WRITE_U(encoder->stream, 0, 1, "short_term_ref_pic_set_sps_flag"); WRITE_UE(encoder->stream, ref_negative, "num_negative_pics"); WRITE_UE(encoder->stream, ref_positive, "num_positive_pics"); diff --git a/src/encoder.h b/src/encoder.h index 8d9538d8..84e2a400 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -61,6 +61,7 @@ typedef struct typedef struct { int32_t frame; + int32_t poc; /*!< \brief picture order count */ config *cfg; encoder_input in; encoder_me me;