--- trunk/xvidcore/examples/xvid_encraw.c 2006/10/11 13:52:06 1729 +++ trunk/xvidcore/examples/xvid_encraw.c 2007/01/09 20:08:53 1769 @@ -21,7 +21,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.28 2006-10-11 13:52:06 Skal Exp $ + * $Id: xvid_encraw.c,v 1.34 2007-01-09 20:08:53 Isibaar Exp $ * ****************************************************************************/ @@ -165,7 +165,7 @@ static frame_stats_t framestats[7]; static int ARG_STATS = 0; -static int ARG_SSIM = 0; +static int ARG_SSIM = -1; static char* ARG_SSIM_PATH = NULL; static int ARG_DUMP = 0; static int ARG_LUMIMASKING = 0; @@ -391,7 +391,17 @@ } else if (strcmp("-h", argv[i]) == 0 && i < argc - 1) { i++; YDIM = atoi(argv[i]); - } else if (strcmp("-bitrate", argv[i]) == 0) { + } else if (strcmp("-csp",argv[i]) == 0 && i < argc - 1) { + i++; + if (strcmp(argv[i],"i420") == 0){ + ARG_COLORSPACE = XVID_CSP_I420; + } else if(strcmp(argv[i],"yv12") == 0){ + ARG_COLORSPACE = XVID_CSP_YV12; + } else { + printf("Invalid colorspace\n"); + return 0; + } + } else if (strcmp("-bitrate", argv[i]) == 0) { if (i < argc - 1) ARG_BITRATE = atoi(argv[i+1]); if (ARG_BITRATE) { @@ -581,7 +591,11 @@ } else if (strcmp("-stats", argv[i]) == 0) { ARG_STATS = 1; } else if (strcmp("-ssim", argv[i]) == 0) { - ARG_SSIM = 1; + ARG_SSIM = 2; + if ((i < argc - 1) && (*argv[i+1] != '-')) { + i++; + ARG_SSIM = atoi(argv[i]); + } } else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) { i++; ARG_SSIM_PATH = argv[i]; @@ -1197,6 +1211,7 @@ framestats[5].size += stats_length; } +#define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height))))) if (ARG_PROGRESS == 0) { printf("%5d: key=%i, time= %6.0f, len= %7d", !result ? input_num : -1, @@ -1204,17 +1219,11 @@ printf(" | type=%s, quant= %2d, len= %7d", type, stats_quant, stats_length); -#define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height))))) if (ARG_STATS) { printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f", - SSE2PSNR(sse[0], XDIM, YDIM), SSE2PSNR(sse[1], XDIM / 2, - YDIM / 2), + 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); } printf("\n"); } else { @@ -1231,8 +1240,13 @@ } } - } + if (ARG_STATS) { + 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); + } #undef SSE2PSNR + } if (m4v_size < 0) break; @@ -1505,6 +1519,7 @@ #endif fprintf(stderr, " -w integer: frame width ([1.2048])\n"); fprintf(stderr, " -h integer: frame height ([1.2048])\n"); + fprintf(stderr, " -csp string : colorspace of raw input file i420, yv12 (default)\n"); fprintf(stderr, " -frames integer: number of frames to encode\n"); fprintf(stderr, "\n"); fprintf(stderr, "Output options:\n"); @@ -1568,7 +1583,7 @@ fprintf(stderr, " -noclosed_gop : Disable closed GOP mode\n"); fprintf(stderr, " -lumimasking : use lumimasking algorithm\n"); fprintf(stderr, " -stats : print stats about encoded frames\n"); - fprintf(stderr, " -ssim : prints the ssim stats for every encoded frame (slow!)\n"); + fprintf(stderr, " -ssim [integer] : prints ssim for every frame (accurate: 0 fast: 4) (2)\n"); fprintf(stderr, " -ssim_file filename : outputs the ssim stats into a file\n"); fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n"); @@ -1903,16 +1918,25 @@ xvid_enc_create.num_plugins++; } -#ifndef WIN32 - if (ARG_SSIM) { + if (ARG_SSIM>=0 || ARG_SSIM_PATH != NULL) { plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim; - ssim.b_printstat = 1; - ssim.stat_path = ARG_SSIM_PATH; + + if( ARG_SSIM >=0){ + ssim.b_printstat = 1; + ssim.acc = ARG_SSIM; + } else { + ssim.b_printstat = 0; + ssim.acc = 2; + } + + if(ARG_SSIM_PATH != NULL){ + ssim.stat_path = ARG_SSIM_PATH; + } + ssim.b_visualize = 0; plugins[xvid_enc_create.num_plugins].param = &ssim; xvid_enc_create.num_plugins++; } -#endif #if 0 if (ARG_DEBUG) { @@ -2052,10 +2076,7 @@ if (image) { xvid_enc_frame.input.plane[0] = image; #ifndef READ_PNM - if (ARG_INPUTTYPE==2) - xvid_enc_frame.input.csp = ARG_COLORSPACE; - else - xvid_enc_frame.input.csp = XVID_CSP_I420; + xvid_enc_frame.input.csp = ARG_COLORSPACE; xvid_enc_frame.input.stride[0] = XDIM; #else xvid_enc_frame.input.csp = XVID_CSP_BGR;