[svn] / branches / dev-api-4 / xvidcore / examples / xvid_encraw.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/examples/xvid_encraw.c

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

trunk/xvidcore/examples/xvid_encraw.c revision 376, Sat Aug 17 20:03:36 2002 UTC branches/dev-api-4/xvidcore/examples/xvid_encraw.c revision 933, Thu Mar 20 17:59:07 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC - Example for encoding and decoding   *  XVID MPEG-4 VIDEO CODEC
4     *  - Console based test application  -
5     *
6     *  Copyright(C) 2002-2003 Christoph Lampert
7   *   *
8   *      This program is free software; you can redistribute it and/or modify   *      This program is free software; you can redistribute it and/or modify
9   *      it under the terms of the GNU General Public License as published by   *      it under the terms of the GNU General Public License as published by
# Line 14  Line 17 
17   *   *
18   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
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., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   *************************************************************************/   * $Id: xvid_encraw.c,v 1.11.2.10 2003-03-20 17:59:07 edgomez Exp $
   
 /************************************************************************  
23   *   *
24   *  Speed test routine for XviD using the XviD-API   ****************************************************************************/
25   *  (C) Christoph Lampert, 2002/08/17  
26    /*****************************************************************************
27     *  Application notes :
28   *   *
29   *  A sequence of YUV pics in PGM or RAW file format is encoded and the   *  A sequence of raw YUV I420 pics or YUV I420 PGM file format is encoded
30   *  raw MPEG-4 stream is written to stdout.   *  The speed is measured and frames' PSNR are taken from core.
  *  The encoding speed of this is measured, too.  
31   *   *
32   *  The program is plain C and needs no libraries except for libxvidcore,   *  The program is plain C and needs no libraries except for libxvidcore,
33   *  and maths-lib, so with UN*X you simply compile by   *  and maths-lib.
  *  
  *   gcc xvid_encraw.c -lxvidcore -lm -o xvid_encraw  
  *  
  *  Run without or with illegal parameters, then PGM input input is read  
  *  from stdin.  
  *  
  *  Parameters are: xvid_stat XDIM YDIM QUALITY BITRATE/QUANTIZER FRAMERATE  
  *  
  *  if XDIM or YDIM are illegal (e.g. 0), they are ignored and input is  
  *  considered to be PGM. Otherwise (X and Y both greater than 0) raw YUV  
  *  is expected, as e.g. the standard MPEG test-files, like "foreman"  
  *  
  *  0 <= QUALITY <= 6  (default 5)  
  *  
  *  BITRATE is in kbps (default 900),  
  *      if BITRATE<32, then value is taken is fixed QUANTIZER  
  *  
  *  FRAMERATE is a float (with or without decimal dot), default is 25.00  
  *  
  *  input/output and m4v-output is saved, if corresponding flags are set  
  *  
  *  PGM input must in a very specific format, see read_pgmheader  
  *  it can be generated e.g. from MPEG2 by    mpeg2dec -o pgmpipe  
  *  
  ************************************************************************/  
   
 /************************************************************************  
  *  
  *  For EXAMPLES how to use this, see the seperate file xvid_stat.examples  
34   *   *
35   ************************************************************************/   ************************************************************************/
36    
37  #include <stdio.h>  #include <stdio.h>
38  #include <stdlib.h>  #include <stdlib.h>
39  #include <math.h>               // needed for log10  #include <string.h>
40  #include <sys/time.h>           // only needed for gettimeofday  #include <math.h>
41    #ifndef WIN32
42    #include <sys/time.h>
43    #else
44    #include <time.h>
45    #endif
46    
47    #include "xvid.h"
48    
 #include "../src/xvid.h"                /* comes with XviD */  
49    
50  int motion_presets[7] = {  /*****************************************************************************
51          0,                                                              // Q 0   *                            Quality presets
52          PMV_EARLYSTOP16,                                                // Q 1   ****************************************************************************/
53          PMV_EARLYSTOP16,                                                // Q 2  
54          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                          // Q 3  static xvid_motion_t const motion_presets[] = {
55          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                          // Q 4          0,
56          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8          // Q 5          PMV_HALFPELREFINE16,
57                          | PMV_HALFPELREFINE8,          PMV_HALFPELREFINE16,
58          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16         // Q 6          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8,
59                          | PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16,
60            PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16 | PMV_CHROMA16 | PMV_CHROMA8,
61          };          };
62    
63  int general_presets[7] = {  static xvid_vol_t const vol_presets[] = {
64          XVID_H263QUANT, /* or use XVID_MPEGQUANT */             // Q 0          XVID_MPEGQUANT,
65          XVID_MPEGQUANT,                                         // Q 1          0,
66          XVID_H263QUANT,                                // Q 2          0,
67          XVID_H263QUANT | XVID_HALFPEL,                          // Q 3          XVID_QUARTERPEL,
68          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V,           // Q 4          XVID_QUARTERPEL | XVID_GMC,
69          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V,           // Q 5          0
70          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V };         // Q 6  };
71    
72    static xvid_vop_t const vop_presets[] = {
73            XVID_DYNAMIC_BFRAMES,
74            XVID_DYNAMIC_BFRAMES,
75            XVID_DYNAMIC_BFRAMES | XVID_HALFPEL,
76            XVID_DYNAMIC_BFRAMES | XVID_HALFPEL | XVID_INTER4V,
77            XVID_DYNAMIC_BFRAMES | XVID_HALFPEL | XVID_INTER4V | XVID_HQACPRED,
78            XVID_DYNAMIC_BFRAMES | XVID_HALFPEL | XVID_HQACPRED | XVID_MODEDECISION_BITS
79    };
80    
81    /*****************************************************************************
82     *                     Command line global variables
83     ****************************************************************************/
84    
85    /* Maximum number of frames to encode */
86    #define ABS_MAXFRAMENR 9999
87    
88    static int ARG_STATS = 0;
89    static int ARG_DUMP = 0;
90    static int ARG_LUMIMASKING = 0;
91    static int ARG_BITRATE = 900;
92    static int ARG_QUANTI = 0;
93    static int ARG_QUALITY = 5;
94    static float ARG_FRAMERATE = 25.00f;
95    static int ARG_MAXFRAMENR = ABS_MAXFRAMENR;
96    static char *ARG_INPUTFILE = NULL;
97    static int ARG_INPUTTYPE = 0;
98    static int ARG_SAVEMPEGSTREAM = 0;
99    static char *ARG_OUTPUTFILE = NULL;
100    static int XDIM = 0;
101    static int YDIM = 0;
102    static int ARG_BQRATIO = 150;
103    static int ARG_BQOFFSET = 100;
104    static int ARG_MAXBFRAMES = 0;
105    static int ARG_PACKED = 0;
106    static int ARG_DEBUG = 0;
107    
108  /* my default values for encoding */  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
109    
110  #define ABS_MAXFRAMENR 9999               // max number of frames  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
111    #define SMALL_EPS (1e-10)
112    
113  int ARG_BITRATE=900;  #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \
114  int ARG_QUANTI=0;                    (((a)&0x00ff0000)>>8)  | (((a)&0xff000000)>>24) )
115    
116  int ARG_QUALITY =6;  /****************************************************************************
117  int ARG_MINQUANT=1;   *                     Nasty global vars ;-)
118  int ARG_MAXQUANT=31;   ***************************************************************************/
 float ARG_FRAMERATE=25.00;  
119    
120  int ARG_MAXFRAMENR=ABS_MAXFRAMENR;  static int i;
121    
122  #ifdef BFRAMES  /* the path where to save output */
123    static char filepath[256] = "./";
124    
125  int ARG_MAXBFRAMES=1;  /* Internal structures (handles) for encoding and decoding */
126  int ARG_BQUANTRATIO=200;  static void *enc_handle = NULL;
127    
128  #endif  /*****************************************************************************
129     *               Local prototypes
130     ****************************************************************************/
131    
132  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )  /* Prints program usage message */
133  #define SMALL_EPS 1e-10  static void usage();
134    
135  /* these are global variables. Not very elegant, but easy, and this is an easy program */  /* Statistical functions */
136    static double msecond();
137    
138  int XDIM=0;  /* PGM related functions */
139  int YDIM=0;     // will be set when reading first image  static int read_pgmheader(FILE * handle);
140  int i,filenr = 0;  static int read_pgmdata(FILE * handle,
141                                                    unsigned char *image);
142    static int read_yuvdata(FILE * handle,
143                                                    unsigned char *image);
144    
145  int save_m4v_flag = 1;          // output MPEG4-bytestream?  /* Encoder related functions */
146  int save_ref_flag = 0;          // save input image  static int enc_init(int use_assembler);
147    static int enc_stop();
148    static int enc_main(unsigned char *image,
149                                            unsigned char *bitstream,
150                                            int *key,
151                                            int *stats_type,
152                                            int *stats_quant,
153                                            int *stats_length,
154                                            int stats[3]);
155    
156  int pgmflag = 0;                // a flag, if input is in PGM format, overwritten in init-phase  /*****************************************************************************
157  char filepath[256] = "./";      // the path where to save output   *               Main function
158     ****************************************************************************/
159    
160  void *enc_handle = NULL;                // internal structures (handles) for encoding  int
161    main(int argc,
162             char *argv[])
163    {
164    
165            unsigned char *mp4_buffer = NULL;
166            unsigned char *in_buffer = NULL;
167            unsigned char *out_buffer = NULL;
168    
169  /*********************************************************************/          double enctime;
170  /*                     "statistical" functions                       */          double totalenctime = 0.;
 /*                                                                   */  
 /*  these are not needed for encoding or decoding, but for measuring */  
 /*  time and quality, there in nothing specific to XviD in these     */  
 /*                                                                   */  
 /*********************************************************************/  
171    
172  double msecond()          int totalsize;
173  /* return the current time in seconds(!)  */          int result;
174  {          int m4v_size;
175          struct timeval  tv;          int key;
176          gettimeofday(&tv, 0);          int stats_type;
177          return tv.tv_sec + tv.tv_usec * 1.0e-6;          int stats_quant;
178  }          int stats_length;
179            int use_assembler = 0;
180    
181  /*********************************************************************/          int input_num;
182  /*                    input and output functions                     */          int output_num;
 /*                                                                   */  
 /* the are small and simple routines to read and write PGM and YUV   */  
 /* image. It's just for convenience, again nothing specific to XviD  */  
 /*                                                                   */  
 /*********************************************************************/  
183    
184  int read_pgmheader(FILE* handle)          char filename[256];
 {  
         int bytes,xsize,ysize,depth;  
         char dummy[2];  
185    
186          bytes = fread(dummy,1,2,handle);          FILE *in_file = stdin;
187            FILE *out_file = NULL;
188    
189          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))          printf("xvid_encraw - raw mpeg4 bitstream encoder ");
190                  return 1;          printf("written by Christoph Lampert 2002-2003\n\n");
191          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);  
192          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )  /*****************************************************************************
193          {   *                            Command line parsing
194                  return 2;   ****************************************************************************/
195    
196            for (i = 1; i < argc; i++) {
197    
198                    if (strcmp("-asm", argv[i]) == 0) {
199                            use_assembler = 1;
200                    } else if (strcmp("-w", argv[i]) == 0 && i < argc - 1) {
201                            i++;
202                            XDIM = atoi(argv[i]);
203                    } else if (strcmp("-h", argv[i]) == 0 && i < argc - 1) {
204                            i++;
205                            YDIM = atoi(argv[i]);
206                    } else if (strcmp("-bitrate", argv[i]) == 0 && i < argc - 1) {
207                            i++;
208                            ARG_BITRATE = atoi(argv[i]);
209                    } else if (strcmp("-max_bframes", argv[i]) == 0 && i < argc - 1) {
210                            i++;
211                            ARG_MAXBFRAMES = atoi(argv[i]);
212                    } else if (strcmp("-packed", argv[i]) == 0) {
213                            ARG_PACKED = 1;
214                    } else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) {
215                            i++;
216                            ARG_BQRATIO = atoi(argv[i]);
217                    } else if (strcmp("-bquant_offset", argv[i]) == 0 && i < argc - 1) {
218                            i++;
219                            ARG_BQOFFSET = atoi(argv[i]);
220                    } else if (strcmp("-quality", argv[i]) == 0 && i < argc - 1) {
221                            i++;
222                            ARG_QUALITY = atoi(argv[i]);
223                    } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {
224                            i++;
225                            ARG_FRAMERATE = (float) atof(argv[i]);
226                    } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1) {
227                            i++;
228                            ARG_INPUTFILE = argv[i];
229                    } else if (strcmp("-stats", argv[i]) == 0) {
230                            ARG_STATS = 1;
231                    } else if (strcmp("-dump", argv[i]) == 0) {
232                            ARG_DUMP = 1;
233                    } else if (strcmp("-lumimasking", argv[i]) == 0) {
234                            ARG_LUMIMASKING = 1;
235                    } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {
236                            i++;
237                            ARG_INPUTTYPE = atoi(argv[i]);
238                    } else if (strcmp("-nframes", argv[i]) == 0 && i < argc - 1) {
239                            i++;
240                            ARG_MAXFRAMENR = atoi(argv[i]);
241                    } else if (strcmp("-quant", argv[i]) == 0 && i < argc - 1) {
242                            i++;
243                            ARG_QUANTI = atoi(argv[i]);
244                    } else if (strcmp("-save", argv[i]) == 0) {
245                            ARG_SAVEMPEGSTREAM = 1;
246                    } else if (strcmp("-debug", argv[i]) == 0) {
247                            ARG_DEBUG = 1;
248                    } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {
249                            i++;
250                            ARG_OUTPUTFILE = argv[i];
251                    } else if (strcmp("-help", argv[i])) {
252                            usage();
253                            return (0);
254                    } else {
255                            usage();
256                            exit(-1);
257                    }
258    
259            }
260    
261    /*****************************************************************************
262     *                            Arguments checking
263     ****************************************************************************/
264    
265            if (XDIM <= 0 || XDIM >= 2048 || YDIM <= 0 || YDIM >= 2048) {
266                    fprintf(stderr,
267                                    "Trying to retreive width and height from PGM header\n");
268                    ARG_INPUTTYPE = 1;              /* pgm */
269            }
270    
271            if (ARG_QUALITY < 0 || ARG_QUALITY > 5) {
272                    fprintf(stderr, "Wrong Quality\n");
273                    return (-1);
274            }
275    
276            if (ARG_BITRATE <= 0 && ARG_QUANTI == 0) {
277                    fprintf(stderr, "Wrong Bitrate\n");
278                    return (-1);
279            }
280    
281            if (ARG_FRAMERATE <= 0) {
282                    fprintf(stderr, "Wrong Framerate %s \n", argv[5]);
283                    return (-1);
284            }
285    
286            if (ARG_MAXFRAMENR <= 0) {
287                    fprintf(stderr, "Wrong number of frames\n");
288                    return (-1);
289            }
290    
291            if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
292                    in_file = stdin;
293            } else {
294    
295                    in_file = fopen(ARG_INPUTFILE, "rb");
296                    if (in_file == NULL) {
297                            fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
298                            return (-1);
299                    }
300            }
301    
302            if (ARG_INPUTTYPE) {
303                    if (read_pgmheader(in_file)) {
304                            fprintf(stderr,
305                                            "Wrong input format, I want YUV encapsulated in PGM\n");
306                            return (-1);
307          }          }
         if ( (XDIM==0) || (YDIM==0) )  
         {       XDIM=xsize;  
                 YDIM=ysize;  
308          }          }
309    
310          return 0;          /* now we know the sizes, so allocate memory */
311  }          in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM, YDIM));
312            if (!in_buffer)
313                    goto free_all_memory;
314    
315  int read_pgmdata(FILE* handle, unsigned char *image)          /* this should really be enough memory ! */
316  {          mp4_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM, YDIM) * 2);
317          int i,status;          if (!mp4_buffer)
318          char dummy;                  goto free_all_memory;
319    
320          unsigned char* buff1_ptr2 = image + XDIM*YDIM;  /*****************************************************************************
321          unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;   *                            XviD PART  Start
322     ****************************************************************************/
323    
         fread(image,XDIM*YDIM,1,stdin); // read Y component of picture  
324    
325          for (i=0;i<YDIM/2;i++)          result = enc_init(use_assembler);
326          {          if (result) {
327                  fread(buff1_ptr2,XDIM/2,1,stdin);        // read U                  fprintf(stderr, "Encore INIT problem, return value %d\n", result);
328                  buff1_ptr2 += XDIM/2;                  goto release_all;
                 fread(buff1_ptr3,XDIM/2,1,stdin);        // read V  
                 buff1_ptr3 += XDIM/2;  
         }  
         fread(&dummy,1,1,handle);       //  I don't know why, but this seems needed  
         return 0;  
329  }  }
330    
331  int read_yuvdata(FILE* handle, unsigned char *image)  /*****************************************************************************
332  {       int i;   *                            Main loop
333          char dummy;   ****************************************************************************/
334    
335          unsigned char* buff1_ptr2 = image + XDIM*YDIM;          if (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) {
         unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;  
336    
337          if (fread(image,XDIM,YDIM*3/2,stdin) != YDIM*3/2)                  if ((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) {
338                  return 1;                          fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE);
339          else                          goto release_all;
                 return 0;  
340  }  }
341    
342  int write_pgm(char *filename, unsigned char *image)          } else {
343  {                  out_file = NULL;
         FILE *filehandle;  
         filehandle=fopen(filename,"wb");  
         if (filehandle)  
         {  
                 fprintf(filehandle,"P5\n\n");           //  
                 fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2);  
                 fwrite(image,XDIM,YDIM*3/2,filehandle);  
                 fclose(filehandle);  
                 return 0;  
344          }          }
345          else  
346                  return 1;  /*****************************************************************************
347     *                       Encoding loop
348     ****************************************************************************/
349    
350            totalsize = 0;
351    
352            result = 0;
353    
354            input_num = 0;                          /* input frame counter */
355            output_num = 0;                         /* output frame counter */
356    
357            do {
358    
359                    char *type;
360                    int sse[3];
361    
362                    if (input_num >= ARG_MAXFRAMENR) {
363                            result = 1;
364  }  }
365    
366  /*********************************************************************/                  if (!result) {
367  /* Routines for encoding: init encoder, frame step, release encoder  */                          if (ARG_INPUTTYPE) {
368  /*********************************************************************/                                  /* read PGM data (YUV-format) */
369                                    result = read_pgmdata(in_file, in_buffer);
370                            } else {
371                                    /* read raw data (YUV-format) */
372                                    result = read_yuvdata(in_file, in_buffer);
373                            }
374                    }
375    
376  #define FRAMERATE_INCR 1001  /*****************************************************************************
377     *                       Encode and decode this frame
378     ****************************************************************************/
379    
380                    enctime = msecond();
381                    m4v_size =
382                            enc_main(!result ? in_buffer : 0, mp4_buffer, &key, &stats_type,
383                                             &stats_quant, &stats_length, sse);
384                    enctime = msecond() - enctime;
385    
386  int enc_init(int use_assembler)                  /* Write the Frame statistics */
 {       /* initialize encoder for first use, pass all needed parameters to the codec */  
         int xerr;  
387    
388          XVID_INIT_PARAM xinit;                  printf("%5d: key=%i, time(ms)=%6.1f, length=%7d",
389          XVID_ENC_PARAM xparam;                             !result ? input_num : -1,
390                               key,
391                               (float) enctime,
392                               (int) m4v_size);
393    
394          if(use_assembler)                  if (stats_type > 0) {   /* !XVID_TYPE_NOTHING */
395    
396  #ifdef ARCH_IA64                          switch (stats_type) {
397                  xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;                          case XVID_TYPE_IVOP:
398  #else                                  type = "I";
399                  xinit.cpu_flags = 0;                                  break;
400  #endif                          case XVID_TYPE_PVOP:
401                                    type = "P";
402                                    break;
403                            case XVID_TYPE_BVOP:
404                                    type = "B";
405                                    break;
406                            case XVID_TYPE_SVOP:
407                                    type = "S";
408                                    break;
409                            default:
410                                    type = "U";
411                                    break;
412                            }
413    
414          else                          printf(" | type=%s, quant=%2d, length=%7d", type, stats_quant,
415                  xinit.cpu_flags = XVID_CPU_FORCE;                                     stats_length);
416    
417          xvid_init(NULL, 0, &xinit, NULL);  #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height)))))
418    
419          xparam.width = XDIM;                          if (ARG_STATS) {
420          xparam.height = YDIM;                                  printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f",
421          if ((ARG_FRAMERATE - (int)ARG_FRAMERATE) < SMALL_EPS)                                             SSE2PSNR(sse[0], XDIM, YDIM),
422          {                                             SSE2PSNR(sse[1], XDIM/2, YDIM/2),
423                  xparam.fincr = 1;                                             SSE2PSNR(sse[2], XDIM/2, YDIM/2));
                 xparam.fbase = (int)ARG_FRAMERATE;  
424          }          }
425          else  
         {  
                 xparam.fincr = FRAMERATE_INCR;  
                 xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE);  
426          }          }
         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;  
   
 #ifdef BFRAMES  
         xparam.global = XVID_GLOBAL_DX50BVOP;  
         xparam.max_bframes = ARG_MAXBFRAMES;  
         xparam.bquant_ratio = ARG_BQUANTRATIO;  
         xparam.frame_drop_ratio=0;  
 #endif  
427    
428          /* I use a small value here, since will not encode whole movies,  #undef SSE2PSNR
                 but short clips */  
429    
430          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL);                  printf("\n");
         enc_handle=xparam.handle;  
431    
432          return xerr;                  if (m4v_size < 0) {
433                            break;
434  }  }
435    
436  int  enc_stop()                  /* Update encoding time stats */
437  {       int xerr;                  totalenctime += enctime;
438                    totalsize += m4v_size;
439    
440    /*****************************************************************************
441     *                       Save stream to file
442     ****************************************************************************/
443    
444          xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL);                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {
445          return xerr;                          /* Save single files */
446                            if (out_file == NULL) {
447                                    sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
448                                    out_file = fopen(filename, "wb");
449                                    fwrite(mp4_buffer, m4v_size, 1, out_file);
450                                    fclose(out_file);
451                                    out_file = NULL;
452                                    output_num++;
453                            } else {
454    
455                                    /* Write mp4 data */
456                                    fwrite(mp4_buffer, 1, m4v_size, out_file);
457    
458                            }
459  }  }
460    
461  int  enc_main(unsigned char* image, unsigned char* bitstream, int *streamlength, int* frametype)                  input_num++;
 {       int xerr;  
462    
463          XVID_ENC_FRAME xframe;                  /* Read the header if it's pgm stream */
464          XVID_ENC_STATS xstats;                  if (!result && ARG_INPUTTYPE)
465                            result = read_pgmheader(in_file);
466    
467          xframe.bitstream = bitstream;          } while (1);
         xframe.length = -1;     // this is written by the routine  
468    
         xframe.image = image;  
         xframe.colorspace = XVID_CSP_YV12;      // defined in <xvid.h>  
469    
         xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0)  
470    
471          xframe.quant = ARG_QUANTI;      // is quant != 0, use a fixed quant (and ignore bitrate)  /*****************************************************************************
472     *         Calculate totals and averages for output, print results
473     ****************************************************************************/
474    
475          xframe.motion = motion_presets[ARG_QUALITY];          printf("Tot: enctime(ms) =%7.2f,               length(bytes) = %7d\n",
476          xframe.general = general_presets[ARG_QUALITY];                     totalenctime, (int) totalsize);
         xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;  
477    
478  #ifdef BFRAMES          if (input_num > 0) {
479          xframe.bquant = 0;                  totalsize /= input_num;
480  #endif                  totalenctime /= input_num;
481            } else {
482                    totalsize = -1;
483                    totalenctime = -1;
484            }
485    
486          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);          printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n",
487                       totalenctime, 1000 / totalenctime, (int) totalsize);
488    
 /*              enc_result->is_key_frame = xframe.intra;  
                 enc_result->quantizer = xframe.quant;  
                 enc_result->total_bits = xframe.length * 8;  
                 enc_result->motion_bits = xstats.hlength * 8;  
                 enc_result->texture_bits = enc_result->total_bits - enc_result->motion_bits;  
 */  
489    
490  /*  This is statictical data, e.g. for 2-pass.  /*****************************************************************************
491      If you are not interested in any of this, you can use   *                            XviD PART  Stop
492          NULL instead of &xstats   ****************************************************************************/
 */  
         *frametype = xframe.intra;  
         *streamlength = xframe.length;  
493    
494          return xerr;    release_all:
 }  
495    
496  /*********************************************************************/          if (enc_handle) {
497  /*                          Main program                             */                  result = enc_stop();
498  /*********************************************************************/                  if (result)
499                            fprintf(stderr, "Encore RELEASE problem return value %d\n",
500                                            result);
501            }
502    
503  int main(int argc, char *argv[])          if (in_file)
504  {                  fclose(in_file);
505    unsigned char *divx_buffer = NULL;          if (out_file)
506    unsigned char *in_buffer = NULL;                  fclose(out_file);
507    
508    double enctime;    free_all_memory:
509    double totalenctime=0.;          free(out_buffer);
510            free(mp4_buffer);
511            free(in_buffer);
512    
513    long totalsize=0;          return (0);
   int status;  
514    
515    int m4v_size;  }
   int frame_type[ABS_MAXFRAMENR];  
   int Iframes=0, Pframes=0, Bframes=0;  
   int use_assembler=1;  
516    
   char filename[256];  
517    
518    FILE *filehandle;  /*****************************************************************************
519     *                        "statistical" functions
520     *
521     *  these are not needed for encoding or decoding, but for measuring
522     *  time and quality, there in nothing specific to XviD in these
523     *
524     *****************************************************************************/
525    
526  /* read YUV in pgm format from stdin */  /* Return time elapsed time in miliseconds since the program started */
527    if (!pgmflag)  static double
528    msecond()
529    {    {
530          pgmflag = 1;  #ifndef WIN32
531            struct timeval tv;
532    
533  //      if (argc==2 && !strcmp(argv[1],"-noasm"))          gettimeofday(&tv, 0);
534  //        use_assembler = 0;          return (tv.tv_sec * 1.0e3 + tv.tv_usec * 1.0e-3);
535    #else
536            clock_t clk;
537    
538          if (argc>=3)          clk = clock();
539          {       XDIM = atoi(argv[1]);          return (clk * 1000 / CLOCKS_PER_SEC);
540                  YDIM = atoi(argv[2]);  #endif
                 if ( (XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048) )  
                 {       fprintf(stderr,"Wrong frames size %d %d, trying PGM \n",XDIM, YDIM);  
                 }  
                 else  
                 {  
                         YDIM = YDIM*3/2; /* for YUV */  
                         pgmflag = 0;  
                 }  
         }  
541    }    }
542    
543    if (pgmflag)  /*****************************************************************************
544    {     if (read_pgmheader(stdin))   *                             Usage message
545     *****************************************************************************/
546    
547    static void
548    usage()
549    {
550            fprintf(stderr, "Usage : xvid_stat [OPTIONS]\n\n");
551            fprintf(stderr, "Input options:\n");
552            fprintf(stderr, " -i       string : input filename (default=stdin)\n");
553            fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");
554            fprintf(stderr, " -w       integer: frame width ([1.2048])\n");
555            fprintf(stderr, " -h       integer: frame height ([1.2048])\n");
556            fprintf(stderr, " -nframes integer: number of frames to encode\n");
557            fprintf(stderr, "\n");
558            fprintf(stderr, "Output options:\n");
559            fprintf(stderr, " -dump    : save decoder output\n");
560            fprintf(stderr, " -save    : save mpeg4 raw stream\n");
561            fprintf(stderr, " -o string: output filename\n");
562            fprintf(stderr, "\n");
563            fprintf(stderr, "Bitrate options:\n");
564            fprintf(stderr, " -bitrate       integer: target bitrate (>0 | default=900kbit)\n");
565            fprintf(stderr, " -quant         integer: fixed quantizer (disables -b setting)\n");
566            fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");
567            fprintf(stderr, " -bquant_ratio  integer: bframe quantizer ratio (default=150)\n");
568            fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (default=100)\n");
569            fprintf(stderr, " -framerate     float  : target framerate (>0)\n");
570            fprintf(stderr, "\n");
571            fprintf(stderr, "Other options\n");
572            fprintf(stderr, " -asm            : use assembly optmized code\n");
573            fprintf(stderr, " -quality integer: quality ([0..5])\n");
574            fprintf(stderr, " -packed         : packed mode\n");
575            fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");
576            fprintf(stderr, " -stats          : print stats about encoded frames\n");
577            fprintf(stderr, " -debug          : print all MB quantizers\n");
578            fprintf(stderr, " -help           : prints this help message\n");
579    }
580    
581    /*****************************************************************************
582     *                       Input and output functions
583     *
584     *      the are small and simple routines to read and write PGM and YUV
585     *      image. It's just for convenience, again nothing specific to XviD
586     *
587     *****************************************************************************/
588    
589    static int
590    read_pgmheader(FILE * handle)
591              {              {
592                fprintf(stderr,"Wrong input format, I want YUV encapsulated in PGM\n");          int bytes, xsize, ysize, depth;
593                return 1;          char dummy[2];
594              }  
595    }          bytes = fread(dummy, 1, 2, handle);
596    if (argc>=4)  
597    {     ARG_QUALITY = atoi(argv[3]);          if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5'))
598          if ( (ARG_QUALITY < 0) || (ARG_QUALITY > 6) )                  return (1);
599                  { fprintf(stderr,"Wrong Quality\n"); return -1; }  
600          else          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
601                    fprintf(stderr,"Quality %d\n",ARG_QUALITY);          if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) {
602    }                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
603    if (argc>=5)                  return (2);
   {     ARG_BITRATE = atoi(argv[4]);  
         if ( (ARG_BITRATE <= 0) )  
                 { fprintf(stderr,"Wrong Bitrate\n"); return -1; }  
         if ( (ARG_BITRATE < 32) )  
                 { ARG_QUANTI = ARG_BITRATE;  
                   ARG_BITRATE=0;  
                   fprintf(stderr,"Quantizer %d\n",ARG_QUANTI);  
604                  }                  }
605          else          if ((XDIM == 0) || (YDIM == 0)) {
606                    fprintf(stderr,"Bitrate %d kbps\n",ARG_BITRATE);                  XDIM = xsize;
607                    YDIM = ysize * 2 / 3;
608    }    }
609    if (argc>=6)  
610    {     ARG_FRAMERATE = (float)atof(argv[5]);          return (0);
         if ( (ARG_FRAMERATE <= 0) )  
                 { fprintf(stderr,"Wrong Fraterate %s \n",argv[5]); return -1; }  
         fprintf(stderr,"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; }  
         fprintf(stderr,"max. Framenr. %d\n",ARG_MAXFRAMENR);  
   }  
   
 #ifdef BFRAMES  
   if (argc>=8)  
   {     ARG_MAXBFRAMES = atoi(argv[7]);  
         if ( (ARG_MAXBFRAMES < -1) || ( ARG_MAXBFRAMES > ARG_FRAMERATE) )  
          { fprintf(stderr,"Wrong maximumnumber of bframes\n"); return -1; }  
         fprintf(stderr,"max. B-frames %d\n",ARG_MAXBFRAMES);  
   }  
   
   if (argc>=9)  
   {     ARG_MAXFRAMENR = atoi(argv[8]);  
         if ( (ARG_BQUANTRATIO <= 0) )  
          { fprintf(stderr,"Wrong B-frames Quantizer ratio \n"); return -1; }  
         fprintf(stderr,"B-frames quant-ratio %d\n",ARG_BQUANTRATIO);  
611    }    }
 #endif  
612    
613  /* now we know the sizes, so allocate memory */  static int
614    read_pgmdata(FILE * handle,
615                             unsigned char *image)
616    {
617            int i;
618            char dummy;
619    
620    in_buffer = (unsigned char *) malloc(XDIM*YDIM);          unsigned char *y = image;
621    if (!in_buffer)          unsigned char *u = image + XDIM * YDIM;
622      goto free_all_memory;          unsigned char *v = image + XDIM * YDIM + XDIM / 2 * YDIM / 2;
623    
624    divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2);          /* read Y component of picture */
625    if (!divx_buffer)          fread(y, 1, XDIM * YDIM, handle);
     goto free_all_memory;  
626    
627    YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture          for (i = 0; i < YDIM / 2; i++) {
628                    /* read U */
629                    fread(u, 1, XDIM / 2, handle);
630    
631  /*********************************************************************/                  /* read V */
632  /*                         XviD PART  Start                          */                  fread(v, 1, XDIM / 2, handle);
 /*********************************************************************/  
633    
634    status = enc_init(use_assembler);                  /* Update pointers */
635          if (status)                  u += XDIM / 2;
636          {                  v += XDIM / 2;
                 fprintf(stderr,"Encore INIT problem, return value %d\n", status);  
                 goto release_all;  
637          }          }
638    
639  /*********************************************************************/          /*  I don't know why, but this seems needed */
640  /*                               Main loop                           */          fread(&dummy, 1, 1, handle);
641  /*********************************************************************/  
642            return (0);
643    }
644    
645    do  static int
646    read_yuvdata(FILE * handle,
647                             unsigned char *image)
648      {      {
649          if (pgmflag)  
650                status = read_pgmdata(stdin, in_buffer);  // read PGM data (YUV-format)          if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) !=
651                    (unsigned int) IMAGE_SIZE(XDIM, YDIM))
652                    return (1);
653          else          else
654                status = read_yuvdata(stdin, in_buffer);  // read raw data (YUV-format)                  return (0);
655    }
656    
657    /*****************************************************************************
658     *     Routines for encoding: init encoder, frame step, release encoder
659     ****************************************************************************/
660    
661    /* sample plugin */
662    
663      if (status)  int
664    rawenc_debug(void *handle,
665                             int opt,
666                             void *param1,
667                             void *param2)
668          {          {
669            // Couldn't read image, most likely end-of-file          switch (opt) {
670            continue;          case XVID_PLG_INFO:
671                    {
672                            xvid_plg_info_t *info = (xvid_plg_info_t *) param1;
673    
674                            info->flags = XVID_REQDQUANTS;
675                            return 0;
676          }          }
677    
678            case XVID_PLG_CREATE:
679            case XVID_PLG_DESTROY:
680            case XVID_PLG_BEFORE:
681                    return 0;
682    
683      if (save_ref_flag)          case XVID_PLG_AFTER:
684          {          {
685                  sprintf(filename, "%s%05d.pgm", filepath, filenr);                          xvid_plg_data_t *data = (xvid_plg_data_t *) param1;
686                  write_pgm(filename,in_buffer);                          int i, j;
687    
688                            printf("---[ frame: %5i   quant: %2i   length: %6i ]---\n",
689                                       data->frame_num, data->quant, data->length);
690                            for (j = 0; j < data->mb_height; j++) {
691                                    for (i = 0; i < data->mb_width; i++)
692                                            printf("%2i ", data->dquant[j * data->dquant_stride + i]);
693                                    printf("\n");
694          }          }
695    
696                            return 0;
697                    }
698            }
699    
700  /*********************************************************************/          return XVID_ERR_FAIL;
701  /*               analyse this frame before encoding                  */  }
 /*********************************************************************/  
702    
 //      nothing is done here at the moment, but you could e.g. create  
 //      histograms or measure entropy or apply preprocessing filters...  
703    
704  /*********************************************************************/  #define FRAMERATE_INCR 1001
 /*               encode and decode this frame                        */  
 /*********************************************************************/  
705    
706          enctime = -msecond();  /* Initialize encoder for first use, pass all needed parameters to the codec */
707          status = enc_main(in_buffer, divx_buffer, &m4v_size, &frame_type[filenr]);  static int
708          enctime += msecond();  enc_init(int use_assembler)
709    {
710            int xerr;
711    
712          totalenctime += enctime;          xvid_enc_plugin_t plugins[3];
         totalsize += m4v_size;  
713    
714          fprintf(stderr,"Frame %5d: intra %d, enctime =%6.1f ms length=%7d bytes\n",          xvid_gbl_init_t xvid_gbl_init;
715                   filenr, frame_type[filenr], enctime*1000, m4v_size);          xvid_enc_create_t xvid_enc_create;
716    
717          if (save_m4v_flag)          /*------------------------------------------------------------------------
718          {           * XviD core initialization
719                  fwrite(divx_buffer, m4v_size, 1, stdout);           *----------------------------------------------------------------------*/
720    
721            /* Set version -- version checking will done by xvidcore */
722            memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
723            xvid_gbl_init.version = XVID_VERSION;
724    
725    
726            /* Do we have to enable ASM optimizations ? */
727            if (use_assembler) {
728    
729    #ifdef ARCH_IS_IA64
730                    xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;
731    #else
732                    xvid_gbl_init.cpu_flags = 0;
733    #endif
734            } else {
735                    xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
736          }          }
737    
738          if (pgmflag)          /* Initialize XviD core -- Should be done once per __process__ */
739                  status = read_pgmheader(stdin);          xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
                                 // because if this was the last PGM, stop now  
740    
741          filenr++;          /*------------------------------------------------------------------------
742             * XviD encoder initialization
743             *----------------------------------------------------------------------*/
744    
745     } while ( (!status) && (filenr<ARG_MAXFRAMENR) );          /* Version again */
746            memset(&xvid_enc_create, 0, sizeof(xvid_enc_create));
747            xvid_enc_create.version = XVID_VERSION;
748    
749            /* Width and Height of input frames */
750            xvid_enc_create.width = XDIM;
751            xvid_enc_create.height = YDIM;
752    
753            /* init plugins  */
754    
755  /*********************************************************************/          xvid_enc_create.plugins = plugins;
756  /*     calculate totals and averages for output, print results       */          xvid_enc_create.num_plugins = 0;
 /*********************************************************************/  
757    
758          totalsize    /= filenr;          if (ARG_LUMIMASKING) {
759          totalenctime /= filenr;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
760                    plugins[xvid_enc_create.num_plugins].param = NULL;
761                    xvid_enc_create.num_plugins++;
762            }
763    
764          for (i=0;i<filenr;i++)          if (ARG_DUMP) {
765          {                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_dump;
766                  switch (frame_type[i])                  plugins[xvid_enc_create.num_plugins].param = NULL;
767                  {                  xvid_enc_create.num_plugins++;
768                  case 0:          }
769                          Pframes++;  
770                          break;          if (ARG_DEBUG) {
771                  case 1:                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;
772                          Iframes++;                  plugins[xvid_enc_create.num_plugins].param = NULL;
773                          break;                  xvid_enc_create.num_plugins++;
                 case 2:  
                 default:  
                         Bframes++;  
                         break;  
774                  }                  }
775    
776            /* No fancy thread tests */
777            xvid_enc_create.num_threads = 0;
778    
779            /* Frame rate - Do some quick float fps = fincr/fbase hack */
780            if ((ARG_FRAMERATE - (int) ARG_FRAMERATE) < SMALL_EPS) {
781                    xvid_enc_create.fincr = 1;
782                    xvid_enc_create.fbase = (int) ARG_FRAMERATE;
783            } else {
784                    xvid_enc_create.fincr = FRAMERATE_INCR;
785                    xvid_enc_create.fbase = (int) (FRAMERATE_INCR * ARG_FRAMERATE);
786          }          }
787    
788          fprintf(stderr,"Avg: enctime %5.2f ms, %5.2f fps, filesize =%d\n",          /* Maximum key frame interval */
789                  1000*totalenctime, 1./totalenctime, totalsize);          xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10;
790    
791  /*********************************************************************/          /* Bframes settings */
792  /*                         XviD PART  Stop                           */          xvid_enc_create.max_bframes = ARG_MAXBFRAMES;
793  /*********************************************************************/          xvid_enc_create.bquant_ratio = ARG_BQRATIO;
794            xvid_enc_create.bquant_offset = ARG_BQOFFSET;
795    
796  release_all:          /* Dropping ratio frame -- we don't need that */
797            xvid_enc_create.frame_drop_ratio = 0;
798    
799          if (enc_handle)          /* Global encoder options */
800            xvid_enc_create.global = 0;
801            if (ARG_PACKED) xvid_enc_create.global |=XVID_PACKED;
802            if (ARG_STATS)  xvid_enc_create.global |=XVID_EXTRASTATS_ENABLE;
803    
804            /* I use a small value here, since will not encode whole movies, but short clips */
805            xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
806    
807            /* Retrieve the encoder instance from the structure */
808            enc_handle = xvid_enc_create.handle;
809    
810            return (xerr);
811    }
812    
813    static int
814    enc_stop()
815          {          {
816                  status = enc_stop();          int xerr;
817                  if (status)  
818                          fprintf(stderr,"Encore RELEASE problem return value %d\n", status);          /* Destroy the encoder instance */
819            xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL);
820    
821            return (xerr);
822          }          }
823    
824  free_all_memory:  static int
825          free(divx_buffer);  enc_main(unsigned char *image,
826          free(in_buffer);                   unsigned char *bitstream,
827                     int *key,
828                     int *stats_type,
829                     int *stats_quant,
830                     int *stats_length,
831                     int sse[3])
832    {
833            int ret;
834    
835            xvid_enc_frame_t xvid_enc_frame;
836            xvid_enc_stats_t xvid_enc_stats;
837    
838            /* Version for the frame and the stats */
839            memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame));
840            xvid_enc_frame.version = XVID_VERSION;
841    
842            memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats));
843            xvid_enc_stats.version = XVID_VERSION;
844    
845            /* Bind output buffer */
846            xvid_enc_frame.bitstream = bitstream;
847            xvid_enc_frame.length = -1;
848    
849            /* Initialize input image fields */
850            if (image) {
851                    xvid_enc_frame.input.plane[0] = image;
852                    xvid_enc_frame.input.csp = XVID_CSP_I420;
853                    xvid_enc_frame.input.stride[0] = XDIM;
854            } else {
855                    xvid_enc_frame.input.csp = XVID_CSP_NULL;
856            }
857    
858            /* Set up core's general features */
859            xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY];
860            if (ARG_STATS)
861                    xvid_enc_frame.vol_flags |= XVID_EXTRASTATS;
862    
863            /* Set up core's general features */
864            xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
865    
866            /* Frame type -- let core decide for us */
867            xvid_enc_frame.type = XVID_TYPE_AUTO;
868    
869            /* Force the right quantizer */
870            xvid_enc_frame.quant = ARG_QUANTI;
871    
872            /* Set up motion estimation flags */
873            xvid_enc_frame.motion = motion_presets[ARG_QUALITY];
874    
875            /* We don't use special matrices */
876            xvid_enc_frame.quant_intra_matrix = NULL;
877            xvid_enc_frame.quant_inter_matrix = NULL;
878    
879            /* Encode the frame */
880            ret =
881                    xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
882                                            &xvid_enc_stats);
883    
884            *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);
885            *stats_type = xvid_enc_stats.type;
886            *stats_quant = xvid_enc_stats.quant;
887            *stats_length = xvid_enc_stats.length;
888            sse[0] = xvid_enc_stats.sse_y;
889            sse[1] = xvid_enc_stats.sse_u;
890            sse[2] = xvid_enc_stats.sse_v;
891    
892    return 0;          return (ret);
893  }  }

Legend:
Removed from v.376  
changed lines
  Added in v.933

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