[cvs] / xvidcore / examples / xvid_stat.c Repository:
ViewVC logotype

Diff of /xvidcore/examples/xvid_stat.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4.2.2, Sun Feb 9 06:46:54 2003 UTC revision 1.6, Sat Sep 14 23:54:17 2002 UTC
# Line 44  Line 44 
44   *  -q integer     : quality ([0..5])   *  -q integer     : quality ([0..5])
45   *  -d boolean     : save decoder output (0 False*, !=0 True)   *  -d boolean     : save decoder output (0 False*, !=0 True)
46   *  -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)   *  -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)
47   *  -mv integer    : Hinted Motion Estimation (0 none, 1 get hints, 2 set hints)   *  -h, -help      : prints this help message
  *  -help          : prints this help message  
48   *  -quant integer : fixed quantizer (disables -b setting)   *  -quant integer : fixed quantizer (disables -b setting)
49   *  (* means default)   *  (* means default)
50   *   *
# Line 66  Line 65 
65  #include <stdlib.h>  #include <stdlib.h>
66  #include <string.h>  #include <string.h>
67  #include <math.h>  #include <math.h>
 #ifndef WIN32  
 #include <sys/time.h>  
 #else  
68  #include <time.h>  #include <time.h>
 #endif  
69    
70  #include "xvid.h"  #include "../src/xvid.h"
71    
72  /****************************************************************************  /****************************************************************************
73   *                               Prototypes   *                               Prototypes
# Line 100  Line 95 
95  static int enc_init(int use_assembler);  static int enc_init(int use_assembler);
96  static int enc_stop();  static int enc_stop();
97  static int enc_main(unsigned char* image, unsigned char* bitstream,  static int enc_main(unsigned char* image, unsigned char* bitstream,
98                                          unsigned char* hints_buffer,                                          int *streamlength, int* frametype);
                                         long *streamlength, long* frametype, long* hints_size);  
99    
100  /* Decoder related functions */  /* Decoder related functions */
101  static int dec_stop();  static int dec_stop();
# Line 114  Line 108 
108   ****************************************************************************/   ****************************************************************************/
109    
110  static int const motion_presets[7] = {  static int const motion_presets[7] = {
111          0,                                                        /* Q 0 */          0,                                                        // Q 0
112          PMV_EARLYSTOP16,                                          /* Q 1 */          PMV_EARLYSTOP16,                                          // Q 1
113          PMV_EARLYSTOP16,                                          /* Q 2 */          PMV_EARLYSTOP16,                                          // Q 2
114          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    /* Q 3 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    // Q 3
115          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    /* Q 4 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    // Q 4
116          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |  /* Q 5 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |  // Q 5
117          PMV_HALFPELREFINE8,          PMV_HALFPELREFINE8,
118          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | /* Q 6 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | // Q 6
119          PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8          PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8
120  };  };
121    
122  static int const general_presets[7] = {  static int const general_presets[7] = {
123          XVID_H263QUANT,                               /* Q 0 */          XVID_H263QUANT,                               // Q 0
124          XVID_MPEGQUANT,                               /* Q 1 */          XVID_MPEGQUANT,                               // Q 1
125          XVID_H263QUANT,                               /* Q 2 */          XVID_H263QUANT,                               // Q 2
126          XVID_H263QUANT | XVID_HALFPEL,                /* Q 3 */          XVID_H263QUANT | XVID_HALFPEL,                // Q 3
127          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 4 */          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4
128          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 5 */          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5
129          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V  /* Q 6 */          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V  // Q 6
130  };  };
131    
132    
# Line 143  Line 137 
137  /* Maximum number of frames to encode */  /* Maximum number of frames to encode */
138  #define ABS_MAXFRAMENR 9999  #define ABS_MAXFRAMENR 9999
139    
 /* HINTMODEs */  
 #define HINT_MODE_NONE 0  
 #define HINT_MODE_GET  1  
 #define HINT_MODE_SET  2  
 #define HINT_FILE "hints.mv"  
   
140  static int   ARG_BITRATE = 900;  static int   ARG_BITRATE = 900;
141  static int   ARG_QUANTI = 0;  static int   ARG_QUANTI = 0;
142  static int   ARG_QUALITY = 6;  static int   ARG_QUALITY = 6;
# Line 160  Line 148 
148  static int   ARG_INPUTTYPE = 0;  static int   ARG_INPUTTYPE = 0;
149  static int   ARG_SAVEDECOUTPUT = 0;  static int   ARG_SAVEDECOUTPUT = 0;
150  static int   ARG_SAVEMPEGSTREAM = 0;  static int   ARG_SAVEMPEGSTREAM = 0;
 static int   ARG_HINTMODE = HINT_MODE_NONE;  
151  static int   XDIM = 0;  static int   XDIM = 0;
152  static int   YDIM = 0;  static int   YDIM = 0;
 #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)  
153    
154  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
155  #define SMALL_EPS 1e-10  #define SMALL_EPS 1e-10
156    
 #define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \  
                                    (((long)(c))<<8)  |((long)(d)))  
   
 #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \  
                   (((a)&0x00ff0000)>>8)  | (((a)&0xff000000)>>24) )  
   
157  /****************************************************************************  /****************************************************************************
158   *                     Nasty global vars ;-)   *                     Nasty global vars ;-)
159   ***************************************************************************/   ***************************************************************************/
# Line 198  Line 178 
178          unsigned char *divx_buffer = NULL;          unsigned char *divx_buffer = NULL;
179          unsigned char *in_buffer = NULL;          unsigned char *in_buffer = NULL;
180          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
         unsigned char *hints_buffer = NULL;  
181    
182          double enctime,dectime;          double enctime,dectime;
183          double totalenctime=0.;          double totalenctime=0.;
184          double totaldectime=0.;          double totaldectime=0.;
185    
186          long totalsize = 0;          long totalsize = 0;
         long hints_size = 0;  
187          int status;          int status;
         int bigendian = 0;  
188    
189          long m4v_size = 0;          int m4v_size;
190          long frame_type[ABS_MAXFRAMENR];          int frame_type[ABS_MAXFRAMENR];
191          int Iframes=0, Pframes=0, use_assembler=0;          int Iframes=0, Pframes=0, use_assembler=0;
192          double framepsnr[ABS_MAXFRAMENR];          double framepsnr[ABS_MAXFRAMENR];
193    
194          double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;          double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;
195          double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;          double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;
196            double Bpsnr=0.,Bmaxpsnr=0.,Bminpsnr=999.,Bvarpsnr=0.;
197    
198          char filename[256];          char filename[256];
199    
200          FILE *filehandle;          FILE *filehandle;
201          FILE *in_file = stdin;          FILE *in_file = stdin;
         FILE *hints_file = NULL;  
202    
203          printf("xvid_stat - XviD core library test program ");          printf("xvid_stat - XviD core library test program ");
204          printf("written by Christoph Lampert 2002\n\n");          printf("written by Christoph Lampert 2002\n\n");
# Line 279  Line 256 
256                          i++;                          i++;
257                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);
258                  }                  }
259                  else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-h", argv[i]) == 0 || strcmp("-help", argv[i])) {
                         i++;  
                         ARG_HINTMODE = atoi(argv[i]);  
                 }  
                 else if (strcmp("-help", argv[i])) {  
260                          usage();                          usage();
261                          return(0);                          return(0);
262                  }                  }
# Line 298  Line 271 
271   *                            Arguments checking   *                            Arguments checking
272   ****************************************************************************/   ****************************************************************************/
273    
274          if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) {          if ( ARG_INPUTTYPE == 0 &&
275                  fprintf(stderr, "Trying to retreive width and height from PGM header\n");                   ((XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048)) ) {
276                    fprintf(stderr,
277                                    "Wrong frame sizes width=%d height=%d, trying PGM header infos\n",
278                                    XDIM,
279                                    YDIM);
280                  ARG_INPUTTYPE = 1; /* pgm */                  ARG_INPUTTYPE = 1; /* pgm */
281          }          }
282            else {
283                    YDIM = YDIM*3/2; /* YUV */
284            }
285    
286          if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) {          if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) {
287                  fprintf(stderr,"Wrong Quality\n");                  fprintf(stderr,"Wrong Quality\n");
# Line 314  Line 294 
294          }          }
295    
296          if ( ARG_FRAMERATE <= 0) {          if ( ARG_FRAMERATE <= 0) {
297                  fprintf(stderr,"Wrong Framerate %s \n",argv[5]);                  fprintf(stderr,"Wrong Fraterate %s \n",argv[5]);
298                  return -1;                  return -1;
299          }          }
300    
# Line 323  Line 303 
303                  return -1;                  return -1;
304          }          }
305    
         if ( ARG_HINTMODE != HINT_MODE_NONE &&  
                  ARG_HINTMODE != HINT_MODE_GET &&  
                  ARG_HINTMODE != HINT_MODE_SET)  
                 ARG_HINTMODE = HINT_MODE_NONE;  
   
         if( ARG_HINTMODE != HINT_MODE_NONE) {  
                 char *rights = "rb";  
   
                 /*  
                  * If we are getting hints from core, we will have to write them to  
                  * hint file  
                  */  
                 if(ARG_HINTMODE == HINT_MODE_GET)  
                         rights = "w+b";  
   
                 /* Open the hint file */  
                 hints_file = fopen(HINT_FILE, rights);  
                 if(hints_file == NULL) {  
                         fprintf(stderr, "Error opening input file %s\n", HINT_FILE);  
                         return -1;  
                 }  
   
                 /* Allocate hint memory space, we will be using rawhints */  
                 /* NB : Hope 1Mb is enough */  
                 if((hints_buffer = malloc(1024*1024)) == NULL) {  
                         fprintf(stderr, "Memory allocation error\n");  
                         return -1;  
                 }  
   
         }  
   
306          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
307                  in_file = stdin;                  in_file = stdin;
308          }          }
# Line 369  Line 318 
318          if (ARG_INPUTTYPE) {          if (ARG_INPUTTYPE) {
319                  if (read_pgmheader(in_file)) {                  if (read_pgmheader(in_file)) {
320                          fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n");                          fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n");
321                          return -1;                          return -11;
322                  }                  }
323          }          }
324    
325          /* now we know the sizes, so allocate memory */          /* now we know the sizes, so allocate memory */
326    
327          in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM));          in_buffer = (unsigned char *) malloc(XDIM*YDIM);
328          if (!in_buffer)          if (!in_buffer)
329                  goto free_all_memory;                  goto free_all_memory;
330    
331          /* this should really be enough memory ! */          /* this should really be enough memory ! */
332          divx_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*2);          divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2);
333          if (!divx_buffer)          if (!divx_buffer)
334                  goto free_all_memory;                  goto free_all_memory;
335    
336          out_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*4);          /* PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture */
337            YDIM = YDIM*2/3;
338    
339            out_buffer = (unsigned char *) malloc(XDIM*YDIM*4);
340          if (!out_buffer)          if (!out_buffer)
341                  goto free_all_memory;                  goto free_all_memory;
342    
# Line 408  Line 360 
360                  goto release_all;                  goto release_all;
361          }          }
362    
         totalsize = LONG_PACK('M','P','4','U');  
         if(*((char *)(&totalsize)) == 'M')  
                 bigendian = 1;  
         else  
                 bigendian = 0;  
         totalsize = 0;  
363    
364  /*****************************************************************************  /*****************************************************************************
365   *                            Main loop   *                            Main loop
# Line 422  Line 368 
368          do {          do {
369    
370                  if (ARG_INPUTTYPE)                  if (ARG_INPUTTYPE)
371                          status = read_pgmdata(in_file, in_buffer);      /* read PGM data (YUV-format) */                          status = read_pgmdata(in_file, in_buffer);      // read PGM data (YUV-format)
372                  else                  else
373                          status = read_yuvdata(in_file, in_buffer);      /* read raw data (YUV-format) */                          status = read_yuvdata(in_file, in_buffer);      // read raw data (YUV-format)
374    
375                  if (status)                  if (status)
376                  {                  {
# Line 450  Line 396 
396   */   */
397    
398  /*****************************************************************************  /*****************************************************************************
  *                       Read hints from file  
  ****************************************************************************/  
   
                 if(ARG_HINTMODE == HINT_MODE_SET) {  
                         fread(&hints_size, 1, sizeof(long), hints_file);  
                         hints_size = (!bigendian)?SWAP(hints_size):hints_size;  
                         fread(hints_buffer, 1, hints_size, hints_file);  
                 }  
   
 /*****************************************************************************  
399   *                       Encode and decode this frame   *                       Encode and decode this frame
400   ****************************************************************************/   ****************************************************************************/
401    
402                  enctime = msecond();                  enctime = msecond();
403                  status = enc_main(in_buffer, divx_buffer, hints_buffer,                  status = enc_main(in_buffer, divx_buffer, &m4v_size, &frame_type[filenr]);
                                                   &m4v_size, &frame_type[filenr], &hints_size);  
404                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
405    
406                  totalenctime += enctime;                  totalenctime += enctime;
# Line 474  Line 409 
409                  printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6d bytes ",                  printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6d bytes ",
410                             (int)filenr, (int)frame_type[filenr], (float)enctime, (int)m4v_size);                             (int)filenr, (int)frame_type[filenr], (float)enctime, (int)m4v_size);
411    
 /*****************************************************************************  
  *                       Save hints to file  
  ****************************************************************************/  
   
                 if(ARG_HINTMODE == HINT_MODE_GET) {  
                         hints_size = (!bigendian)?SWAP(hints_size):hints_size;  
                         fwrite(&hints_size, 1, sizeof(long), hints_file);  
                         hints_size = (!bigendian)?SWAP(hints_size):hints_size;  
                         fwrite(hints_buffer, 1, hints_size, hints_file);  
                 }  
   
 /*****************************************************************************  
  *                       Save stream to file  
  ****************************************************************************/  
   
412                  if (ARG_SAVEMPEGSTREAM)                  if (ARG_SAVEMPEGSTREAM)
413                  {                  {
414                          sprintf(filename, "%sframe%05d.m4v", filepath, filenr);                          sprintf(filename, "%sframe%05d.m4v", filepath, filenr);
# Line 508  Line 428 
428   *             Analyse the decoded frame and compare to original   *             Analyse the decoded frame and compare to original
429   ****************************************************************************/   ****************************************************************************/
430    
431                  framepsnr[filenr] = PSNR(XDIM,YDIM*3/2, in_buffer, XDIM, out_buffer, XDIM);                  framepsnr[filenr] = PSNR(XDIM,YDIM, in_buffer, XDIM, out_buffer, XDIM );
432    
433                  printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]);                  printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]);
434    
# Line 583  Line 503 
503    
504          /* Print all statistics */          /* Print all statistics */
505          printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));          printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));
506          printf("%04d ",(ARG_QUANTI)?ARG_QUANTI:ARG_BITRATE);          printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE));
507          printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);          printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);
508          printf("size %6d ", (int)totalsize);          printf("size %6d ",totalsize);
509          printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));          printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));
510          printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);          printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);
511          printf("enc: %6.1f fps, dec: %6.1f fps \n",1000/totalenctime, 1000/totaldectime);          printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime);
512          printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr));          printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr));
513          printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr));          printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr));
514          printf("\n");          printf("\n");
# Line 637  Line 557 
557  /* Return time elapsed time in miliseconds since the program started */  /* Return time elapsed time in miliseconds since the program started */
558  static double msecond()  static double msecond()
559  {  {
 #ifndef WIN32  
         struct timeval  tv;  
         gettimeofday(&tv, 0);  
         return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3;  
 #else  
560          clock_t clk;          clock_t clk;
561    
562          clk = clock();          clk = clock();
563    
564          return clk * 1000 / CLOCKS_PER_SEC;          return clk * 1000 / CLOCKS_PER_SEC;
565  #endif  
566  }  }
567    
568    
# Line 717  Line 634 
634          fprintf(stderr, " -q integer     : quality ([0..5])\n");          fprintf(stderr, " -q integer     : quality ([0..5])\n");
635          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");
636          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");
637          fprintf(stderr, " -help          : prints this help message\n");          fprintf(stderr, " -h, -help      : prints this help message\n");
638          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");
639          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
640    
# Line 740  Line 657 
657    
658          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))
659                  return 1;                  return 1;
   
660          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);
661          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )
662          {          {
# Line 750  Line 666 
666          if ( (XDIM==0) || (YDIM==0) )          if ( (XDIM==0) || (YDIM==0) )
667          {          {
668                  XDIM=xsize;                  XDIM=xsize;
669                  YDIM=ysize*2/3;                  YDIM=ysize;
670          }          }
671    
672          return 0;          return 0;
# Line 761  Line 677 
677          int i;          int i;
678          char dummy;          char dummy;
679    
680          unsigned char *y = image;          unsigned char* buff1_ptr2 = image + XDIM*YDIM;
681          unsigned char *u = image + XDIM*YDIM;          unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;
         unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;  
682    
683          /* read Y component of picture */          fread(image,XDIM*YDIM,1, handle);       // read Y component of picture
         fread(y, 1, XDIM*YDIM, handle);  
684    
685          for (i=0;i<YDIM/2;i++)          for (i=0;i<YDIM/2;i++)
686          {          {
687                  /* read U */                  fread(buff1_ptr2,XDIM/2,1,handle);        // read U
688                  fread(u, 1, XDIM/2, handle);                  buff1_ptr2 += XDIM/2;
689                    fread(buff1_ptr3,XDIM/2,1,handle);               // read V
690                  /* read V */                  buff1_ptr3 += XDIM/2;
                 fread(v, 1, XDIM/2, handle);  
   
                 /* Update pointers */  
                 u += XDIM/2;  
                 v += XDIM/2;  
691          }          }
692            fread(&dummy,1,1,handle);       //  I don't know why, but this seems needed
     /*  I don't know why, but this seems needed */  
         fread(&dummy, 1, 1, handle);  
   
693          return 0;          return 0;
694  }  }
695    
696  static int read_yuvdata(FILE* handle, unsigned char *image)  static int read_yuvdata(FILE* handle, unsigned char *image)
697  {  {
698    
699          if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != (unsigned int)IMAGE_SIZE(XDIM, YDIM))          unsigned char* buff1_ptr2 = image + XDIM*YDIM;
700            unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;
701    
702            if (fread(image,XDIM,YDIM*3/2,handle) != (unsigned int)YDIM*3/2)
703                  return 1;                  return 1;
704          else          else
705                  return 0;                  return 0;
# Line 798  Line 707 
707    
708  static int write_pgm(char *filename, unsigned char *image)  static int write_pgm(char *filename, unsigned char *image)
709  {  {
         int loop;  
   
         unsigned char *y = image;  
         unsigned char *u = image + XDIM*YDIM;  
         unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;  
   
710          FILE *filehandle;          FILE *filehandle;
711          filehandle=fopen(filename,"w+b");          filehandle=fopen(filename,"wb");
712          if (filehandle)          if (filehandle)
713          {          {
714                  /* Write header */                  fprintf(filehandle,"P5\n\n");           //
715                  fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2);                  fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2);
716                    fwrite(image, XDIM*YDIM*3/2, 1 ,filehandle);
                 /* Write Y data */  
                 fwrite(y, 1, XDIM*YDIM, filehandle);  
   
                 for(loop=0; loop<YDIM/2; loop++)  
                 {  
                         /* Write U scanline */  
                         fwrite(u, 1, XDIM/2, filehandle);  
   
                         /* Write V scanline */  
                         fwrite(v, 1, XDIM/2, filehandle);  
   
                         /* Update pointers */  
                         u += XDIM/2;  
                         v += XDIM/2;  
   
                 }  
   
                 /* Close file */  
717                  fclose(filehandle);                  fclose(filehandle);
   
718                  return 0;                  return 0;
719          }          }
720          else          else
# Line 881  Line 765 
765      xparam.rc_averaging_period = 100;      xparam.rc_averaging_period = 100;
766      xparam.rc_buffer = 10;      xparam.rc_buffer = 10;
767          xparam.rc_bitrate = ARG_BITRATE*1000;          xparam.rc_bitrate = ARG_BITRATE*1000;
768          xparam.min_quantizer = ARG_MINQUANT;          xparam.min_quantizer = 1;
769          xparam.max_quantizer = ARG_MAXQUANT;          xparam.max_quantizer = 31;
770          xparam.max_key_interval = (int)ARG_FRAMERATE*10;          xparam.max_key_interval = (int)ARG_FRAMERATE*10;
771    
772          /* I use a small value here, since will not encode whole movies, but short clips */          /* I use a small value here, since will not encode whole movies, but short clips */
# Line 903  Line 787 
787  }  }
788    
789  static int enc_main(unsigned char* image, unsigned char* bitstream,  static int enc_main(unsigned char* image, unsigned char* bitstream,
790                                          unsigned char* hints_buffer,                                          int *streamlength, int* frametype)
                                         long *streamlength, long* frametype, long* hints_size)  
791  {  {
792          int xerr;          int xerr;
793    
# Line 912  Line 795 
795          XVID_ENC_STATS xstats;          XVID_ENC_STATS xstats;
796    
797          xframe.bitstream = bitstream;          xframe.bitstream = bitstream;
798          xframe.length = -1;     /* this is written by the routine */          xframe.length = -1;     // this is written by the routine
799    
800          xframe.image = image;          xframe.image = image;
801          xframe.colorspace = XVID_CSP_YV12;      /* defined in <xvid.h> */          xframe.colorspace = XVID_CSP_YV12;      // defined in <xvid.h>
802    
803          xframe.intra = -1; /* let the codec decide between I-frame (1) and P-frame (0) */          xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0)
804    
805          xframe.quant = ARG_QUANTI;      /* is quant != 0, use a fixed quant (and ignore bitrate) */          xframe.quant = ARG_QUANTI;      // is quant != 0, use a fixed quant (and ignore bitrate)
806    
807          xframe.motion = motion_presets[ARG_QUALITY];          xframe.motion = motion_presets[ARG_QUALITY];
808          xframe.general = general_presets[ARG_QUALITY];          xframe.general = general_presets[ARG_QUALITY];
809          xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;          xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;
810    
         xframe.hint.hintstream = hints_buffer;  
   
         if(ARG_HINTMODE == HINT_MODE_SET) {  
                 xframe.hint.hintlength = *hints_size;  
                 xframe.hint.rawhints = 0;  
                 xframe.general |= XVID_HINTEDME_SET;  
         }  
   
         if(ARG_HINTMODE == HINT_MODE_GET) {  
                 xframe.hint.rawhints = 0;  
                 xframe.general |= XVID_HINTEDME_GET;  
         }  
   
811          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);
812    
         if(ARG_HINTMODE == HINT_MODE_GET)  
                 *hints_size = xframe.hint.hintlength;  
   
813          /*          /*
814           * This is statictical data, e.g. for 2-pass. If you are not           * This is statictical data, e.g. for 2-pass. If you are not
815           * interested in any of this, you can use NULL instead of &xstats           * interested in any of this, you can use NULL instead of &xstats
# Line 997  Line 864 
864          xframe.length = m4v_size;          xframe.length = m4v_size;
865          xframe.image = out_buffer;          xframe.image = out_buffer;
866          xframe.stride = XDIM;          xframe.stride = XDIM;
867          xframe.colorspace = XVID_CSP_YV12;             /* XVID_CSP_USER is fastest (no memcopy involved) */          xframe.colorspace = XVID_CSP_YV12;             // XVID_CSP_USER is fastest (no memcopy involved)
868    
869          xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);          xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);
870    

Legend:
Removed from v.1.4.2.2  
changed lines
  Added in v.1.6

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4