--- trunk/xvidcore/examples/xvid_encraw.c 2010/03/09 14:56:02 1884 +++ trunk/xvidcore/examples/xvid_encraw.c 2010/12/28 19:19:57 1928 @@ -22,7 +22,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.40 2010-03-09 14:56:02 Isibaar Exp $ + * $Id: xvid_encraw.c,v 1.47 2010-12-28 19:19:43 Isibaar Exp $ * ****************************************************************************/ @@ -189,6 +189,7 @@ static int ARG_CPU_FLAGS = 0; static int ARG_STATS = 0; static int ARG_SSIM = -1; +static int ARG_PSNRHVSM = 0; static char* ARG_SSIM_PATH = NULL; static int ARG_DUMP = 0; static int ARG_LUMIMASKING = 0; @@ -230,6 +231,7 @@ static int ARG_TURBO = 0; static int ARG_VHQMODE = 1; static int ARG_BVHQ = 0; +static int ARG_QMETRIC = 0; static int ARG_CLOSED_GOP = 1; static int ARG_CHROMAME = 1; static int ARG_PAR = 1; @@ -255,6 +257,7 @@ static int ARG_VBVMAXRATE = 0; static int ARG_VBVPEAKRATE = 0; static int ARG_THREADS = 0; +static int ARG_SLICES = 1; static int ARG_VFR = 0; static int ARG_PROGRESS = 0; static int ARG_COLORSPACE = XVID_CSP_YV12; @@ -345,27 +348,6 @@ int use_assembler = 1; int i; -#if defined(XVID_AVI_INPUT) - PAVIFILE avi_in = NULL; - PAVISTREAM avi_in_stream = NULL; - PGETFRAME get_frame = NULL; -#else -#define get_frame NULL -#endif -#if defined(XVID_AVI_OUTPUT) - PAVIFILE myAVIFile = NULL; - PAVISTREAM myAVIStream = NULL; - BITMAPINFOHEADER myBitmapInfoHeader; -#endif -#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) - AVIFileInit(); -#endif -#ifdef XVID_MKV_OUTPUT - PMKVFILE myMKVFile=NULL; - PMKVSTREAM myMKVStream=NULL; - MKVSTREAMINFO myMKVStreamInfo; -#endif - printf("xvid_encraw - raw mpeg4 bitstream encoder "); printf("written by Christoph Lampert\n\n"); @@ -409,8 +391,8 @@ ARG_BITRATE = atoi(argv[i+1]); if (ARG_BITRATE) { i++; - if (ARG_BITRATE <= 10000) - /* if given parameter is <= 10000, assume it means kbps */ + if (ARG_BITRATE <= 20000) + /* if given parameter is <= 20000, assume it means kbps */ ARG_BITRATE *= 1000; } else @@ -466,6 +448,9 @@ } else if (strcmp("-threads", argv[i]) == 0 && i < argc -1) { i++; ARG_THREADS = atoi(argv[i]); + } else if (strcmp("-slices", argv[i]) == 0 && i < argc -1) { + i++; + ARG_SLICES = atoi(argv[i]); } else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) { i++; ARG_BQRATIO = atoi(argv[i]); @@ -500,7 +485,7 @@ memset(&ZONES[NUM_ZONES], 0, sizeof(zone_t)); ZONES[NUM_ZONES].frame = startframe; - ZONES[NUM_ZONES].modifier = atof(options)*100; + ZONES[NUM_ZONES].modifier = (int)atof(options)*100; if (toupper(c)=='Q') ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT; else if (toupper(c)=='W') @@ -513,7 +498,7 @@ if ((frameoptions=strchr(options, ','))!=NULL) { int readchar=0, count; frameoptions++; - while (readchar 1) + CoInitializeEx(0, COINIT_MULTITHREADED); + AVIFileInit(); #endif if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { @@ -1236,9 +1238,6 @@ AVISTREAMINFO avi_info; FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); - if (ARG_NUM_APP_THREADS > 1) - CoInitializeEx(0, COINIT_MULTITHREADED); - if (avi_fp == NULL) { fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); return; @@ -1301,7 +1300,7 @@ temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0); if (temp != NULL) { int i; - for (i = 0; i < ((DWORD*)temp)[0]; i++) { + for (i = 0; i < (int)((DWORD*)temp)[0]; i++) { fprintf(stderr, "%2d ", temp[i]); } fprintf(stderr, "\n"); @@ -1528,7 +1527,7 @@ * Encode and decode this frame ****************************************************************************/ - if ((input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) { + if ((unsigned int)(input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) { stats_type = XVID_TYPE_PVOP; } else @@ -1722,6 +1721,9 @@ if (myMKVStream) MKVStreamRelease(myMKVStream); if (myMKVFile) MKVFileRelease(myMKVFile); #endif +#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) + AVIFileExit(); +#endif free_all_memory: free(out_buffer); @@ -1863,7 +1865,7 @@ fprintf(stderr, "-odegrade integer : max overflow degradation (5)\n"); fprintf(stderr, "-chigh integer : high bitrate scenes degradation (0)\n"); fprintf(stderr, "-clow integer : low bitrate scenes improvement (0)\n"); - fprintf(stderr, "-overhead integer : container frame overhead (24)\n"); + fprintf(stderr, "-overhead integer : container frame overhead (0)\n"); fprintf(stderr, "-vbvsize integer : use vbv buffer size\n"); fprintf(stderr, "-vbvmax integer : vbv max bitrate\n"); fprintf(stderr, "-vbvpeak integer : vbv peak bitrate over 1 second\n"); @@ -1874,6 +1876,7 @@ fprintf(stderr, " -quality integer : quality ([0..%d]) (6)\n", ME_ELEMENTS - 1); fprintf(stderr, " -vhqmode integer : level of R-D optimizations ([0..4]) (1)\n"); fprintf(stderr, " -bvhq : use R-D optimizations for B-frames\n"); + fprintf(stderr, " -metric integer : distortion metric for R-D opt (PSNR:0, PSNRHVSM: 1)\n"); fprintf(stderr, " -qpel : use quarter pixel ME\n"); fprintf(stderr, " -gmc : use global motion compensation\n"); fprintf(stderr, " -qtype integer : quantization type (H263:0, MPEG4:1) (0)\n"); @@ -1885,6 +1888,7 @@ fprintf(stderr, " -stats : print stats about encoded frames\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, " -psnrhvsm : prints PSNRHVSM metric for every frame\n"); fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n"); fprintf(stderr, " -nochromame : Disable chroma motion estimation\n"); @@ -1898,6 +1902,7 @@ fprintf(stderr, " -drop integer : Frame Drop Ratio (0..100) (0)\n"); fprintf(stderr, " -start integer : Starting frame number\n"); fprintf(stderr, " -threads integer : Number of threads\n"); + fprintf(stderr, " -slices integer : Number of slices\n"); fprintf(stderr, " -progress [integer] : Show progress updates every n frames (10)\n"); fprintf(stderr, " -par integer[:integer] : Set Pixel Aspect Ratio.\n"); fprintf(stderr, " 1 = 1:1\n"); @@ -1926,7 +1931,7 @@ int bytes, xsize, ysize, depth; char dummy[2]; - bytes = fread(dummy, 1, 2, handle); + bytes = (int) fread(dummy, 1, 2, handle); if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5')) return (1); @@ -2121,7 +2126,7 @@ xvid_plugin_2pass1_t rc2pass1; xvid_plugin_2pass2_t rc2pass2; xvid_plugin_ssim_t ssim; - xvid_plugin_lumimasking_t masking; + xvid_plugin_lumimasking_t masking; //xvid_plugin_fixed_t rcfixed; xvid_enc_plugin_t plugins[8]; xvid_enc_create_t xvid_enc_create; @@ -2183,7 +2188,7 @@ rc2pass2.vbv_size = ARG_VBVSIZE; rc2pass2.vbv_initial = (ARG_VBVSIZE*3)/4; rc2pass2.vbv_maxrate = ARG_VBVMAXRATE; - rc2pass2.vbv_peakrate = ARG_VBVPEAKRATE*3; + rc2pass2.vbv_peakrate = ARG_VBVPEAKRATE; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; @@ -2250,6 +2255,12 @@ xvid_enc_create.num_plugins++; } + if (ARG_PSNRHVSM>0) { + plugins[xvid_enc_create.num_plugins].func = xvid_plugin_psnrhvsm; + plugins[xvid_enc_create.num_plugins].param = NULL; + xvid_enc_create.num_plugins++; + } + #if 0 if (ARG_DEBUG) { plugins[xvid_enc_create.num_plugins].func = rawenc_debug; @@ -2259,6 +2270,7 @@ #endif xvid_enc_create.num_threads = ARG_THREADS; + xvid_enc_create.num_slices = ARG_SLICES; /* Frame rate */ xvid_enc_create.fincr = ARG_DWSCALE; @@ -2481,6 +2493,9 @@ if (ARG_BVHQ) xvid_enc_frame.vop_flags |= XVID_VOP_RD_BVOP; + if (ARG_QMETRIC == 1) + xvid_enc_frame.vop_flags |= XVID_VOP_RD_PSNRHVSM; + switch (ARG_VHQMODE) /* this is the same code as for vfw */ { case 1: /* VHQ_MODE_DECISION */ @@ -2576,7 +2591,7 @@ ZONES[NUM_ZONES].frame = 0; ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT; - ZONES[NUM_ZONES].modifier = ARG_CQ; + ZONES[NUM_ZONES].modifier = (int)ARG_CQ; ZONES[NUM_ZONES].type = XVID_TYPE_AUTO; ZONES[NUM_ZONES].greyscale = 0; ZONES[NUM_ZONES].chroma_opt = 0; @@ -2592,7 +2607,7 @@ for(i = 0; i < NUM_ZONES; i++) if (ZONES[i].mode == XVID_ZONE_WEIGHT) { ZONES[i].mode = XVID_ZONE_QUANT; - ZONES[i].modifier = (100*ARG_CQ) / ZONES[i].modifier; + ZONES[i].modifier = (int) ((100*ARG_CQ) / ZONES[i].modifier); } } @@ -2661,7 +2676,7 @@ int i; char* userdata; - for (i=0; i <= (bufsize-sizeof(userdata_start_code)); i++) { + for (i=0; i <= (int)(bufsize-sizeof(userdata_start_code)); i++) { if (memcmp((void*)userdata_start_code, (void*)(buf+i), strlen(userdata_start_code))==0) { if ((userdata = strstr(buf+i+4, "DivX"))!=NULL) { userdata[strlen(userdata)-1] = '\0';