Added commandline configuration of intra period (-p <intra_period>)

This commit is contained in:
Marko Viitanen 2014-01-31 10:23:56 +02:00
parent 76f24408b6
commit 5d5fbb8704
5 changed files with 24 additions and 5 deletions

View file

@ -53,6 +53,7 @@ int config_init(config *cfg)
cfg->width = 320; cfg->width = 320;
cfg->height = 240; cfg->height = 240;
cfg->qp = 32; cfg->qp = 32;
cfg->intra_period = 0;
return 1; return 1;
} }
@ -118,6 +119,9 @@ int config_read(config *cfg,int argc, char *argv[])
case 'q': // QP case 'q': // QP
cfg->qp = atoi(argv[arg]); cfg->qp = atoi(argv[arg]);
break; break;
case 'p': // Intra period
cfg->intra_period = atoi(argv[arg]);
break;
default: default:
// Unknown command, print error message and ignore // Unknown command, print error message and ignore
fprintf(stderr, "%c is not a known option\r\n", option); fprintf(stderr, "%c is not a known option\r\n", option);

View file

@ -37,6 +37,7 @@ typedef struct
char *output; /*!< \brief Pointer to output filename */ char *output; /*!< \brief Pointer to output filename */
char *debug; /*!< \brief Pointer to debug output */ char *debug; /*!< \brief Pointer to debug output */
int8_t qp; /*!< \brief Quantization parameter */ 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 frames; /*!< \brief Number of frames to decode */
int32_t width; /*!< \brief frame width */ int32_t width; /*!< \brief frame width */
int32_t height; /*!< \brief frame height */ int32_t height; /*!< \brief frame height */

View file

@ -73,7 +73,7 @@ int main(int argc, char *argv[])
if (!config_init(cfg) || !config_read(cfg,argc,argv)) { if (!config_init(cfg) || !config_read(cfg,argc,argv)) {
fprintf(stderr, "/***********************************************/\r\n"); fprintf(stderr, "/***********************************************/\r\n");
fprintf(stderr, " * HEVC Encoder v. " VERSION_STRING "*\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, "/***********************************************/\r\n\r\n");
fprintf(stderr, "Usage:\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, "Optional parameters:\r\n");
fprintf(stderr, " -n <frames> : number of frames to decode\r\n"); fprintf(stderr, " -n <frames> : number of frames to decode\r\n");
fprintf(stderr, " -q <QP> : Quantization Parameter, default 32\r\n"); fprintf(stderr, " -q <QP> : Quantization Parameter, default 32\r\n");
fprintf(stderr, " -p <intra period> : 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); config_destroy(cfg);
return EXIT_FAILURE; 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); MOVE_POINTER(encoder->in.cur_pic->pred_v,encoder->ref->pics[0]->pred_v);
encoder->frame++; encoder->frame++;
encoder->poc++;
} }
// Coding finished // Coding finished
fgetpos(output,(fpos_t*)&curpos); fgetpos(output,(fpos_t*)&curpos);

View file

@ -280,8 +280,15 @@ void init_encoder_input(encoder_input *input, FILE *inputfile,
void encode_one_frame(encoder_control* encoder) void encode_one_frame(encoder_control* encoder)
{ {
// output parameters before first frame /** IDR picture when: period == 0 and frame == 0
if (encoder->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) // Video Parameter Set (VPS)
encode_vid_parameter_set(encoder); encode_vid_parameter_set(encoder);
bitstream_align(encoder->stream); bitstream_align(encoder->stream);
@ -324,7 +331,8 @@ void encode_one_frame(encoder_control* encoder)
bitstream_clear_buffer(encoder->stream); bitstream_clear_buffer(encoder->stream);
} else { } else {
cabac_start(&cabac); 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; encoder->in.cur_pic->type = NAL_TRAIL_R;
scalinglist_process(); scalinglist_process();
search_slice_data(encoder); search_slice_data(encoder);
@ -754,7 +762,7 @@ void encode_slice_header(encoder_control* encoder)
int j; int j;
int ref_negative = 1; int ref_negative = 1;
int ref_positive = 0; 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_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_negative, "num_negative_pics");
WRITE_UE(encoder->stream, ref_positive, "num_positive_pics"); WRITE_UE(encoder->stream, ref_positive, "num_positive_pics");

View file

@ -61,6 +61,7 @@ typedef struct
typedef struct typedef struct
{ {
int32_t frame; int32_t frame;
int32_t poc; /*!< \brief picture order count */
config *cfg; config *cfg;
encoder_input in; encoder_input in;
encoder_me me; encoder_me me;