static unsigned int Log2MaxFrameNum = 12;
static unsigned int Log2MaxPicOrderCntLsb = 8;
+static const struct option longopts[] = {
+ {"qp", required_argument, 0, 1},
+ {"fb", required_argument, 0, 2},
+ {"mode", required_argument, 0, 3},
+ { NULL, 0, NULL, 0}
+};
+
static int
build_packed_pic_buffer(unsigned char **header_buffer);
static void show_help()
{
- printf("Usage: avnenc <width> <height> <input_yuvfile> <output_avcfile> [qp=qpvalue|fb=framebitrate] [mode=0(I frames only)/1(I and P frames)/2(I, P and B frames)\n");
+ printf("Usage: avnenc <width> <height> <input_yuvfile> <output_avcfile> [--qp=qpvalue|--fb=framebitrate] [--mode=0(I frames only)/1(I and P frames)/2(I, P and B frames)\n");
}
static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_param,
va_init_display_args(&argc, argv);
- //TODO may be we should using option analytics library
- if(argc != 5 && argc != 6 && argc != 7) {
+ if(argc < 5) {
show_help();
return -1;
}
picture_width_in_mbs = (picture_width + 15) / 16;
picture_height_in_mbs = (picture_height + 15) / 16;
- if (argc == 6 || argc == 7) {
- qp_value = -1;
- sscanf(argv[5], "qp=%d", &qp_value);
- if ( qp_value == -1 ) {
- frame_bit_rate = -1;
- sscanf(argv[5], "fb=%d", &frame_bit_rate);
- if ( frame_bit_rate == -1 ) {
+ if (argc > 5) {
+ char o;
+
+ optind = 5;
+
+ while ((o = getopt_long_only(argc, argv, "", longopts, NULL)) != -1) {
+ switch (o) {
+ case 1: // qp
+ frame_bit_rate = -1;
+ qp_value = atoi(optarg);
+
+ if (qp_value > 51)
+ qp_value = 51;
+
+ if (qp_value < 0)
+ qp_value = 0;
+
+ break;
+
+ case 2: // fb
+ qp_value = -1;
+ frame_bit_rate = atoi(optarg);
+
+ if (frame_bit_rate <= 0) {
+ show_help();
+
+ return -1;
+ }
+
+ break;
+
+ case 3: // mode
+ mode_value = atoi(optarg);
+
+ if (mode_value == 0)
+ ip_period = 0;
+ else if (mode_value == 1)
+ ip_period = 1;
+ else if (mode_value == 2)
+ /* Hack mechanism before adding the parameter of B-frame number */
+ ip_period = 2;
+ else {
+ printf("mode_value = %d\n", mode_value);
+ show_help();
+ return -1;
+ }
+
+ break;
+
+ default:
show_help();
return -1;
}
- } else if (qp_value > 51) {
- qp_value = 51;
- } else if (qp_value < 0) {
- qp_value = 0;
}
} else
qp_value = 28; //default const QP mode
- if (argc == 7) {
- sscanf(argv[6], "mode=%d", &mode_value);
- if ( mode_value == 0 ) {
- ip_period = 0;
- }
- else if ( mode_value == 1) {
- ip_period = 1;
- }
- else if ( mode_value == 2 ) {
- /* Hack mechanism before adding the parameter of B-frame number */
- ip_period = 3;
- }
- else {
- printf("mode_value=%d\n",mode_value);
- show_help();
- return -1;
- }
- }
-
yuv_fp = fopen(argv[3],"rb");
if ( yuv_fp == NULL){
printf("Can't open input YUV file\n");