--- branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/03/26 14:56:49 949 +++ branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/04/27 19:53:09 996 @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_encraw.c,v 1.11.2.14 2003-03-26 14:56:09 edgomez Exp $ + * $Id: xvid_encraw.c,v 1.11.2.19 2003-04-27 19:53:09 chl Exp $ * ****************************************************************************/ @@ -52,32 +52,35 @@ ****************************************************************************/ static xvid_motion_t const motion_presets[] = { - 0, - XVID_ME_HALFPELREFINE16, - XVID_ME_HALFPELREFINE16, - XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8, + 0, /* 0 */ + XVID_ME_HALFPELREFINE16, /* 1 */ + XVID_ME_HALFPELREFINE16, /* 2 */ + XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8, /* 3 */ + XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8, /* 4 */ XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH16 | - XVID_ME_USESQUARES16, + XVID_ME_USESQUARES16, /* 5 */ XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH16 | - XVID_ME_USESQUARES16 | XVID_ME_CHROMA16 | XVID_ME_CHROMA8, + XVID_ME_USESQUARES16 | XVID_ME_CHROMA16 | XVID_ME_CHROMA8, /* 6 */ }; static xvid_vol_t const vol_presets[] = { - XVID_VOL_MPEGQUANT, - 0, - 0, - XVID_VOL_QUARTERPEL, - XVID_VOL_QUARTERPEL | XVID_VOL_GMC, - 0 + XVID_VOL_MPEGQUANT, /* 0 */ + 0, /* 1 */ + 0, /* 2 */ + 0, /* 3 */ + 0, /* 4 */ + XVID_VOL_QUARTERPEL | XVID_VOL_GMC, /* 5 */ + 0 /* 6 */ }; static xvid_vop_t const vop_presets[] = { - XVID_VOP_DYNAMIC_BFRAMES, - XVID_VOP_DYNAMIC_BFRAMES, - XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL, - XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V, - XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_HQACPRED, - XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_HQACPRED | + XVID_VOP_DYNAMIC_BFRAMES, /* 0 */ + XVID_VOP_DYNAMIC_BFRAMES, /* 1 */ + XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL, /* 2 */ + XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V, /* 3 */ + XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_TRELLISQUANT, /* 4 */ + XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_HQACPRED, /* 5 */ + XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_HQACPRED | /* 6 */ XVID_VOP_MODEDECISION_BITS }; @@ -94,8 +97,9 @@ static int ARG_BITRATE = 0; static char *ARG_PASS1 = 0; static char *ARG_PASS2 = 0; +static int ARG_PASS2_BITRATE = 0; static float ARG_QUANTI = 0.0f; -static int ARG_QUALITY = 5; +static int ARG_QUALITY = 3; static float ARG_FRAMERATE = 25.00f; static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; static char *ARG_INPUTFILE = NULL; @@ -173,6 +177,7 @@ double enctime; double totalenctime = 0.; + float totalPSNR[3] = {0., 0., 0.}; int totalsize; int result; @@ -216,9 +221,9 @@ ARG_PASS1 = argv[i]; } else if (strcmp("-pass2", argv[i]) == 0 && i < argc - 2) { i++; - ARG_PASS1 = argv[i]; - i++; ARG_PASS2 = argv[i]; + i++; + ARG_PASS2_BITRATE = atoi(argv[i]); } else if (strcmp("-max_bframes", argv[i]) == 0 && i < argc - 1) { i++; ARG_MAXBFRAMES = atoi(argv[i]); @@ -281,7 +286,7 @@ ARG_INPUTTYPE = 1; /* pgm */ } - if (ARG_QUALITY < 0 || ARG_QUALITY > 5) { + if (ARG_QUALITY < 0 || ARG_QUALITY > 6) { fprintf(stderr, "Wrong Quality\n"); return (-1); } @@ -393,7 +398,7 @@ /* Write the Frame statistics */ - printf("%5d: key=%i, time=%6.0f, length=%7d", !result ? input_num : -1, + printf("%5d: key=%i, time= %6.0f, length= %7d", !result ? input_num : -1, key, (float) enctime, (int) m4v_size); if (stats_type > 0) { /* !XVID_TYPE_NOTHING */ @@ -416,7 +421,7 @@ break; } - printf(" | type=%s, quant=%2d, length=%7d", type, stats_quant, + printf(" | type=%s, quant= %2d, length= %7d", type, stats_quant, stats_length); #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height))))) @@ -426,6 +431,10 @@ SSE2PSNR(sse[0], XDIM, YDIM), SSE2PSNR(sse[1], XDIM / 2, YDIM / 2), SSE2PSNR(sse[2], XDIM / 2, YDIM / 2)); + + totalPSNR[0] += SSE2PSNR(sse[0], XDIM, YDIM); + totalPSNR[1] += SSE2PSNR(sse[1], XDIM/2, YDIM/2); + totalPSNR[2] += SSE2PSNR(sse[2], XDIM/2, YDIM/2); } } @@ -482,13 +491,21 @@ if (input_num > 0) { totalsize /= input_num; totalenctime /= input_num; + totalPSNR[0] /= input_num; + totalPSNR[1] /= input_num; + totalPSNR[2] /= input_num; } else { totalsize = -1; totalenctime = -1; } - printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n", + printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d, ", totalenctime, 1000 / totalenctime, (int) totalsize); + if (ARG_STATS) { + printf("psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f", + totalPSNR[0],totalPSNR[1],totalPSNR[2]); + } + printf("\n"); /***************************************************************************** @@ -573,8 +590,8 @@ fprintf(stderr, " -framerate float : target framerate (>0 | default=25.0)\n"); fprintf(stderr, " -bitrate integer : bitrate -- for CBR/VBR pass2\n"); fprintf(stderr, " -quant float : quantizer -- for \"Fixed\" quantizer RC\n"); - fprintf(stderr, " -pass1 filename : stats filename\n"); - fprintf(stderr, " -pass2 filename1 filename2 : first pass stats and scaled stats filename\n"); + fprintf(stderr, " -pass1 filename : output stats filename\n"); + fprintf(stderr, " -pass2 filename bitrate : input stats filename, target bitrate\n"); fprintf(stderr, "\n"); fprintf(stderr, "Other options\n"); fprintf(stderr, " -asm : use assembly optmized code\n"); @@ -767,8 +784,8 @@ xvid_enc_create.num_plugins = 0; if (ARG_BITRATE) { - cbr.version = XVID_VERSION; memset(&cbr, 0, sizeof(xvid_plugin_cbr_t)); + cbr.version = XVID_VERSION; cbr.bitrate = ARG_BITRATE; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_cbr; @@ -777,6 +794,7 @@ } if (ARG_QUANTI) { + memset(&rcfixed, 0, sizeof(xvid_plugin_fixed_t)); rcfixed.version = XVID_VERSION; /* We will use a 1/10 precision, just to make sure it works */ rcfixed.quant_base = 10; @@ -787,18 +805,20 @@ xvid_enc_create.num_plugins++; } - if (ARG_PASS1 && ARG_PASS2) { - rc2pass2.version = XVID_VERSION; + if (ARG_PASS2) { memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); - rc2pass2.filename1 = ARG_PASS1; - rc2pass2.filename2 = ARG_PASS2; + rc2pass2.version = XVID_VERSION; + rc2pass2.filename = ARG_PASS2; + rc2pass2.bitrate = ARG_PASS2_BITRATE; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2; xvid_enc_create.num_plugins++; - } else if (ARG_PASS1) { - rc2pass1.version = XVID_VERSION; + } + + if (ARG_PASS1) { memset(&rc2pass1, 0, sizeof(xvid_plugin_2pass1_t)); + rc2pass1.version = XVID_VERSION; rc2pass1.filename = ARG_PASS1; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass1;