[Libva] [PATCH] test/encode/avcenc:modify the command parameters to make it more flexible

Xiang, Haihao haihao.xiang at intel.com
Thu Dec 1 21:53:17 PST 2011


> +	if (argc<9)	{
> +		fprintf(stderr, "You must specify input/output/width/height at least\n");
> +		show_help();
> +	}

'argc >= 9' can't guarantee that input/output/width/height are
specified .

e.g.
./avcenc -i xxx.yuv -o xxx.h264  -h 288  -fps 30

> +
> +	for (i = 1; i < argc; i++) {
> +		if (!strcmp("-help", argv[i])) {
> +			show_help();
> +			continue;
> +		}

Usually long option is '--xxx' or '--xxx=xxx'

> +		if (!strcmp ("-input", argv[i]) || !strcmp ("-i", argv[i])) {
> +			if (++i>=argc) show_help();
> +			yuv_fp = fopen(argv[i],"rb");
> +			continue;
> +		}
> +		if (!strcmp ("-output", argv[i]) || !strcmp ("-o", argv[i])) {
> +			if (++i>=argc) show_help();
> +			avc_fp = fopen(argv[i], "wb");
> +			continue;
> +		}
> +		if (!strcmp ("-cqp", argv[i])) {
> +			if (++i>=argc) show_help();
> +			if (sscanf (argv[i], "%d",&qp_value) != 1)
> +				show_help();
> +			if (qp_value > 51) {
> +				qp_value = 51;
> +			} else if (qp_value < 0) {
> +				qp_value = 0;
> +		    }
> +			frame_bit_rate = -1;
> +			continue;
> +		}
> +		if (!strcmp ("-cbr", argv[i])) {
> +			if (++i>=argc) show_help();
> +			if (sscanf (argv[i], "%d",&frame_bit_rate) != 1)
> +				show_help();
> +			qp_value = -1;
> +			continue;
> +		}
> +		if (!strcmp ("-width", argv[i]) || !strcmp ("-w", argv[i])) {
> +			if (++i>=argc) show_help();
> +			if (sscanf (argv[i], "%d",&picture_width) != 1)
> +				show_help();
> +			continue;
> +		}
> +		if (!strcmp ("-height", argv[i]) || !strcmp ("-h", argv[i])) {
> +			if (++i>=argc) show_help();
> +			if (sscanf (argv[i], "%d",&picture_height) != 1)
> +				show_help();
> +			continue;
> +		}
> +		if (!strcmp("-cavlc", argv[i])) {
> +			use_cavlc = TRUE;
> +			continue;
> +		}
> +		if (!strcmp("-i_frame_only", argv[i])) {
> +			i_frame_only = TRUE;
> +			i_p_frame_only = FALSE;
> +			i_p_b_frame = FALSE;
> +			continue;
> +		}
> +		if (!strcmp("-i_p_frame_only", argv[i])) {
> +			i_frame_only = FALSE;
> +			i_p_frame_only = TRUE;
> +			i_p_b_frame = FALSE;
> +			continue;
> +		}
> +		if (!strcmp("-i_p_b_frame", argv[i])) {
> +			i_frame_only = FALSE;
> +			i_p_frame_only = FALSE;
> +			i_p_b_frame = TRUE;
> +			continue;
> +		}
> +		if (!strcmp ("-fps", argv[i]) || !strcmp ("-f", argv[i])) {
> +			if (++i>=argc) show_help();
> +			if (sscanf (argv[i], "%d",&fps) != 1)
> +				show_help();
> +			continue;
> +		}
> +	}
>  
> -    picture_width = atoi(argv[1]);
> -    picture_height = atoi(argv[2]);
>      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 ) {
> -                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 ) {
> -                i_frame_only = 1;
> -		i_p_frame_only = 0;
> -        }
> -        else if ( mode_value == 1) {
> -		i_frame_only = 0;
> -                i_p_frame_only = 1;
> -        }
> -        else if ( mode_value == 2 ) {
> -		i_frame_only = 0;
> -                i_p_frame_only = 0;
> -        }
> -        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");
>          return -1;
>      }
> +
>      fseek(yuv_fp,0l, SEEK_END);
>      file_size = ftell(yuv_fp);
>      frame_size = picture_width * picture_height +  ((picture_width * picture_height) >> 1) ;
> @@ -1303,7 +1362,7 @@ int main(int argc, char *argv[])
>      frame_number = file_size / frame_size;
>      fseek(yuv_fp, 0l, SEEK_SET);
>  
> -    avc_fp = fopen(argv[4], "wb");	
> +    //avc_fp = fopen(argv[4], "wb");
>      if ( avc_fp == NULL) {
>          fclose(yuv_fp);
>          printf("Can't open output avc file\n");




More information about the Libva mailing list