[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 479 - (view) (download)

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

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