[cvs] / xvidcore / examples / xvid_encraw.c Repository:
ViewVC logotype

Diff of /xvidcore/examples/xvid_encraw.c

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

revision 1.11.2.20, Sun Apr 27 20:36:13 2003 UTC revision 1.21, Thu Oct 6 18:28:31 2005 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Console based test application  -   *  - Console based test application  -
5   *   *
6   *  Copyright(C) 2002-2003 Christoph Lampert   *  Copyright(C) 2002-2003 Christoph Lampert <gruel@web.de>
7     *               2002-2003 Edouard Gomez <ed.gomez@free.fr>
8     *               2003      Peter Ross <pross@xvid.org>
9   *   *
10   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
11   *  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 32  Line 34 
34   *  The program is plain C and needs no libraries except for libxvidcore,   *  The program is plain C and needs no libraries except for libxvidcore,
35   *  and maths-lib.   *  and maths-lib.
36   *   *
37     *  Use ./xvid_encraw -help for a list of options
38     *
39   ************************************************************************/   ************************************************************************/
40    
41  #include <stdio.h>  #include <stdio.h>
# Line 41  Line 45 
45  #ifndef WIN32  #ifndef WIN32
46  #include <sys/time.h>  #include <sys/time.h>
47  #else  #else
48    #include <windows.h>
49    #include <vfw.h>
50  #include <time.h>  #include <time.h>
51    #define XVID_AVI_INPUT
52  #endif  #endif
53    
54  #include "xvid.h"  #include "xvid.h"
55    
56    #undef READ_PNM
57    
58  /*****************************************************************************  /*****************************************************************************
59   *                            Quality presets   *                            Quality presets
60   ****************************************************************************/   ****************************************************************************/
61    
62  static xvid_motion_t const motion_presets[] = {  static const int motion_presets[] = {
63          0,                                                                                                                                                      /* 0 */          /* quality 0 */
64          XVID_ME_HALFPELREFINE16,                                                                                                        /* 1 */          0,
65          XVID_ME_HALFPELREFINE16,                                                                                                        /* 2 */  
66          XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8,                                                       /* 3 */          /* quality 1 */
67          XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8,                                                       /* 4 */          XVID_ME_ADVANCEDDIAMOND16,
68          XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH16 |  
69                  XVID_ME_USESQUARES16,                                                                                                   /* 5 */          /* quality 2 */
70          XVID_ME_HALFPELREFINE16 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH16 |          XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16,
71                  XVID_ME_USESQUARES16 | XVID_ME_CHROMA16 | XVID_ME_CHROMA8,                              /* 6 */  
72  };          /* quality 3 */
73            XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
74            XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8,
75    
76            /* quality 4 */
77            XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
78            XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |
79            XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,
80    
81            /* quality 5 */
82            XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
83            XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |
84            XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,
85    
86            /* quality 6 */
87            XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |
88            XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 |
89            XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,
90    
 static xvid_vol_t const vol_presets[] = {  
         XVID_VOL_MPEGQUANT,                                                                                                                     /* 0 */  
         0,                                                                                                                                                      /* 1 */  
         0,                                                                                                                                                      /* 2 */  
         0,                                                                                                                                                      /* 3 */  
         0,                                                                                                                                                      /* 4 */  
         XVID_VOL_QUARTERPEL | XVID_VOL_GMC,                                                                                     /* 5 */  
         0                                                                                                                                                       /* 6 */  
91  };  };
92    #define ME_ELEMENTS (sizeof(motion_presets)/sizeof(motion_presets[0]))
93    
94    static const int vop_presets[] = {
95            /* quality 0 */
96            0,
97    
98            /* quality 1 */
99            0,
100    
101            /* quality 2 */
102            XVID_VOP_HALFPEL,
103    
104            /* quality 3 */
105            XVID_VOP_HALFPEL | XVID_VOP_INTER4V,
106    
107            /* quality 4 */
108            XVID_VOP_HALFPEL | XVID_VOP_INTER4V,
109    
110            /* quality 5 */
111            XVID_VOP_HALFPEL | XVID_VOP_INTER4V |
112            XVID_VOP_TRELLISQUANT,
113    
114            /* quality 6 */
115            XVID_VOP_HALFPEL | XVID_VOP_INTER4V |
116            XVID_VOP_TRELLISQUANT | XVID_VOP_HQACPRED,
117    
 static xvid_vop_t const vop_presets[] = {  
         XVID_VOP_DYNAMIC_BFRAMES,                                                                                                                               /* 0 */  
         XVID_VOP_DYNAMIC_BFRAMES,                                                                                                                               /* 1 */  
         XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL,                                                                                    /* 2 */  
         XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V,                                                 /* 3 */  
         XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_TRELLISQUANT, /* 4 */  
         XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_HQACPRED,     /* 5 */  
         XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | XVID_VOP_HQACPRED |                                               /* 6 */  
                 XVID_VOP_MODEDECISION_BITS  
118  };  };
119    #define VOP_ELEMENTS (sizeof(vop_presets)/sizeof(vop_presets[0]))
120    
121  /*****************************************************************************  /*****************************************************************************
122   *                     Command line global variables   *                     Command line global variables
123   ****************************************************************************/   ****************************************************************************/
124    
125    #define MAX_ZONES   64
126    
127    static xvid_enc_zone_t ZONES[MAX_ZONES];
128    static int NUM_ZONES = 0;
129    
130  /* Maximum number of frames to encode */  /* Maximum number of frames to encode */
131  #define ABS_MAXFRAMENR 9999  #define ABS_MAXFRAMENR 9999
132    
# Line 95  Line 134 
134  static int ARG_DUMP = 0;  static int ARG_DUMP = 0;
135  static int ARG_LUMIMASKING = 0;  static int ARG_LUMIMASKING = 0;
136  static int ARG_BITRATE = 0;  static int ARG_BITRATE = 0;
137    static int ARG_SINGLE = 0;
138  static char *ARG_PASS1 = 0;  static char *ARG_PASS1 = 0;
139  static char *ARG_PASS2 = 0;  static char *ARG_PASS2 = 0;
140  static int ARG_PASS2_BITRATE = 0;  static int ARG_QUALITY = ME_ELEMENTS - 1;
 static float ARG_QUANTI = 0.0f;  
 static int ARG_QUALITY = 3;  
141  static float ARG_FRAMERATE = 25.00f;  static float ARG_FRAMERATE = 25.00f;
142  static int ARG_MAXFRAMENR = ABS_MAXFRAMENR;  static int ARG_MAXFRAMENR = ABS_MAXFRAMENR;
143    static int ARG_MAXKEYINTERVAL = 0;
144  static char *ARG_INPUTFILE = NULL;  static char *ARG_INPUTFILE = NULL;
145  static int ARG_INPUTTYPE = 0;  static int ARG_INPUTTYPE = 0;
146  static int ARG_SAVEMPEGSTREAM = 0;  static int ARG_SAVEMPEGSTREAM = 0;
147    static int ARG_SAVEINDIVIDUAL = 0;
148  static char *ARG_OUTPUTFILE = NULL;  static char *ARG_OUTPUTFILE = NULL;
149  static int XDIM = 0;  static int XDIM = 0;
150  static int YDIM = 0;  static int YDIM = 0;
# Line 113  Line 153 
153  static int ARG_MAXBFRAMES = 0;  static int ARG_MAXBFRAMES = 0;
154  static int ARG_PACKED = 0;  static int ARG_PACKED = 0;
155  static int ARG_DEBUG = 0;  static int ARG_DEBUG = 0;
156    static int ARG_VOPDEBUG = 0;
157    static int ARG_GREYSCALE = 0;
158    static int ARG_QTYPE = 0;
159    static int ARG_QMATRIX = 0;
160    static int ARG_GMC = 0;
161    static int ARG_INTERLACING = 0;
162    static int ARG_QPEL = 0;
163    static int ARG_TURBO = 0;
164    static int ARG_VHQMODE = 0;
165    static int ARG_BVHQ = 0;
166    static int ARG_CLOSED_GOP = 0;
167    
168    #ifndef READ_PNM
169  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
170    #else
171    #define IMAGE_SIZE(x,y) ((x)*(y)*3)
172    #endif
173    
174  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
175  #define SMALL_EPS (1e-10)  #define SMALL_EPS (1e-10)
# Line 134  Line 189 
189  /* Internal structures (handles) for encoding and decoding */  /* Internal structures (handles) for encoding and decoding */
190  static void *enc_handle = NULL;  static void *enc_handle = NULL;
191    
192    static unsigned char qmatrix_intra[64];
193    static unsigned char qmatrix_inter[64];
194    
195    #ifdef XVID_AVI_INPUT
196    static PAVISTREAM avi_stream = NULL;
197    #endif
198    
199  /*****************************************************************************  /*****************************************************************************
200   *               Local prototypes   *               Local prototypes
201   ****************************************************************************/   ****************************************************************************/
# Line 145  Line 207 
207  static double msecond();  static double msecond();
208    
209  /* PGM related functions */  /* PGM related functions */
210    #ifndef READ_PNM
211  static int read_pgmheader(FILE * handle);  static int read_pgmheader(FILE * handle);
212  static int read_pgmdata(FILE * handle,  static int read_pgmdata(FILE * handle,
213                                                  unsigned char *image);                                                  unsigned char *image);
214    #else
215    static int read_pnmheader(FILE * handle);
216    static int read_pnmdata(FILE * handle,
217                                                    unsigned char *image);
218    #endif
219  static int read_yuvdata(FILE * handle,  static int read_yuvdata(FILE * handle,
220                                                  unsigned char *image);                                                  unsigned char *image);
221    
# Line 186  Line 254 
254          int stats_type;          int stats_type;
255          int stats_quant;          int stats_quant;
256          int stats_length;          int stats_length;
257          int use_assembler = 0;          int use_assembler = 1;
258    
259          int input_num;          int input_num;
260          int output_num;          int output_num;
# Line 199  Line 267 
267          printf("xvid_encraw - raw mpeg4 bitstream encoder ");          printf("xvid_encraw - raw mpeg4 bitstream encoder ");
268          printf("written by Christoph Lampert 2002-2003\n\n");          printf("written by Christoph Lampert 2002-2003\n\n");
269    
270            /* Is there a dumb XviD coder ? */
271            if(ME_ELEMENTS != VOP_ELEMENTS) {
272                    fprintf(stderr, "Presets' arrays should have the same number of elements -- Please fill a bug to xvid-devel@xvid.org\n");
273                    return(-1);
274            }
275    
276  /*****************************************************************************  /*****************************************************************************
277   *                            Command line parsing   *                            Command line parsing
278   ****************************************************************************/   ****************************************************************************/
# Line 207  Line 281 
281    
282                  if (strcmp("-asm", argv[i]) == 0) {                  if (strcmp("-asm", argv[i]) == 0) {
283                          use_assembler = 1;                          use_assembler = 1;
284                    } else if (strcmp("-noasm", argv[i]) == 0) {
285                            use_assembler = 0;
286                  } else if (strcmp("-w", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-w", argv[i]) == 0 && i < argc - 1) {
287                          i++;                          i++;
288                          XDIM = atoi(argv[i]);                          XDIM = atoi(argv[i]);
# Line 216  Line 292 
292                  } else if (strcmp("-bitrate", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-bitrate", argv[i]) == 0 && i < argc - 1) {
293                          i++;                          i++;
294                          ARG_BITRATE = atoi(argv[i]);                          ARG_BITRATE = atoi(argv[i]);
295                    } else if (strcmp("-single", argv[i]) == 0) {
296                            ARG_SINGLE = 1;
297                  } else if (strcmp("-pass1", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-pass1", argv[i]) == 0 && i < argc - 1) {
298                          i++;                          i++;
299                          ARG_PASS1 = argv[i];                          ARG_PASS1 = argv[i];
300                  } else if (strcmp("-pass2", argv[i]) == 0 && i < argc - 2) {                  } else if (strcmp("-pass2", argv[i]) == 0 && i < argc - 1) {
301                          i++;                          i++;
302                          ARG_PASS2 = argv[i];                          ARG_PASS2 = argv[i];
                         i++;  
                         ARG_PASS2_BITRATE = atoi(argv[i]);  
303                  } else if (strcmp("-max_bframes", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-max_bframes", argv[i]) == 0 && i < argc - 1) {
304                          i++;                          i++;
305                          ARG_MAXBFRAMES = atoi(argv[i]);                          ARG_MAXBFRAMES = atoi(argv[i]);
# Line 235  Line 311 
311                  } else if (strcmp("-bquant_offset", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-bquant_offset", argv[i]) == 0 && i < argc - 1) {
312                          i++;                          i++;
313                          ARG_BQOFFSET = atoi(argv[i]);                          ARG_BQOFFSET = atoi(argv[i]);
314    
315            } else if ((strcmp("-zq", argv[i]) == 0 || strcmp("-zw", argv[i]) == 0) && i < argc - 2) {
316    
317                if (NUM_ZONES >= MAX_ZONES) {
318                    fprintf(stderr,"warning: too many zones; zone ignored\n");
319                    continue;
320                }
321                ZONES[NUM_ZONES].mode = strcmp("-zq", argv[i])==0 ? XVID_ZONE_QUANT : XVID_ZONE_WEIGHT;
322                            i++;
323                ZONES[NUM_ZONES].frame = atoi(argv[i]);
324                i++;
325                ZONES[NUM_ZONES].increment  = (int)(atof(argv[i]) * 100);
326                ZONES[NUM_ZONES].base  = 100;
327                NUM_ZONES++;
328    
329                  } else if (strcmp("-quality", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-quality", argv[i]) == 0 && i < argc - 1) {
330                          i++;                          i++;
331                          ARG_QUALITY = atoi(argv[i]);                          ARG_QUALITY = atoi(argv[i]);
332                    } else if (strcmp("-vhqmode", argv[i]) == 0 && i < argc - 1) {
333                            i++;
334                            ARG_VHQMODE = atoi(argv[i]);
335                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {
336                          i++;                          i++;
337                          ARG_FRAMERATE = (float) atof(argv[i]);                          ARG_FRAMERATE = (float) atof(argv[i]);
338                    } else if (strcmp("-max_key_interval", argv[i]) == 0 && i < argc - 1) {
339                            i++;
340                            ARG_MAXKEYINTERVAL = atoi(argv[i]);
341                  } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1) {
342                          i++;                          i++;
343                          ARG_INPUTFILE = argv[i];                          ARG_INPUTFILE = argv[i];
# Line 253  Line 350 
350                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {
351                          i++;                          i++;
352                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
353                  } else if (strcmp("-nframes", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-frames", argv[i]) == 0 && i < argc - 1) {
354                          i++;                          i++;
355                          ARG_MAXFRAMENR = atoi(argv[i]);                          ARG_MAXFRAMENR = atoi(argv[i]);
356                  } else if (strcmp("-quant", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-qtype", argv[i]) == 0 && i < argc - 1) {
357                          i++;                          i++;
358                          ARG_QUANTI = (float) atof(argv[i]);                          ARG_QTYPE = atoi(argv[i]);
359                    } else if (strcmp("-qmatrix", argv[i]) == 0 && i < argc - 1) {
360                            FILE *fp = fopen(argv[++i], "rb");
361                            if (fp == NULL) {
362                                    fprintf(stderr, "Error opening input file %s\n", argv[i]);
363                                    return (-1);
364                            }
365                            fseek(fp, 0, SEEK_END);
366                            if (ftell(fp) != 128) {
367                                    fprintf(stderr, "Unexpected size of input file %s\n", argv[i]);
368                                    return (-1);
369                            }
370    
371                            fseek(fp, 0, SEEK_SET);
372                            fread(qmatrix_intra, 1, 64, fp);
373                            fread(qmatrix_inter, 1, 64, fp);
374    
375                            ARG_QMATRIX = 1;
376                  } else if (strcmp("-save", argv[i]) == 0) {                  } else if (strcmp("-save", argv[i]) == 0) {
377                          ARG_SAVEMPEGSTREAM = 1;                          ARG_SAVEMPEGSTREAM = 1;
378                            ARG_SAVEINDIVIDUAL = 1;
379                  } else if (strcmp("-debug", argv[i]) == 0) {                  } else if (strcmp("-debug", argv[i]) == 0) {
380                          ARG_DEBUG = 1;                          i++;
381                if (sscanf(argv[i],"0x%x", &ARG_DEBUG) || sscanf(argv[i],"%d", &ARG_DEBUG)) ;
382                  } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {
383                            ARG_SAVEMPEGSTREAM = 1;
384                          i++;                          i++;
385                          ARG_OUTPUTFILE = argv[i];                          ARG_OUTPUTFILE = argv[i];
386                    } else if (strcmp("-vop_debug", argv[i]) == 0) {
387                            ARG_VOPDEBUG = 1;
388                    } else if (strcmp("-grey", argv[i]) == 0) {
389                            ARG_GREYSCALE = 1;
390                    } else if (strcmp("-bvhq", argv[i]) == 0) {
391                            ARG_BVHQ = 1;
392                    } else if (strcmp("-qpel", argv[i]) == 0) {
393                            ARG_QPEL = 1;
394                    } else if (strcmp("-turbo", argv[i]) == 0) {
395                            ARG_TURBO = 1;
396                    } else if (strcmp("-gmc", argv[i]) == 0) {
397                            ARG_GMC = 1;
398                    } else if (strcmp("-interlaced", argv[i]) == 0) {
399                            ARG_INTERLACING = 1;
400                    } else if (strcmp("-closed_gop", argv[i]) == 0) {
401                            ARG_CLOSED_GOP = 1;
402                  } else if (strcmp("-help", argv[i])) {                  } else if (strcmp("-help", argv[i])) {
403                          usage();                          usage();
404                          return (0);                          return (0);
# Line 280  Line 413 
413   *                            Arguments checking   *                            Arguments checking
414   ****************************************************************************/   ****************************************************************************/
415    
416          if (XDIM <= 0 || XDIM >= 2048 || YDIM <= 0 || YDIM >= 2048) {          if (XDIM <= 0 || XDIM >= 4096 || YDIM <= 0 || YDIM >= 4096) {
417                  fprintf(stderr,                  fprintf(stderr,
418                                  "Trying to retreive width and height from PGM header\n");                                  "Trying to retrieve width and height from input header\n");
419                    if (!ARG_INPUTTYPE)
420                  ARG_INPUTTYPE = 1;              /* pgm */                  ARG_INPUTTYPE = 1;              /* pgm */
421          }          }
422    
423          if (ARG_QUALITY < 0 || ARG_QUALITY > 6) {          if (ARG_QUALITY < 0 ) {
424                  fprintf(stderr, "Wrong Quality\n");                  ARG_QUALITY = 0;
425                  return (-1);          } else if (ARG_QUALITY >= ME_ELEMENTS) {
426                    ARG_QUALITY = ME_ELEMENTS - 1;
427          }          }
428    
429          if (ARG_FRAMERATE <= 0) {          if (ARG_FRAMERATE <= 0) {
# Line 304  Line 439 
439          if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
440                  in_file = stdin;                  in_file = stdin;
441          } else {          } else {
442    #ifdef XVID_AVI_INPUT
443          if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 ||
444              strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 ||
445                      ARG_INPUTTYPE==2)
446          {
447                      AVISTREAMINFO avi_info;
448    
449                      AVIFileInit();
450                      if (AVIStreamOpenFromFile(&avi_stream, ARG_INPUTFILE, streamtypeVIDEO, 0, OF_READ, NULL) != AVIERR_OK) {
451                              fprintf(stderr, "Can't open stream from file '%s'!\n", ARG_INPUTFILE);
452                              AVIFileExit();
453                              return (-1);
454                      }
455    
456                      if(AVIStreamInfo(avi_stream, &avi_info, sizeof(AVISTREAMINFO)) != AVIERR_OK) {
457                              fprintf(stderr, "Can't get stream info from file '%s'!\n", ARG_INPUTFILE);
458                              AVIStreamRelease(avi_stream);
459                              AVIFileExit();
460                              return (-1);
461                      }
462    
463                  if (avi_info.fccHandler != MAKEFOURCC('Y', 'V', '1', '2')) {
464                              fprintf(stderr, "Unsupported input colorspace! Only YV12 is supported!\n");
465                              AVIStreamRelease(avi_stream);
466                          AVIFileExit();
467                  return (-1);
468                      }
469    
470                      XDIM = avi_info.rcFrame.right - avi_info.rcFrame.left;
471                      YDIM = avi_info.rcFrame.bottom - avi_info.rcFrame.top;
472                      ARG_FRAMERATE = (float) avi_info.dwRate / (float) avi_info.dwScale;
473    
474                      ARG_INPUTTYPE = 2;
475        }
476        else
477    #endif
478                    {
479                  in_file = fopen(ARG_INPUTFILE, "rb");                  in_file = fopen(ARG_INPUTFILE, "rb");
480                  if (in_file == NULL) {                  if (in_file == NULL) {
481                          fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);                          fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
482                          return (-1);                          return (-1);
483                  }                  }
484          }          }
485            }
486    
487          if (ARG_INPUTTYPE) {          if (ARG_INPUTTYPE==1) {
488    #ifndef READ_PNM
489                  if (read_pgmheader(in_file)) {                  if (read_pgmheader(in_file)) {
490    #else
491                    if (read_pnmheader(in_file)) {
492    #endif
493                          fprintf(stderr,                          fprintf(stderr,
494                                          "Wrong input format, I want YUV encapsulated in PGM\n");                                          "Wrong input format, I want YUV encapsulated in PGM\n");
495                          return (-1);                          return (-1);
# Line 377  Line 553 
553                  }                  }
554    
555                  if (!result) {                  if (!result) {
556                          if (ARG_INPUTTYPE) {  #ifdef XVID_AVI_INPUT
557                            if (ARG_INPUTTYPE==2) {
558                                    /* read avs/avi data (YUV-format) */
559                                    if(AVIStreamRead(avi_stream, input_num, 1, in_buffer, IMAGE_SIZE(XDIM, YDIM), NULL, NULL ) != AVIERR_OK)
560                                            result = 1;
561                            } else
562    #endif
563                                    if (ARG_INPUTTYPE==1) {
564                                  /* read PGM data (YUV-format) */                                  /* read PGM data (YUV-format) */
565    #ifndef READ_PNM
566                                  result = read_pgmdata(in_file, in_buffer);                                  result = read_pgmdata(in_file, in_buffer);
567    #else
568                                    result = read_pnmdata(in_file, in_buffer);
569    #endif
570                          } else {                          } else {
571                                  /* read raw data (YUV-format) */                                  /* read raw data (YUV-format) */
572                                  result = read_yuvdata(in_file, in_buffer);                                  result = read_yuvdata(in_file, in_buffer);
# Line 398  Line 585 
585    
586                  /* Write the Frame statistics */                  /* Write the Frame statistics */
587    
588                  printf("%5d: key=%i, time= %6.0f, length= %7d", !result ? input_num : -1,                  printf("%5d: key=%i, time= %6.0f, len= %7d", !result ? input_num : -1,
589                             key, (float) enctime, (int) m4v_size);                             key, (float) enctime, (int) m4v_size);
590    
591                  if (stats_type > 0) {   /* !XVID_TYPE_NOTHING */                  if (stats_type > 0) {   /* !XVID_TYPE_NOTHING */
# Line 421  Line 608 
608                                  break;                                  break;
609                          }                          }
610    
611                          printf(" | type=%s, quant= %2d, length= %7d", type, stats_quant,                          printf(" | type=%s, quant= %2d, len= %7d", type, stats_quant,
612                                     stats_length);                                     stats_length);
613    
614  #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height)))))  #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height)))))
# Line 455  Line 642 
642   ****************************************************************************/   ****************************************************************************/
643    
644                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {
645    
646                          /* Save single files */                          /* Save single files */
647                          if (out_file == NULL) {                          if (ARG_SAVEINDIVIDUAL) {
648                                    FILE *out;
649                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
650                                  out_file = fopen(filename, "wb");                                  out = fopen(filename, "w+b");
651                                  fwrite(mp4_buffer, m4v_size, 1, out_file);                                  fwrite(mp4_buffer, m4v_size, 1, out);
652                                  fclose(out_file);                                  fclose(out);
                                 out_file = NULL;  
653                                  output_num++;                                  output_num++;
654                          } else {                          }
655    
656                                  /* Write mp4 data */                          /* Save ES stream */
657                            if (ARG_OUTPUTFILE && out_file)
658                                  fwrite(mp4_buffer, 1, m4v_size, out_file);                                  fwrite(mp4_buffer, 1, m4v_size, out_file);
   
                         }  
659                  }                  }
660    
661                  input_num++;                  input_num++;
662    
663                  /* Read the header if it's pgm stream */                  /* Read the header if it's pgm stream */
664                  if (!result && ARG_INPUTTYPE)                  if (!result && (ARG_INPUTTYPE==1))
665    #ifndef READ_PNM
666                          result = read_pgmheader(in_file);                          result = read_pgmheader(in_file);
667    #else
668                            result = read_pnmheader(in_file);
669    #endif
670          } while (1);          } while (1);
671    
672    
# Line 514  Line 704 
704    
705    release_all:    release_all:
706    
707    #ifdef XVID_AVI_INPUT
708            if (avi_stream) {
709                    AVIStreamRelease(avi_stream);
710                    AVIFileExit();
711            }
712    #endif
713    
714          if (enc_handle) {          if (enc_handle) {
715                  result = enc_stop();                  result = enc_stop();
716                  if (result)                  if (result)
# Line 571  Line 768 
768          fprintf(stderr, "Usage : xvid_stat [OPTIONS]\n\n");          fprintf(stderr, "Usage : xvid_stat [OPTIONS]\n\n");
769          fprintf(stderr, "Input options:\n");          fprintf(stderr, "Input options:\n");
770          fprintf(stderr, " -i       string : input filename (default=stdin)\n");          fprintf(stderr, " -i       string : input filename (default=stdin)\n");
771    #ifdef XVID_AVI_INPUT
772            fprintf(stderr, " -type   integer: input data type (yuv=0, pgm=1, avi/avs=2)\n");
773    #else
774          fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");          fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");
775    #endif
776          fprintf(stderr, " -w       integer: frame width ([1.2048])\n");          fprintf(stderr, " -w       integer: frame width ([1.2048])\n");
777          fprintf(stderr, " -h       integer: frame height ([1.2048])\n");          fprintf(stderr, " -h       integer: frame height ([1.2048])\n");
778          fprintf(stderr, " -nframes integer: number of frames to encode\n");          fprintf(stderr, " -frames integer: number of frames to encode\n");
779          fprintf(stderr, "\n");          fprintf(stderr, "\n");
780          fprintf(stderr, "Output options:\n");          fprintf(stderr, "Output options:\n");
781          fprintf(stderr, " -dump    : save decoder output\n");          fprintf(stderr, " -dump    : save decoder output\n");
782          fprintf(stderr, " -save    : save mpeg4 raw stream\n");          fprintf(stderr, " -save    : save an Elementary Stream file per frame\n");
783          fprintf(stderr, " -o string: output filename\n");          fprintf(stderr, " -o string: save an Elementary Stream for the complete sequence\n");
784          fprintf(stderr, "\n");          fprintf(stderr, "\n");
785          fprintf(stderr, "BFrames options:\n");          fprintf(stderr, "BFrames options:\n");
786          fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");          fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");
# Line 588  Line 789 
789          fprintf(stderr, "\n");          fprintf(stderr, "\n");
790          fprintf(stderr, "Rate control options:\n");          fprintf(stderr, "Rate control options:\n");
791          fprintf(stderr, " -framerate float               : target framerate (>0 | default=25.0)\n");          fprintf(stderr, " -framerate float               : target framerate (>0 | default=25.0)\n");
792          fprintf(stderr, " -bitrate   integer             : bitrate -- for CBR/VBR pass2\n");          fprintf(stderr, " -bitrate   integer             : target bitrate\n");
793          fprintf(stderr, " -quant     float               : quantizer -- for \"Fixed\" quantizer RC\n");      fprintf(stderr,     " -single                        : single pass mode\n");
794          fprintf(stderr, " -pass1     filename            : output stats filename\n");          fprintf(stderr, " -pass1     filename            : twopass mode (first pass)\n");
795          fprintf(stderr, " -pass2     filename bitrate : input stats filename, target bitrate\n");          fprintf(stderr, " -pass2     filename            : twopass mode (2nd pass)\n");
796            fprintf(stderr, " -zq starting_frame float       : bitrate zone; quant\n");
797            fprintf(stderr, " -zw starting_frame float       : bitrate zone; weight\n");
798        fprintf(stderr, " -max_key_interval integer      : maximum keyframe interval\n");
799          fprintf(stderr, "\n");          fprintf(stderr, "\n");
800          fprintf(stderr, "Other options\n");          fprintf(stderr, "Other options\n");
801          fprintf(stderr, " -asm            : use assembly optmized code\n");          fprintf(stderr, " -noasm           : do not use assembly optmized code\n");
802          fprintf(stderr, " -quality integer: quality ([0..5])\n");          fprintf(stderr, " -turbo           : use turbo presets for higher encoding speed\n");
803            fprintf(stderr, " -quality integer : quality ([0..%d])\n", ME_ELEMENTS - 1);
804            fprintf(stderr, " -vhqmode integer : level of Rate-Distortion optimizations ([0..4]) (default=0)\n");
805            fprintf(stderr, " -bvhq            : use Rate-Distortion optimizations for B-frames too\n");
806            fprintf(stderr, " -qpel            : use quarter pixel ME\n");
807            fprintf(stderr, " -gmc             : use global motion compensation\n");
808            fprintf(stderr, " -qtype   integer : quantization type (H263:0, MPEG4:1) (default=0)\n");
809            fprintf(stderr, " -qmatrix filename: use custom MPEG4 quantization matrix\n");
810            fprintf(stderr, " -interlaced      : use interlaced encoding (this is NOT a deinterlacer!)\n");
811          fprintf(stderr, " -packed         : packed mode\n");          fprintf(stderr, " -packed         : packed mode\n");
812            fprintf(stderr, " -closed_gop      : closed GOP mode\n");
813            fprintf(stderr, " -grey            : grey scale coding (chroma is discarded)\n");
814          fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");          fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");
815          fprintf(stderr, " -stats          : print stats about encoded frames\n");          fprintf(stderr, " -stats          : print stats about encoded frames\n");
816          fprintf(stderr, " -debug          : print all MB dquants\n");          fprintf(stderr, " -debug           : activates xvidcore internal debugging output\n");
817            fprintf(stderr, " -vop_debug       : print some info directly into encoded frames\n");
818          fprintf(stderr, " -help           : prints this help message\n");          fprintf(stderr, " -help           : prints this help message\n");
819            fprintf(stderr, "\n");
820            fprintf(stderr, "NB: You can define %d zones repeating the -z[qw] option as many times as needed.\n", MAX_ZONES);
821            fprintf(stderr, "\n");
822  }  }
823    
824  /*****************************************************************************  /*****************************************************************************
# Line 611  Line 829 
829   *   *
830   *****************************************************************************/   *****************************************************************************/
831    
832    #ifndef READ_PNM
833  static int  static int
834  read_pgmheader(FILE * handle)  read_pgmheader(FILE * handle)
835  {  {
# Line 623  Line 842 
842                  return (1);                  return (1);
843    
844          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
845          if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) {          if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) {
846                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
847                  return (2);                  return (2);
848          }          }
# Line 666  Line 885 
885    
886          return (0);          return (0);
887  }  }
888    #else
889    static int
890    read_pnmheader(FILE * handle)
891    {
892            int bytes, xsize, ysize, depth;
893            char dummy[2];
894    
895            bytes = fread(dummy, 1, 2, handle);
896    
897            if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '6'))
898                    return (1);
899    
900            fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
901            if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) {
902                    fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
903                    return (2);
904            }
905    
906            XDIM = xsize;
907            YDIM = ysize;
908    
909            return (0);
910    }
911    
912    static int
913    read_pnmdata(FILE * handle,
914                             unsigned char *image)
915    {
916            int i;
917            char dummy;
918    
919            /* read Y component of picture */
920            fread(image, 1, XDIM * YDIM * 3, handle);
921    
922            /*  I don't know why, but this seems needed */
923            fread(&dummy, 1, 1, handle);
924    
925            return (0);
926    }
927    #endif
928    
929  static int  static int
930  read_yuvdata(FILE * handle,  read_yuvdata(FILE * handle,
# Line 734  Line 993 
993  enc_init(int use_assembler)  enc_init(int use_assembler)
994  {  {
995          int xerr;          int xerr;
996          xvid_plugin_cbr_t cbr;          //xvid_plugin_cbr_t cbr;
997        xvid_plugin_single_t single;
998          xvid_plugin_2pass1_t rc2pass1;          xvid_plugin_2pass1_t rc2pass1;
999          xvid_plugin_2pass2_t rc2pass2;          xvid_plugin_2pass2_t rc2pass2;
1000          xvid_plugin_fixed_t rcfixed;          //xvid_plugin_fixed_t rcfixed;
1001          xvid_enc_plugin_t plugins[7];          xvid_enc_plugin_t plugins[7];
1002          xvid_gbl_init_t xvid_gbl_init;          xvid_gbl_init_t xvid_gbl_init;
1003          xvid_enc_create_t xvid_enc_create;          xvid_enc_create_t xvid_enc_create;
# Line 749  Line 1009 
1009          /* Set version -- version checking will done by xvidcore */          /* Set version -- version checking will done by xvidcore */
1010          memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));          memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
1011          xvid_gbl_init.version = XVID_VERSION;          xvid_gbl_init.version = XVID_VERSION;
1012        xvid_gbl_init.debug = ARG_DEBUG;
1013    
1014    
1015          /* Do we have to enable ASM optimizations ? */          /* Do we have to enable ASM optimizations ? */
1016          if (use_assembler) {          if (use_assembler) {
1017    
1018  #ifdef ARCH_IS_IA64  #ifdef ARCH_IS_IA64
1019                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ASM;
1020  #else  #else
1021                  xvid_gbl_init.cpu_flags = 0;                  xvid_gbl_init.cpu_flags = 0;
1022  #endif  #endif
# Line 777  Line 1038 
1038          /* Width and Height of input frames */          /* Width and Height of input frames */
1039          xvid_enc_create.width = XDIM;          xvid_enc_create.width = XDIM;
1040          xvid_enc_create.height = YDIM;          xvid_enc_create.height = YDIM;
1041            xvid_enc_create.profile = XVID_PROFILE_AS_L4;
1042    
1043          /* init plugins  */          /* init plugins  */
1044        xvid_enc_create.zones = ZONES;
1045        xvid_enc_create.num_zones = NUM_ZONES;
1046    
1047          xvid_enc_create.plugins = plugins;          xvid_enc_create.plugins = plugins;
1048          xvid_enc_create.num_plugins = 0;          xvid_enc_create.num_plugins = 0;
1049    
1050          if (ARG_BITRATE) {          if (ARG_SINGLE) {
1051                  memset(&cbr, 0, sizeof(xvid_plugin_cbr_t));                  memset(&single, 0, sizeof(xvid_plugin_single_t));
1052                  cbr.version = XVID_VERSION;                  single.version = XVID_VERSION;
1053                  cbr.bitrate = ARG_BITRATE;                  single.bitrate = ARG_BITRATE;
   
                 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_cbr;  
                 plugins[xvid_enc_create.num_plugins].param = &cbr;  
                 xvid_enc_create.num_plugins++;  
         }  
   
         if (ARG_QUANTI) {  
                 memset(&rcfixed, 0, sizeof(xvid_plugin_fixed_t));  
                 rcfixed.version = XVID_VERSION;  
                 /* We will use a 1/10 precision, just to make sure it works */  
                 rcfixed.quant_base = 10;  
                 rcfixed.quant_increment = (int) (ARG_QUANTI * 10);  
1054    
1055                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_fixed;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
1056                  plugins[xvid_enc_create.num_plugins].param = &rcfixed;                  plugins[xvid_enc_create.num_plugins].param = &single;
1057                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
1058          }          }
1059    
# Line 809  Line 1061 
1061                  memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t));                  memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t));
1062                  rc2pass2.version = XVID_VERSION;                  rc2pass2.version = XVID_VERSION;
1063                  rc2pass2.filename = ARG_PASS2;                  rc2pass2.filename = ARG_PASS2;
1064                  rc2pass2.bitrate = ARG_PASS2_BITRATE;                  rc2pass2.bitrate = ARG_BITRATE;
1065    
1066    /*              An example of activating VBV could look like this
1067                    rc2pass2.vbv_size     =  3145728;
1068                    rc2pass2.vbv_initial  =  2359296;
1069                    rc2pass2.vbv_maxrate  =  4000000;
1070                    rc2pass2.vbv_peakrate = 10000000;
1071    */
1072    
1073                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
1074                  plugins[xvid_enc_create.num_plugins].param = &rc2pass2;                  plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
# Line 838  Line 1097 
1097                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
1098          }          }
1099    
1100    #if 0
1101          if (ARG_DEBUG) {          if (ARG_DEBUG) {
1102                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;
1103                  plugins[xvid_enc_create.num_plugins].param = NULL;                  plugins[xvid_enc_create.num_plugins].param = NULL;
1104                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
1105          }          }
1106    #endif
1107    
1108          /* No fancy thread tests */          /* No fancy thread tests */
1109          xvid_enc_create.num_threads = 0;          xvid_enc_create.num_threads = 0;
# Line 857  Line 1118 
1118          }          }
1119    
1120          /* Maximum key frame interval */          /* Maximum key frame interval */
1121        if (ARG_MAXKEYINTERVAL > 0) {
1122            xvid_enc_create.max_key_interval = ARG_MAXKEYINTERVAL;
1123        }else {
1124          xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10;          xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10;
1125        }
1126    
1127          /* Bframes settings */          /* Bframes settings */
1128          xvid_enc_create.max_bframes = ARG_MAXBFRAMES;          xvid_enc_create.max_bframes = ARG_MAXBFRAMES;
# Line 873  Line 1138 
1138          if (ARG_PACKED)          if (ARG_PACKED)
1139                  xvid_enc_create.global |=XVID_GLOBAL_PACKED;                  xvid_enc_create.global |=XVID_GLOBAL_PACKED;
1140    
1141            if (ARG_CLOSED_GOP)
1142                    xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
1143    
1144          if (ARG_STATS)          if (ARG_STATS)
1145                  xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;                  xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;
1146    
# Line 924  Line 1192 
1192          /* Initialize input image fields */          /* Initialize input image fields */
1193          if (image) {          if (image) {
1194                  xvid_enc_frame.input.plane[0] = image;                  xvid_enc_frame.input.plane[0] = image;
1195    #ifndef READ_PNM
1196                    if (ARG_INPUTTYPE==2)
1197                            xvid_enc_frame.input.csp = XVID_CSP_YV12;
1198                    else
1199                  xvid_enc_frame.input.csp = XVID_CSP_I420;                  xvid_enc_frame.input.csp = XVID_CSP_I420;
1200                  xvid_enc_frame.input.stride[0] = XDIM;                  xvid_enc_frame.input.stride[0] = XDIM;
1201    #else
1202                    xvid_enc_frame.input.csp = XVID_CSP_BGR;
1203                    xvid_enc_frame.input.stride[0] = XDIM*3;
1204    #endif
1205          } else {          } else {
1206                  xvid_enc_frame.input.csp = XVID_CSP_NULL;                  xvid_enc_frame.input.csp = XVID_CSP_NULL;
1207          }          }
1208    
1209          /* Set up core's general features */          /* Set up core's general features */
1210          xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY];          xvid_enc_frame.vol_flags = 0;
1211          if (ARG_STATS)          if (ARG_STATS)
1212                  xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS;                  xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS;
1213            if (ARG_QTYPE)
1214                    xvid_enc_frame.vol_flags |= XVID_VOL_MPEGQUANT;
1215            if (ARG_QPEL)
1216                    xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL;
1217            if (ARG_GMC)
1218                    xvid_enc_frame.vol_flags |= XVID_VOL_GMC;
1219            if (ARG_INTERLACING)
1220                    xvid_enc_frame.vol_flags |= XVID_VOL_INTERLACING;
1221    
1222          /* Set up core's general features */          /* Set up core's general features */
1223          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
1224    
1225        if (ARG_VOPDEBUG) {
1226            xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG;
1227        }
1228    
1229        if (ARG_GREYSCALE) {
1230            xvid_enc_frame.vop_flags |= XVID_VOP_GREYSCALE;
1231        }
1232    
1233          /* Frame type -- let core decide for us */          /* Frame type -- let core decide for us */
1234          xvid_enc_frame.type = XVID_TYPE_AUTO;          xvid_enc_frame.type = XVID_TYPE_AUTO;
1235    
# Line 947  Line 1239 
1239          /* Set up motion estimation flags */          /* Set up motion estimation flags */
1240          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];
1241    
1242            if (ARG_GMC)
1243                    xvid_enc_frame.motion |= XVID_ME_GME_REFINE;
1244    
1245            if (ARG_QPEL)
1246                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16;
1247            if (ARG_QPEL && (xvid_enc_frame.vop_flags & XVID_VOP_INTER4V))
1248                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8;
1249    
1250            if (ARG_TURBO)
1251                    xvid_enc_frame.motion |= XVID_ME_FASTREFINE16 | XVID_ME_FASTREFINE8 |
1252                                                                     XVID_ME_SKIP_DELTASEARCH | XVID_ME_FAST_MODEINTERPOLATE |
1253                                                                     XVID_ME_BFRAME_EARLYSTOP;
1254    
1255            if (ARG_BVHQ)
1256                    xvid_enc_frame.vop_flags |= XVID_VOP_RD_BVOP;
1257    
1258            switch (ARG_VHQMODE) /* this is the same code as for vfw */
1259            {
1260            case 1: /* VHQ_MODE_DECISION */
1261                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1262                    break;
1263    
1264            case 2: /* VHQ_LIMITED_SEARCH */
1265                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1266                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE16_RD;
1267                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;
1268                    break;
1269    
1270            case 3: /* VHQ_MEDIUM_SEARCH */
1271                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1272                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE16_RD;
1273                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE8_RD;
1274                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;
1275                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8_RD;
1276                    xvid_enc_frame.motion |= XVID_ME_CHECKPREDICTION_RD;
1277                    break;
1278    
1279            case 4: /* VHQ_WIDE_SEARCH */
1280                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1281                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE16_RD;
1282                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE8_RD;
1283                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;
1284                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8_RD;
1285                    xvid_enc_frame.motion |= XVID_ME_CHECKPREDICTION_RD;
1286                    xvid_enc_frame.motion |= XVID_ME_EXTSEARCH_RD;
1287                    break;
1288    
1289            default :
1290                    break;
1291            }
1292    
1293            if (ARG_QMATRIX) {
1294                    /* We don't use special matrices */
1295                    xvid_enc_frame.quant_intra_matrix = qmatrix_intra;
1296                    xvid_enc_frame.quant_inter_matrix = qmatrix_inter;
1297            }
1298            else {
1299          /* We don't use special matrices */          /* We don't use special matrices */
1300          xvid_enc_frame.quant_intra_matrix = NULL;          xvid_enc_frame.quant_intra_matrix = NULL;
1301          xvid_enc_frame.quant_inter_matrix = NULL;          xvid_enc_frame.quant_inter_matrix = NULL;
1302            }
1303    
1304          /* Encode the frame */          /* Encode the frame */
1305          ret =          ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
                 xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame,  
1306                                          &xvid_enc_stats);                                          &xvid_enc_stats);
1307    
1308          *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);          *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);

Legend:
Removed from v.1.11.2.20  
changed lines
  Added in v.1.21

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