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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (view) (download)

1 : chl 119 /**************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC - Example for encoding and decoding
4 :     *
5 :     * This program is free software; you can redistribute it and/or modify
6 :     * it under the terms of the GNU General Public License as published by
7 :     * the Free Software Foundation; either version 2 of the License, or
8 :     * (at your option) any later version.
9 :     *
10 :     * This program is distributed in the hope that it will be useful,
11 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :     * GNU General Public License for more details.
14 :     *
15 :     * You should have received a copy of the GNU General Public License
16 :     * along with this program; if not, write to the Free Software
17 :     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 :     *
19 :     *************************************************************************/
20 :    
21 :     /************************************************************************
22 :     *
23 :     * PSNR and Speed test routine for XviD using the XviD-API
24 :     * (C) Christoph Lampert, 2002/04/13
25 :     *
26 :     * A sequence of YUV pics in PGM file format is encoded and decoded
27 :     * The speed is measured and PSNR of decoded picture is calculated.
28 :     *
29 :     * The program is plain C and needs no libraries except for libxvidcore,
30 :     * and maths-lib ,so with UN*X you simply compile by
31 :     *
32 :     * gcc xvid_stat.c -lxvidcore -lm -o xvid_stat
33 :     *
34 :     * Run without or with illegal parameters, then PGM input input is read
35 :     * from stdin.
36 :     *
37 :     * Parameters are: xvid_stat XDIM YDIM QUALITY BITRATE/QUANTIZER FRAMERATE
38 :     *
39 :     * if XDIM or YDIM are illegal (e.g. 0), they are ignored and input is
40 :     * considered to be PGM. Otherwise (X and Y both greater than 0) raw YUV
41 :     * is expected, as e.g. the standard MPEG test-files, like "foreman"
42 :     *
43 :     * 0 <= QUALITY <= 6 (default 5)
44 :     *
45 :     * BITRATE is in kbps (default 900),
46 :     * if BITRATE<32, then value is taken is fixed QUANTIZER
47 :     *
48 :     * FRAMERATE is a float (with or without decimal dot), default is 25.00
49 :     *
50 :     * input/output and m4v-output is saved, if corresponding flags are set
51 :     *
52 :     * PGM input must in a very specific format, see read_pgmheader
53 :     * it can be generated e.g. from MPEG2 by mpeg2dec -o pgmpipe
54 :     *
55 :     ************************************************************************/
56 :    
57 :     /************************************************************************
58 :     *
59 :     * For EXAMPLES how to use this, see the seperate file xvid_stat.examples
60 :     *
61 :     ************************************************************************/
62 :    
63 :     #include <stdio.h>
64 :     #include <stdlib.h>
65 :     #include <math.h> // needed for log10
66 :     #include <sys/time.h> // only needed for gettimeofday
67 :    
68 :     #include "xvid.h" /* comes with XviD */
69 :    
70 :     int motion_presets[7] = {
71 :     0, // Q 0
72 :     PMV_EARLYSTOP16, // Q 1
73 :     PMV_EARLYSTOP16, // Q 2
74 :     PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3
75 : chl 151 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4
76 :     PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5
77 :     | PMV_HALFPELREFINE8,
78 : chl 119 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 // Q 6
79 :     | PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8
80 :     };
81 :    
82 :     int general_presets[7] = {
83 :     XVID_H263QUANT, /* or use XVID_MPEGQUANT */ // Q 0
84 : chl 151 XVID_MPEGQUANT, // Q 1
85 :     XVID_H263QUANT, // Q 2
86 : chl 119 XVID_H263QUANT | XVID_HALFPEL, // Q 3
87 :     XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4
88 :     XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5
89 : chl 151 XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V }; // Q 6
90 : chl 119
91 :    
92 :     /* my default values for encoding */
93 :    
94 : chl 151 #define ABS_MAXFRAMENR 9999 // max number of frames
95 :    
96 : chl 119 int ARG_BITRATE=900;
97 :     int ARG_QUANTI=0;
98 :    
99 :     int ARG_QUALITY =6;
100 :     int ARG_MINQUANT=1;
101 :     int ARG_MAXQUANT=31;
102 :     float ARG_FRAMERATE=25.00;
103 :    
104 : chl 151 int ARG_MAXFRAMENR=ABS_MAXFRAMENR;
105 : chl 119
106 : chl 151
107 : chl 119 #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
108 :     #define SMALL_EPS 1e-10
109 :    
110 :    
111 :     /* these are global variables. Not very elegant, but easy, and this is an easy program */
112 :    
113 :     int XDIM=0;
114 :     int YDIM=0; // will be set when reading first image
115 :     int i,filenr = 0;
116 :    
117 :     int save_m4v_flag = 0; // save MPEG4-bytestream?
118 :     int save_dec_flag = 1; // save decompressed bytestream?
119 :     int save_ref_flag = 0; //
120 :    
121 :     int pgmflag = 0; // a flag, if input is in PGM format, overwritten in init-phase
122 :     char filepath[256] = "./"; // the path where to save output
123 :    
124 :     void *enc_handle = NULL; // internal structures (handles) for encoding
125 :     void *dec_handle = NULL; // and decoding
126 :    
127 :    
128 :     /*********************************************************************/
129 :     /* "statistical" functions */
130 :     /* */
131 :     /* these are not needed for encoding or decoding, but for measuring */
132 :     /* time and quality, there in nothing specific to XviD in these */
133 :     /* */
134 :     /*********************************************************************/
135 :    
136 :     double msecond()
137 :     /* return the current time in seconds(!) */
138 :     {
139 :     struct timeval tv;
140 :     gettimeofday(&tv, 0);
141 :     return tv.tv_sec + tv.tv_usec * 1.0e-6;
142 :     }
143 :    
144 :    
145 :    
146 :     double absdistq(int x,int y, unsigned char* buf1, int stride1, unsigned char* buf2, int stride2)
147 :     /* returns the sum of squared distances (SSD) between two images of dimensions x times y */
148 :     {
149 :     double dist=0.;
150 :     int i,j,val;
151 :    
152 :     for (i=0;i<y;i++)
153 :     {
154 :     val=0;
155 :     for (j=0;j<x;j++)
156 :     val+= ((int)buf1[j]-(int)buf2[j])*((int)buf1[j]-(int)buf2[j]);
157 :    
158 :     dist += (double)val;
159 :     buf1 += stride1;
160 :     buf2 += stride2;
161 :     }
162 :     return dist/(x*y);
163 :     }
164 :    
165 :    
166 :     double PSNR(int x,int y, unsigned char* buf1, int stride1, unsigned char* buf2, int stride2 )
167 :     /* return the PSNR between to images */
168 :     /* this is a logarithmic measure for "quality" from the world of signal processing */
169 :     /* if you don't know what it is, simply accept that higher values are better */
170 :     {
171 :     return 10*(log10(255*255)-log10( absdistq(x, y, buf1, stride1, buf2, stride2) ));
172 :     }
173 :    
174 :    
175 :     /*********************************************************************/
176 :     /* input and output functions */
177 :     /* */
178 :     /* the are small and simple routines to read and write PGM and YUV */
179 :     /* image. It's just for convenience, again nothing specific to XviD */
180 :     /* */
181 :     /*********************************************************************/
182 :    
183 :     int read_pgmheader(FILE* handle)
184 :     {
185 :     int bytes,xsize,ysize,depth;
186 :     char dummy[2];
187 :    
188 :     bytes = fread(dummy,1,2,handle);
189 :    
190 :     if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))
191 :     return 1;
192 :     fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);
193 :     if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )
194 :     {
195 :     fprintf(stderr,"%d %d %d\n",xsize,ysize,depth);
196 :     return 2;
197 :     }
198 :     if ( (XDIM==0) || (YDIM==0) )
199 :     { XDIM=xsize;
200 :     YDIM=ysize;
201 :     }
202 :    
203 :     return 0;
204 :     }
205 :    
206 :     int read_pgmdata(FILE* handle, unsigned char *image)
207 :     {
208 :     int i,status;
209 :     char dummy;
210 :    
211 :     unsigned char* buff1_ptr2 = image + XDIM*YDIM;
212 :     unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;
213 :    
214 :     fread(image,XDIM*YDIM,1,stdin); // read Y component of picture
215 :    
216 :     for (i=0;i<YDIM/2;i++)
217 :     {
218 :     fread(buff1_ptr2,XDIM/2,1,stdin); // read U
219 :     buff1_ptr2 += XDIM/2;
220 :     fread(buff1_ptr3,XDIM/2,1,stdin); // read V
221 :     buff1_ptr3 += XDIM/2;
222 :     }
223 :     fread(&dummy,1,1,handle); // I don't know why, but this seems needed
224 :     return 0;
225 :     }
226 :    
227 :     int read_yuvdata(FILE* handle, unsigned char *image)
228 :     { int i;
229 :     char dummy;
230 :    
231 :     unsigned char* buff1_ptr2 = image + XDIM*YDIM;
232 :     unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;
233 :    
234 :     if (fread(image,XDIM,YDIM*3/2,stdin) != YDIM*3/2)
235 :     return 1;
236 :     else
237 :     return 0;
238 :     }
239 :    
240 :     int write_pgm(char *filename, unsigned char *image)
241 :     {
242 :     FILE *filehandle;
243 :     filehandle=fopen(filename,"wb");
244 :     if (filehandle)
245 :     {
246 :     fprintf(filehandle,"P5\n\n"); //
247 :     fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2);
248 :     fwrite(image,XDIM,YDIM*3/2,filehandle);
249 :     fclose(filehandle);
250 :     return 0;
251 :     }
252 :     else
253 :     return 1;
254 :     }
255 :    
256 :    
257 :    
258 :     /*********************************************************************/
259 :     /* Routines for encoding: init encoder, frame step, release encoder */
260 :     /*********************************************************************/
261 :    
262 :     #define FRAMERATE_INCR 1001
263 :    
264 :    
265 :     int enc_init()
266 :     { /* initialize encoder for first use, pass all needed parameters to the codec */
267 :     int xerr;
268 :    
269 :     XVID_INIT_PARAM xinit;
270 :     XVID_ENC_PARAM xparam;
271 :    
272 :     xinit.cpu_flags = XVID_CPU_FORCE;
273 :     xvid_init(NULL, 0, &xinit, NULL);
274 :    
275 :     xparam.width = XDIM;
276 :     xparam.height = YDIM;
277 :     if ((ARG_FRAMERATE - (int)ARG_FRAMERATE) < SMALL_EPS)
278 :     {
279 :     xparam.fincr = 1;
280 :     xparam.fbase = (int)ARG_FRAMERATE;
281 :     }
282 :     else
283 :     {
284 :     xparam.fincr = FRAMERATE_INCR;
285 :     xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE);
286 :     }
287 : chl 151 xparam.rc_reaction_delay_factor = 16;
288 :     xparam.rc_averaging_period = 100;
289 :     xparam.rc_buffer = 10;
290 :     xparam.rc_bitrate = ARG_BITRATE*1000;
291 : chl 119 xparam.min_quantizer = 1;
292 :     xparam.max_quantizer = 31;
293 :     xparam.max_key_interval = (int)ARG_FRAMERATE*10;
294 : chl 151
295 : chl 119 /* I use a small value here, since will not encode whole movies, but short clips */
296 :    
297 :     xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL);
298 :     enc_handle=xparam.handle;
299 :    
300 :     return xerr;
301 :     }
302 :    
303 :     int enc_stop()
304 :     { int xerr;
305 :    
306 :     xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL);
307 :     return xerr;
308 :     }
309 :    
310 :     int enc_main(unsigned char* image, unsigned char* bitstream, int *streamlength, int* frametype)
311 :     { int xerr;
312 :    
313 :     XVID_ENC_FRAME xframe;
314 :     XVID_ENC_STATS xstats;
315 :    
316 :     xframe.bitstream = bitstream;
317 :     xframe.length = -1; // this is written by the routine
318 :    
319 :     xframe.image = image;
320 :     xframe.colorspace = XVID_CSP_YV12; // defined in <xvid.h>
321 :    
322 :     xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0)
323 :    
324 :     xframe.quant = ARG_QUANTI; // is quant != 0, use a fixed quant (and ignore bitrate)
325 :    
326 :     xframe.motion = motion_presets[ARG_QUALITY];
327 :     xframe.general = general_presets[ARG_QUALITY];
328 :     xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;
329 :    
330 :     xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);
331 :    
332 :     /* enc_result->is_key_frame = xframe.intra;
333 :     enc_result->quantizer = xframe.quant;
334 :     enc_result->total_bits = xframe.length * 8;
335 :     enc_result->motion_bits = xstats.hlength * 8;
336 :     enc_result->texture_bits = enc_result->total_bits - enc_result->motion_bits;
337 :     */
338 :    
339 :     /* This is statictical data, e.g. for 2-pass.
340 :     If you are not interested in any of this, you can use NULL instead of &xstats
341 :     */
342 :     *frametype = xframe.intra;
343 :     *streamlength = xframe.length;
344 :    
345 :     return xerr;
346 :     }
347 :    
348 :    
349 :     /*********************************************************************/
350 :     /* Routines for decoding: init encoder, frame step, release encoder */
351 :     /*********************************************************************/
352 :    
353 :     int dec_init() /* init decoder before first run */
354 :     {
355 :     int xerr;
356 :    
357 :     XVID_INIT_PARAM xinit;
358 :     XVID_DEC_PARAM xparam;
359 :    
360 :     xinit.cpu_flags = 0;
361 :     xvid_init(NULL, 0, &xinit, NULL);
362 :     xparam.width = XDIM;
363 :     xparam.height = YDIM;
364 :    
365 :     xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);
366 :     dec_handle = xparam.handle;
367 :    
368 :     return xerr;
369 :     }
370 :    
371 :     int dec_main(unsigned char *m4v_buffer, unsigned char *out_buffer, int m4v_size)
372 :     { /* decode one frame */
373 :    
374 :     int xerr;
375 :     XVID_DEC_FRAME xframe;
376 :    
377 :     xframe.bitstream = m4v_buffer;
378 :     xframe.length = m4v_size;
379 :     xframe.image = out_buffer;
380 :     xframe.stride = XDIM;
381 :     xframe.colorspace = XVID_CSP_YV12; // XVID_CSP_USER is fastest (no memcopy involved)
382 :    
383 :     xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);
384 :    
385 :     return xerr;
386 :     }
387 :    
388 :     int dec_stop() /* close decoder to release resources */
389 :     {
390 :     int xerr;
391 :     xerr = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);
392 :    
393 :     return xerr;
394 :     }
395 :    
396 :    
397 :     /*********************************************************************/
398 :     /* Main program */
399 :     /*********************************************************************/
400 :    
401 :     int main(int argc, char *argv[])
402 :     {
403 :     unsigned char *divx_buffer = NULL;
404 :     unsigned char *in_buffer = NULL;
405 :     unsigned char *out_buffer = NULL;
406 :    
407 :     double enctime,dectime;
408 :     double totalenctime=0.;
409 :     double totaldectime=0.;
410 :    
411 :     long totalsize=0;
412 :     int status;
413 :    
414 :     int m4v_size;
415 : chl 151 int frame_type[ABS_MAXFRAMENR];
416 : chl 119 int Iframes=0, Pframes=0, Bframes=0;
417 : chl 151 double framepsnr[ABS_MAXFRAMENR];
418 : chl 119
419 :     double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;
420 :     double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;
421 :     double Bpsnr=0.,Bmaxpsnr=0.,Bminpsnr=999.,Bvarpsnr=0.;
422 :    
423 :     char filename[256];
424 :    
425 :     FILE *filehandle;
426 :    
427 :     /* read YUV in pgm format from stdin */
428 :     if (!pgmflag)
429 :     {
430 :     pgmflag = 1;
431 :    
432 :     if (argc>=3)
433 :     { XDIM = atoi(argv[1]);
434 :     YDIM = atoi(argv[2]);
435 :     if ( (XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048) )
436 :     { fprintf(stderr,"Wrong frames size %d %d, trying PGM \n",XDIM, YDIM);
437 :     }
438 :     else
439 :     {
440 :     YDIM = YDIM*3/2; /* for YUV */
441 :     pgmflag = 0;
442 :     }
443 :     }
444 :     }
445 :    
446 :     if (pgmflag)
447 :     { if (read_pgmheader(stdin))
448 :     {
449 :     printf("Wrong input format, I want YUV encapsulated in PGM\n");
450 :     return 1;
451 :     }
452 :     }
453 :     if (argc>=4)
454 :     { ARG_QUALITY = atoi(argv[3]);
455 :     if ( (ARG_QUALITY < 0) || (ARG_QUALITY > 6) )
456 :     { fprintf(stderr,"Wrong Quality\n"); return -1; }
457 :     else
458 :     printf("Quality %d\n",ARG_QUALITY);
459 :     }
460 :     if (argc>=5)
461 :     { ARG_BITRATE = atoi(argv[4]);
462 :     if ( (ARG_BITRATE <= 0) )
463 :     { fprintf(stderr,"Wrong Bitrate\n"); return -1; }
464 :     if ( (ARG_BITRATE <= 32) )
465 :     { ARG_QUANTI = ARG_BITRATE;
466 :     ARG_BITRATE=0;
467 :     printf("Quantizer %d\n",ARG_QUANTI);
468 :     }
469 :     else
470 :     printf("Bitrate %d kbps\n",ARG_BITRATE);
471 :     }
472 :     if (argc>=6)
473 :     { ARG_FRAMERATE = (float)atof(argv[5]);
474 :     if ( (ARG_FRAMERATE <= 0) )
475 :     { fprintf(stderr,"Wrong Fraterate %s \n",argv[5]); return -1; }
476 :     printf("Framerate %6.3f fps\n",ARG_FRAMERATE);
477 :     }
478 :    
479 : chl 151 if (argc>=7)
480 :     { ARG_MAXFRAMENR = atoi(argv[6]);
481 :     if ( (ARG_MAXFRAMENR <= 0) )
482 :     { fprintf(stderr,"Wrong number of frames\n"); return -1; }
483 :     printf("max. Framenr. %d\n",ARG_MAXFRAMENR);
484 :     }
485 :    
486 : chl 119 /* now we know the sizes, so allocate memory */
487 :    
488 :     in_buffer = (unsigned char *) malloc(XDIM*YDIM);
489 :     if (!in_buffer)
490 :     goto free_all_memory; // goto is one of the most underestimated instructions in C !!!
491 :    
492 :     divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); // this should really be enough memory!
493 :     if (!divx_buffer)
494 :     goto free_all_memory;
495 :    
496 :     YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture
497 :    
498 :     out_buffer = (unsigned char *) malloc(XDIM*YDIM*4);
499 :     if (!out_buffer)
500 :     goto free_all_memory;
501 :    
502 :    
503 :     /*********************************************************************/
504 :     /* XviD PART Start */
505 :     /*********************************************************************/
506 :    
507 :    
508 :     status = enc_init();
509 :     if (status)
510 :     {
511 :     printf("Encore INIT problem, return value %d\n", status);
512 :     goto release_all;
513 :     }
514 :    
515 :     status = dec_init();
516 :     if (status)
517 :     {
518 :     printf("Decore INIT problem, return value %d\n", status);
519 :     goto release_all;
520 :     }
521 :    
522 :    
523 :     /*********************************************************************/
524 :     /* Main loop */
525 :     /*********************************************************************/
526 :    
527 :     do
528 :     {
529 :     if (pgmflag)
530 :     status = read_pgmdata(stdin, in_buffer); // read PGM data (YUV-format)
531 :     else
532 :     status = read_yuvdata(stdin, in_buffer); // read raw data (YUV-format)
533 :    
534 :     if (status)
535 :     {
536 :     // Couldn't read image, most likely end-of-file
537 :     continue;
538 :     }
539 :    
540 :    
541 :     if (save_ref_flag)
542 :     {
543 :     sprintf(filename, "%s%05d.pgm", filepath, filenr);
544 :     write_pgm(filename,in_buffer);
545 :     }
546 :    
547 :    
548 :     /*********************************************************************/
549 :     /* analyse this frame before encoding */
550 :     /*********************************************************************/
551 :    
552 :     // nothing is done here at the moment, but you could e.g. create
553 :     // histograms or measure entropy or apply preprocessing filters...
554 :    
555 :     /*********************************************************************/
556 :     /* encode and decode this frame */
557 :     /*********************************************************************/
558 :    
559 :     enctime = -msecond();
560 :     status = enc_main(in_buffer, divx_buffer, &m4v_size, &frame_type[filenr]);
561 :     enctime += msecond();
562 :    
563 :     totalenctime += enctime;
564 :     totalsize += m4v_size;
565 :    
566 :     printf("Frame %5d: intra %d, enctime =%6.1f ms length=%7d bytes ",
567 :     filenr, frame_type[filenr], enctime*1000, m4v_size);
568 :    
569 :     if (save_m4v_flag)
570 :     {
571 :     sprintf(filename, "%sframe%05d.m4v", filepath, filenr);
572 :     filehandle = fopen(filename, "wb");
573 :     fwrite(divx_buffer, m4v_size, 1, filehandle);
574 :     fclose(filehandle);
575 :     }
576 :    
577 :     dectime = -msecond();
578 :     status = dec_main(divx_buffer, out_buffer, m4v_size);
579 :     dectime += msecond();
580 :    
581 :     totaldectime += dectime;
582 :    
583 :    
584 :     /*********************************************************************/
585 :     /* analyse the decoded frame and compare to original */
586 :     /*********************************************************************/
587 :    
588 :     framepsnr[filenr] = PSNR(XDIM,YDIM, in_buffer, XDIM, out_buffer, XDIM );
589 :    
590 :     printf("dectime =%6.1f ms PSNR %5.2f\n",dectime*1000, framepsnr[filenr]);
591 :    
592 :     if (save_dec_flag)
593 :     {
594 :     sprintf(filename, "%sdec%05d.pgm", filepath, filenr);
595 :     write_pgm(filename,out_buffer);
596 :     }
597 :    
598 :     if (pgmflag)
599 :     status = read_pgmheader(stdin); // because if this was the last PGM, stop now
600 :    
601 :     filenr++;
602 :    
603 : chl 151 } while ( (!status) && (filenr<ARG_MAXFRAMENR) );
604 : chl 119
605 :    
606 :    
607 :     /*********************************************************************/
608 :     /* calculate totals and averages for output, print results */
609 :     /*********************************************************************/
610 :    
611 :     totalsize /= filenr;
612 :     totalenctime /= filenr;
613 :     totaldectime /= filenr;
614 :    
615 :     for (i=0;i<filenr;i++)
616 :     {
617 :     switch (frame_type[i])
618 :     {
619 :     case 0:
620 :     Pframes++;
621 :     Ppsnr += framepsnr[i];
622 :     break;
623 :     case 1:
624 :     Iframes++;
625 :     Ipsnr += framepsnr[i];
626 :     break;
627 :     case 2:
628 :     default:
629 :     Bframes++;
630 :     Bpsnr += framepsnr[i];
631 :     break;
632 :     }
633 :     }
634 :    
635 :     if (Pframes)
636 :     Ppsnr /= Pframes;
637 :     if (Iframes)
638 :     Ipsnr /= Iframes;
639 :     if (Bframes)
640 :     Bpsnr /= Bframes;
641 :    
642 :    
643 :     for (i=0;i<filenr;i++) // calculate statistics for every frametype: P,I (and B)
644 :     {
645 :     switch (frame_type[i])
646 :     {
647 :     case 0:
648 :     if (framepsnr[i] > Pmaxpsnr)
649 :     Pmaxpsnr = framepsnr[i];
650 :     if (framepsnr[i] < Pminpsnr)
651 :     Pminpsnr = framepsnr[i];
652 :     Pvarpsnr += (framepsnr[i] - Ppsnr)*(framepsnr[i] - Ppsnr) /Pframes;
653 :     break;
654 :     case 1:
655 :     if (framepsnr[i] > Imaxpsnr)
656 :     Imaxpsnr = framepsnr[i];
657 :     if (framepsnr[i] < Pminpsnr)
658 :     Iminpsnr = framepsnr[i];
659 :     Ivarpsnr += (framepsnr[i] - Ipsnr)*(framepsnr[i] - Ipsnr) /Iframes;
660 :     break;
661 :     case 2:
662 :     if (framepsnr[i] > Bmaxpsnr)
663 :     Bmaxpsnr = framepsnr[i];
664 :     if (framepsnr[i] < Pminpsnr)
665 :     Bminpsnr = framepsnr[i];
666 :     Bvarpsnr += (framepsnr[i] - Bpsnr)*(framepsnr[i] - Bpsnr) /Bframes;
667 :     break;
668 :     }
669 :     }
670 :    
671 :     printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));
672 :     printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE));
673 : chl 151 printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);
674 : chl 119 printf("size %6d ",totalsize);
675 : chl 151 printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));
676 : chl 119 printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);
677 :     printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime);
678 :     printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr));
679 :     printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr));
680 :     if (Bframes)
681 :     printf("B(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Bframes,Bpsnr,Bminpsnr,Bmaxpsnr,sqrt(Bvarpsnr/filenr));
682 :     printf("\n");
683 :    
684 :     /*********************************************************************/
685 :     /* XviD PART Stop */
686 :     /*********************************************************************/
687 :    
688 :     release_all:
689 :    
690 :     if (enc_handle)
691 :     {
692 :     status = enc_stop();
693 :     if (status)
694 :     printf("Encore RELEASE problem return value %d\n", status);
695 :     }
696 :    
697 :     if (dec_handle)
698 :     {
699 :     status = dec_stop();
700 :     if (status)
701 :     printf("Decore RELEASE problem return value %d\n", status);
702 :     }
703 :    
704 :    
705 :     free_all_memory:
706 :     free(out_buffer);
707 :     free(divx_buffer);
708 :     free(in_buffer);
709 :    
710 :     return 0;
711 :     }

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