--- trunk/xvidcore/examples/xvid_stat.c 2002/04/13 22:21:46 119 +++ trunk/xvidcore/examples/xvid_stat.c 2002/09/12 19:18:12 479 @@ -1,22 +1,36 @@ -/************************************************************************** +/***************************************************************************** * - * XVID MPEG-4 VIDEO CODEC - Example for encoding and decoding + * XVID MPEG-4 VIDEO CODEC + * - Console based test application - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright(C) 2002 Christoph Lampert * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is an implementation of a part of one or more MPEG-4 + * Video tools as specified in ISO/IEC 14496-2 standard. Those intending + * to use this software module in hardware or software products are + * advised that its use may infringe existing patents or copyrights, and + * any such use would be at such party's own risk. The original + * developer of this software module and his/her company, and subsequent + * editors and their companies, will have no liability for use of this + * software or modifications or derivatives thereof. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - *************************************************************************/ + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: xvid_stat.c,v 1.5 2002-09-12 19:18:12 chl Exp $ + * + ****************************************************************************/ /************************************************************************ * @@ -65,32 +79,34 @@ #include // needed for log10 #include // only needed for gettimeofday -#include "xvid.h" /* comes with XviD */ +#include "../src/xvid.h" /* comes with XviD */ int motion_presets[7] = { 0, // Q 0 PMV_EARLYSTOP16, // Q 1 PMV_EARLYSTOP16, // Q 2 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 - PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8, // Q 4 - PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5 - | PMV_HALFPELREFINE8, + PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 + PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5 + | PMV_HALFPELREFINE8, PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 // Q 6 | PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 }; int general_presets[7] = { XVID_H263QUANT, /* or use XVID_MPEGQUANT */ // Q 0 - XVID_H263QUANT, // Q 1 - XVID_H263QUANT, // Q 2 + XVID_MPEGQUANT, // Q 1 + XVID_H263QUANT, // Q 2 XVID_H263QUANT | XVID_HALFPEL, // Q 3 XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5 - XVID_H263QUANT |XVID_HALFPEL | XVID_INTER4V }; // Q 6 + XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V }; // Q 6 /* my default values for encoding */ +#define ABS_MAXFRAMENR 9999 // max number of frames + int ARG_BITRATE=900; int ARG_QUANTI=0; @@ -99,11 +115,12 @@ int ARG_MAXQUANT=31; float ARG_FRAMERATE=25.00; +int ARG_MAXFRAMENR=ABS_MAXFRAMENR; + #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) #define SMALL_EPS 1e-10 - /* these are global variables. Not very elegant, but easy, and this is an easy program */ int XDIM=0; @@ -117,8 +134,6 @@ int pgmflag = 0; // a flag, if input is in PGM format, overwritten in init-phase char filepath[256] = "./"; // the path where to save output -#define MAXFILENR 9999 // max number of frames (this should be made into an option!) - void *enc_handle = NULL; // internal structures (handles) for encoding void *dec_handle = NULL; // and decoding @@ -140,7 +155,6 @@ } - double absdistq(int x,int y, unsigned char* buf1, int stride1, unsigned char* buf2, int stride2) /* returns the sum of squared distances (SSD) between two images of dimensions x times y */ { @@ -260,14 +274,24 @@ #define FRAMERATE_INCR 1001 -int enc_init() +int enc_init(int use_assembler) { /* initialize encoder for first use, pass all needed parameters to the codec */ int xerr; XVID_INIT_PARAM xinit; XVID_ENC_PARAM xparam; - xinit.cpu_flags = XVID_CPU_FORCE; + if(use_assembler) + +#ifdef ARCH_IA64 + xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; +#else + xinit.cpu_flags = 0; +#endif + + else + xinit.cpu_flags = XVID_CPU_FORCE; + xvid_init(NULL, 0, &xinit, NULL); xparam.width = XDIM; @@ -282,11 +306,14 @@ xparam.fincr = FRAMERATE_INCR; xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE); } - xparam.bitrate = ARG_BITRATE*1000; + xparam.rc_reaction_delay_factor = 16; + xparam.rc_averaging_period = 100; + xparam.rc_buffer = 10; + xparam.rc_bitrate = ARG_BITRATE*1000; xparam.min_quantizer = 1; xparam.max_quantizer = 31; xparam.max_key_interval = (int)ARG_FRAMERATE*10; - xparam.rc_buffersize = 2; + /* I use a small value here, since will not encode whole movies, but short clips */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); @@ -345,14 +372,24 @@ /* Routines for decoding: init encoder, frame step, release encoder */ /*********************************************************************/ -int dec_init() /* init decoder before first run */ +int dec_init(int use_assembler) /* init decoder before first run */ { int xerr; XVID_INIT_PARAM xinit; XVID_DEC_PARAM xparam; - xinit.cpu_flags = 0; + if(use_assembler) + +#ifdef ARCH_IA64 + xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; +#else + xinit.cpu_flags = 0; +#endif + + else + xinit.cpu_flags = XVID_CPU_FORCE; + xvid_init(NULL, 0, &xinit, NULL); xparam.width = XDIM; xparam.height = YDIM; @@ -407,9 +444,9 @@ int status; int m4v_size; - int frame_type[MAXFILENR]; - int Iframes=0, Pframes=0, Bframes=0; - double framepsnr[MAXFILENR]; + int frame_type[ABS_MAXFRAMENR]; + int Iframes=0, Pframes=0, use_assembler=0; + double framepsnr[ABS_MAXFRAMENR]; double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.; double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.; @@ -424,6 +461,8 @@ { pgmflag = 1; + if (argc==2 && !strcmp(argv[1],"-asm")) + use_assembler = 1; if (argc>=3) { XDIM = atoi(argv[1]); YDIM = atoi(argv[2]); @@ -471,6 +510,13 @@ printf("Framerate %6.3f fps\n",ARG_FRAMERATE); } + if (argc>=7) + { ARG_MAXFRAMENR = atoi(argv[6]); + if ( (ARG_MAXFRAMENR <= 0) ) + { fprintf(stderr,"Wrong number of frames\n"); return -1; } + printf("max. Framenr. %d\n",ARG_MAXFRAMENR); + } + /* now we know the sizes, so allocate memory */ in_buffer = (unsigned char *) malloc(XDIM*YDIM); @@ -493,14 +539,14 @@ /*********************************************************************/ - status = enc_init(); + status = enc_init(use_assembler); if (status) { printf("Encore INIT problem, return value %d\n", status); goto release_all; } - status = dec_init(); + status = dec_init(use_assembler); if (status) { printf("Decore INIT problem, return value %d\n", status); @@ -588,7 +634,7 @@ filenr++; - } while ( (!status) && (filenr Bmaxpsnr) - Bmaxpsnr = framepsnr[i]; - if (framepsnr[i] < Pminpsnr) - Bminpsnr = framepsnr[i]; - Bvarpsnr += (framepsnr[i] - Bpsnr)*(framepsnr[i] - Bpsnr) /Bframes; + default: break; } } printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br")); printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE)); - printf("(%.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE); + printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE); printf("size %6d ",totalsize); - printf("(%4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000)); + printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000)); printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM); printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime); printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr)); printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr)); - if (Bframes) - printf("B(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Bframes,Bpsnr,Bminpsnr,Bmaxpsnr,sqrt(Bvarpsnr/filenr)); printf("\n"); /*********************************************************************/