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

Diff of /trunk/xvidcore/examples/xvid_stat.c

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

revision 483, Sat Sep 14 23:54:17 2002 UTC revision 561, Sat Sep 28 14:53:40 2002 UTC
# Line 19  Line 19 
19   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: xvid_stat.c,v 1.6 2002-09-14 23:54:17 edgomez Exp $   * $Id: xvid_stat.c,v 1.15 2002-09-28 14:53:40 edgomez Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# 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   *  -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 65  Line 65 
65  #include <stdlib.h>  #include <stdlib.h>
66  #include <string.h>  #include <string.h>
67  #include <math.h>  #include <math.h>
68    #ifndef _MSC_VER
69    #include <sys/time.h>
70    #else
71  #include <time.h>  #include <time.h>
72    #endif
73    
74  #include "../src/xvid.h"  #include "xvid.h"
75    
76  /****************************************************************************  /****************************************************************************
77   *                               Prototypes   *                               Prototypes
# Line 150  Line 154 
154  static int   ARG_SAVEMPEGSTREAM = 0;  static int   ARG_SAVEMPEGSTREAM = 0;
155  static int   XDIM = 0;  static int   XDIM = 0;
156  static int   YDIM = 0;  static int   YDIM = 0;
157    #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
158    
159  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
160  #define SMALL_EPS 1e-10  #define SMALL_EPS 1e-10
# Line 193  Line 198 
198    
199          double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;          double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;
200          double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;          double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;
         double Bpsnr=0.,Bmaxpsnr=0.,Bminpsnr=999.,Bvarpsnr=0.;  
201    
202          char filename[256];          char filename[256];
203    
# Line 256  Line 260 
260                          i++;                          i++;
261                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);
262                  }                  }
263                  else if (strcmp("-h", argv[i]) == 0 || strcmp("-help", argv[i])) {                  else if (strcmp("-help", argv[i])) {
264                          usage();                          usage();
265                          return(0);                          return(0);
266                  }                  }
# Line 271  Line 275 
275   *                            Arguments checking   *                            Arguments checking
276   ****************************************************************************/   ****************************************************************************/
277    
278          if ( ARG_INPUTTYPE == 0 &&          if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) {
279                   ((XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048)) ) {                  fprintf(stderr, "Trying to retreive width and height from PGM header\n");
                 fprintf(stderr,  
                                 "Wrong frame sizes width=%d height=%d, trying PGM header infos\n",  
                                 XDIM,  
                                 YDIM);  
280                  ARG_INPUTTYPE = 1; /* pgm */                  ARG_INPUTTYPE = 1; /* pgm */
281          }          }
         else {  
                 YDIM = YDIM*3/2; /* YUV */  
         }  
282    
283          if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) {          if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) {
284                  fprintf(stderr,"Wrong Quality\n");                  fprintf(stderr,"Wrong Quality\n");
# Line 294  Line 291 
291          }          }
292    
293          if ( ARG_FRAMERATE <= 0) {          if ( ARG_FRAMERATE <= 0) {
294                  fprintf(stderr,"Wrong Fraterate %s \n",argv[5]);                  fprintf(stderr,"Wrong Framerate %s \n",argv[5]);
295                  return -1;                  return -1;
296          }          }
297    
# Line 318  Line 315 
315          if (ARG_INPUTTYPE) {          if (ARG_INPUTTYPE) {
316                  if (read_pgmheader(in_file)) {                  if (read_pgmheader(in_file)) {
317                          fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n");                          fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n");
318                          return -11;                          return -1;
319                  }                  }
320          }          }
321    
322          /* now we know the sizes, so allocate memory */          /* now we know the sizes, so allocate memory */
323    
324          in_buffer = (unsigned char *) malloc(XDIM*YDIM);          in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM));
325          if (!in_buffer)          if (!in_buffer)
326                  goto free_all_memory;                  goto free_all_memory;
327    
328          /* this should really be enough memory ! */          /* this should really be enough memory ! */
329          divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2);          divx_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*2);
330          if (!divx_buffer)          if (!divx_buffer)
331                  goto free_all_memory;                  goto free_all_memory;
332    
333          /* PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture */          out_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*4);
         YDIM = YDIM*2/3;  
   
         out_buffer = (unsigned char *) malloc(XDIM*YDIM*4);  
334          if (!out_buffer)          if (!out_buffer)
335                  goto free_all_memory;                  goto free_all_memory;
336    
# Line 428  Line 422 
422   *             Analyse the decoded frame and compare to original   *             Analyse the decoded frame and compare to original
423   ****************************************************************************/   ****************************************************************************/
424    
425                  framepsnr[filenr] = PSNR(XDIM,YDIM, in_buffer, XDIM, out_buffer, XDIM );                  framepsnr[filenr] = PSNR(XDIM,YDIM*3/2, in_buffer, XDIM, out_buffer, XDIM);
426    
427                  printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]);                  printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]);
428    
# Line 503  Line 497 
497    
498          /* Print all statistics */          /* Print all statistics */
499          printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));          printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));
500          printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE));          printf("%04d ",(ARG_QUANTI)?ARG_QUANTI:ARG_BITRATE);
501          printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);          printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);
502          printf("size %6d ",totalsize);          printf("size %6d ", (int)totalsize);
503          printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));          printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));
504          printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);          printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);
505          printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime);          printf("enc: %6.1f fps, dec: %6.1f fps \n",1000/totalenctime, 1000/totaldectime);
506          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));
507          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));
508          printf("\n");          printf("\n");
# Line 557  Line 551 
551  /* Return time elapsed time in miliseconds since the program started */  /* Return time elapsed time in miliseconds since the program started */
552  static double msecond()  static double msecond()
553  {  {
554    #ifndef _MSC_VER
555            struct timeval  tv;
556            gettimeofday(&tv, 0);
557            return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3;
558    #else
559          clock_t clk;          clock_t clk;
   
560          clk = clock();          clk = clock();
   
561          return clk * 1000 / CLOCKS_PER_SEC;          return clk * 1000 / CLOCKS_PER_SEC;
562    #endif
563  }  }
564    
565    
# Line 634  Line 631 
631          fprintf(stderr, " -q integer     : quality ([0..5])\n");          fprintf(stderr, " -q integer     : quality ([0..5])\n");
632          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");
633          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");
634          fprintf(stderr, " -h, -help      : prints this help message\n");          fprintf(stderr, " -help          : prints this help message\n");
635          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");
636          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
637    
# Line 657  Line 654 
654    
655          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))
656                  return 1;                  return 1;
657    
658          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);
659          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )
660          {          {
# Line 666  Line 664 
664          if ( (XDIM==0) || (YDIM==0) )          if ( (XDIM==0) || (YDIM==0) )
665          {          {
666                  XDIM=xsize;                  XDIM=xsize;
667                  YDIM=ysize;                  YDIM=ysize*2/3;
668          }          }
669    
670          return 0;          return 0;
# Line 677  Line 675 
675          int i;          int i;
676          char dummy;          char dummy;
677    
678          unsigned char* buff1_ptr2 = image + XDIM*YDIM;          unsigned char *y = image;
679          unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;          unsigned char *u = image + XDIM*YDIM;
680            unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;
681    
682          fread(image,XDIM*YDIM,1, handle);       // read Y component of picture          /* read Y component of picture */
683            fread(y, 1, XDIM*YDIM, handle);
684    
685          for (i=0;i<YDIM/2;i++)          for (i=0;i<YDIM/2;i++)
686          {          {
687                  fread(buff1_ptr2,XDIM/2,1,handle);        // read U                  /* read U */
688                  buff1_ptr2 += XDIM/2;                  fread(u, 1, XDIM/2, handle);
689                  fread(buff1_ptr3,XDIM/2,1,handle);               // read V  
690                  buff1_ptr3 += XDIM/2;                  /* read V */
691                    fread(v, 1, XDIM/2, handle);
692    
693                    /* Update pointers */
694                    u += XDIM/2;
695                    v += XDIM/2;
696          }          }
697          fread(&dummy,1,1,handle);       //  I don't know why, but this seems needed  
698        /*  I don't know why, but this seems needed */
699            fread(&dummy, 1, 1, handle);
700    
701          return 0;          return 0;
702  }  }
703    
704  static int read_yuvdata(FILE* handle, unsigned char *image)  static int read_yuvdata(FILE* handle, unsigned char *image)
705  {  {
706    
707          unsigned char* buff1_ptr2 = image + XDIM*YDIM;          if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != (unsigned int)IMAGE_SIZE(XDIM, YDIM))
         unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;  
   
         if (fread(image,XDIM,YDIM*3/2,handle) != (unsigned int)YDIM*3/2)  
708                  return 1;                  return 1;
709          else          else
710                  return 0;                  return 0;
# Line 707  Line 712 
712    
713  static int write_pgm(char *filename, unsigned char *image)  static int write_pgm(char *filename, unsigned char *image)
714  {  {
715            int loop;
716    
717            unsigned char *y = image;
718            unsigned char *u = image + XDIM*YDIM;
719            unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;
720    
721          FILE *filehandle;          FILE *filehandle;
722          filehandle=fopen(filename,"wb");          filehandle=fopen(filename,"w+b");
723          if (filehandle)          if (filehandle)
724          {          {
725                  fprintf(filehandle,"P5\n\n");           //                  /* Write header */
726                  fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2);                  fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2);
727                  fwrite(image, XDIM*YDIM*3/2, 1 ,filehandle);  
728                    /* Write Y data */
729                    fwrite(y, 1, XDIM*YDIM, filehandle);
730    
731                    for(loop=0; loop<YDIM/2; loop++)
732                    {
733                            /* Write U scanline */
734                            fwrite(u, 1, XDIM/2, filehandle);
735    
736                            /* Write V scanline */
737                            fwrite(v, 1, XDIM/2, filehandle);
738    
739                            /* Update pointers */
740                            u += XDIM/2;
741                            v += XDIM/2;
742    
743                    }
744    
745                    /* Close file */
746                  fclose(filehandle);                  fclose(filehandle);
747    
748                  return 0;                  return 0;
749          }          }
750          else          else
# Line 765  Line 795 
795      xparam.rc_averaging_period = 100;      xparam.rc_averaging_period = 100;
796      xparam.rc_buffer = 10;      xparam.rc_buffer = 10;
797          xparam.rc_bitrate = ARG_BITRATE*1000;          xparam.rc_bitrate = ARG_BITRATE*1000;
798          xparam.min_quantizer = 1;          xparam.min_quantizer = ARG_MINQUANT;
799          xparam.max_quantizer = 31;          xparam.max_quantizer = ARG_MAXQUANT;
800          xparam.max_key_interval = (int)ARG_FRAMERATE*10;          xparam.max_key_interval = (int)ARG_FRAMERATE*10;
801    
802          /* 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 */

Legend:
Removed from v.483  
changed lines
  Added in v.561

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