[Libva] [PATCH] test/encode/avcenc:modify the command parameters to make it more flexible
Hai Lan
hai.lan at intel.com
Tue Nov 29 14:12:27 PST 2011
Now we can use "avcenc [options]" to use this program
where options are:
-help or -h
-input <filename> or -i <filename>
-output <filename> or -o <filename>
-width <width> or -w <width>
-height <height> or -h <height>
-cqp <qpvalue> :use const qp mode
-cbr <bitrate> :use const bitrate mode
-fps <fps> or -f <fps>
-i_frame_only :use i frames only
-i_p_frame_only :use i and p frames
-i_p_b_frame :use i, p and b frames
-cavlc :use cavlc, default is to use cabac
Signed-off-by: Hai Lan <hai.lan at intel.com>
---
test/encode/avcenc.c | 157 ++++++++++++++++++++++++++++++++++----------------
1 files changed, 108 insertions(+), 49 deletions(-)
diff --git a/test/encode/avcenc.c b/test/encode/avcenc.c
index a4f343f..d354fef 100644
--- a/test/encode/avcenc.c
+++ b/test/encode/avcenc.c
@@ -46,6 +46,9 @@
#define PROFILE_IDC_MAIN 77
#define PROFILE_IDC_HIGH 100
+#define TRUE 1
+#define FALSE 0
+
#define CHECK_VASTATUS(va_status,func) \
if (va_status != VA_STATUS_SUCCESS) { \
fprintf(stderr,"%s:%s (%d) failed,exit\n", __func__, func, __LINE__); \
@@ -66,6 +69,12 @@ static int intra_period = 30;
static int pb_period = 5;
static int frame_bit_rate = -1;
+static int use_cavlc = FALSE;
+static int i_frame_only = FALSE;
+static int i_p_frame_only = TRUE;
+static int i_p_b_frame = FALSE;
+static int fps = 30;
+
#define BR_CBR 0
#define BR_VBR 1
#define BR_CQP 2
@@ -1110,7 +1119,21 @@ static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes,
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");
+ fprintf(stderr, "usage: %s [options]\n", "avcenc");
+ fprintf(stderr, " where options are:\n");
+ fprintf(stderr, " -help or -h\n");
+ fprintf(stderr, " -input <filename> or -i <filename>\n");
+ fprintf(stderr, " -output <filename> or -o <filename>\n");
+ fprintf(stderr, " -width <width> or -w <width>\n");
+ fprintf(stderr, " -height <height> or -h <height>\n");
+ fprintf(stderr, " -cqp <qpvalue>\t:use const qp mode\n");
+ fprintf(stderr, " -cbr <bitrate>\t:use const bitrate mode\n");
+ fprintf(stderr, " -fps <fps> or -f <fps>\n");
+ fprintf(stderr, " -i_frame_only\t\t:use i frames only \n");
+ fprintf(stderr, " -i_p_frame_only\t:use i and p frames\n");
+ fprintf(stderr, " -i_p_b_frame\t\t:use i, p and b frames\n");
+ fprintf(stderr, " -cavlc\t\t:use cavlc, default is to use cabac\n");
+ exit(1);
}
static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_param,
@@ -1194,7 +1217,7 @@ static void avcenc_context_pic_param_init(VAEncPictureParameterBufferH264 *pic_p
pic_param->pic_fields.bits.idr_pic_flag = 0;
pic_param->pic_fields.bits.reference_pic_flag = 0;
- pic_param->pic_fields.bits.entropy_coding_mode_flag = ENTROPY_MODE_CABAC;
+ pic_param->pic_fields.bits.entropy_coding_mode_flag = !use_cavlc;
pic_param->pic_fields.bits.weighted_pred_flag = 0;
pic_param->pic_fields.bits.weighted_bipred_idc = 0;
pic_param->pic_fields.bits.transform_8x8_mode_flag = 1;
@@ -1236,61 +1259,97 @@ int main(int argc, char *argv[])
int mode_value;
struct timeval tpstart,tpend;
float timeuse;
+ int i;
//TODO may be we should using option analytics library
- if(argc != 5 && argc != 6 && argc != 7) {
- show_help();
- return -1;
- }
+ if (argc<9) {
+ fprintf(stderr, "You must specify input/output/width/height at least\n");
+ show_help();
+ }
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp("-help", argv[i])) {
+ show_help();
+ continue;
+ }
+ 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");
--
1.7.4.1
More information about the Libva
mailing list