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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1054 - (view) (download)

1 : edgomez 558 /*****************************************************************************
2 : chl 376 *
3 : edgomez 558 * XVID MPEG-4 VIDEO CODEC
4 :     * - Console based test application -
5 : chl 376 *
6 : edgomez 1054 * 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 : chl 376 *
10 : edgomez 558 * 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
12 :     * the Free Software Foundation; either version 2 of the License, or
13 :     * (at your option) any later version.
14 : chl 376 *
15 : edgomez 558 * This program is distributed in the hope that it will be useful,
16 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     * GNU General Public License for more details.
19 : chl 376 *
20 : edgomez 558 * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software
22 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 : edgomez 1054 * $Id: xvid_encraw.c,v 1.11.2.27 2003-06-09 13:49:25 edgomez Exp $
25 : edgomez 558 *
26 :     ****************************************************************************/
27 : chl 376
28 : edgomez 558 /*****************************************************************************
29 :     * Application notes :
30 : chl 376 *
31 : edgomez 918 * A sequence of raw YUV I420 pics or YUV I420 PGM file format is encoded
32 :     * The speed is measured and frames' PSNR are taken from core.
33 : chl 376 *
34 :     * The program is plain C and needs no libraries except for libxvidcore,
35 : edgomez 558 * and maths-lib.
36 : edgomez 1054 *
37 :     * Use ./xvid_encraw -help for a list of options
38 : chl 376 *
39 :     ************************************************************************/
40 :    
41 :     #include <stdio.h>
42 :     #include <stdlib.h>
43 : edgomez 566 #include <string.h>
44 : edgomez 558 #include <math.h>
45 : edgomez 851 #ifndef WIN32
46 : edgomez 558 #include <sys/time.h>
47 :     #else
48 :     #include <time.h>
49 :     #endif
50 : chl 376
51 : edgomez 558 #include "xvid.h"
52 : chl 376
53 : suxen_drol 920
54 : edgomez 558 /*****************************************************************************
55 :     * Quality presets
56 :     ****************************************************************************/
57 : edgomez 909 static xvid_motion_t const motion_presets[] = {
58 : edgomez 1013 /* quality 0 */
59 :     0,
60 : edgomez 558
61 : edgomez 1013 /* quality 1 */
62 :     XVID_ME_ADVANCEDDIAMOND16,
63 :    
64 :     /* quality 2 */
65 :     XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16,
66 :    
67 :     /* quality 3 */
68 :     XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
69 :     XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8,
70 :    
71 :     /* quality 4 */
72 :     XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
73 :     XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |
74 :     XVID_ME_CHROMA16 | XVID_ME_CHROMA8,
75 :    
76 :     /* quality 5 */
77 :     XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
78 :     XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |
79 :     XVID_ME_CHROMA16 | XVID_ME_CHROMA8,
80 :    
81 :     /* quality 6 */
82 :     XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |
83 :     XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 |
84 :     XVID_ME_CHROMA16 | XVID_ME_CHROMA8 ,
85 :    
86 : edgomez 558 };
87 : edgomez 1013 #define ME_ELEMENTS (sizeof(motion_presets)/sizeof(motion_presets[0]))
88 : chl 376
89 : edgomez 909 static xvid_vop_t const vop_presets[] = {
90 : edgomez 1013 /* quality 0 */
91 :     0,
92 :    
93 :     /* quality 1 */
94 : edgomez 1027 0,
95 : edgomez 1013
96 :     /* quality 2 */
97 : edgomez 1027 XVID_VOP_HALFPEL,
98 : edgomez 1013
99 :     /* quality 3 */
100 : edgomez 1027 XVID_VOP_HALFPEL | XVID_VOP_INTER4V,
101 : edgomez 1013
102 :     /* quality 4 */
103 : edgomez 1027 XVID_VOP_HALFPEL | XVID_VOP_INTER4V,
104 : edgomez 1013
105 :     /* quality 5 */
106 : edgomez 1027 XVID_VOP_HALFPEL | XVID_VOP_INTER4V |
107 :     XVID_VOP_TRELLISQUANT,
108 : edgomez 1013
109 :     /* quality 6 */
110 : edgomez 1027 XVID_VOP_HALFPEL | XVID_VOP_INTER4V |
111 :     XVID_VOP_TRELLISQUANT | XVID_VOP_HQACPRED,
112 : edgomez 1013
113 : edgomez 909 };
114 : edgomez 1013 #define VOP_ELEMENTS (sizeof(vop_presets)/sizeof(vop_presets[0]))
115 : edgomez 909
116 : edgomez 558 /*****************************************************************************
117 :     * Command line global variables
118 :     ****************************************************************************/
119 : chl 376
120 : suxen_drol 1019 #define MAX_ZONES 64
121 :    
122 :     static xvid_enc_zone_t ZONES[MAX_ZONES];
123 :     static int NUM_ZONES = 0;
124 :    
125 : edgomez 558 /* Maximum number of frames to encode */
126 :     #define ABS_MAXFRAMENR 9999
127 : chl 376
128 : edgomez 932 static int ARG_STATS = 0;
129 :     static int ARG_DUMP = 0;
130 :     static int ARG_LUMIMASKING = 0;
131 : suxen_drol 938 static int ARG_BITRATE = 0;
132 : suxen_drol 1019 static int ARG_SINGLE = 0;
133 : edgomez 944 static char *ARG_PASS1 = 0;
134 :     static char *ARG_PASS2 = 0;
135 : edgomez 1026 static int ARG_QUALITY = ME_ELEMENTS - 1;
136 : edgomez 558 static float ARG_FRAMERATE = 25.00f;
137 : edgomez 932 static int ARG_MAXFRAMENR = ABS_MAXFRAMENR;
138 : suxen_drol 1031 static int ARG_MAXKEYINTERVAL = 0;
139 : edgomez 558 static char *ARG_INPUTFILE = NULL;
140 : edgomez 932 static int ARG_INPUTTYPE = 0;
141 :     static int ARG_SAVEMPEGSTREAM = 0;
142 : edgomez 558 static char *ARG_OUTPUTFILE = NULL;
143 : edgomez 932 static int XDIM = 0;
144 :     static int YDIM = 0;
145 :     static int ARG_BQRATIO = 150;
146 :     static int ARG_BQOFFSET = 100;
147 :     static int ARG_MAXBFRAMES = 0;
148 :     static int ARG_PACKED = 0;
149 :     static int ARG_DEBUG = 0;
150 : suxen_drol 1031 static int ARG_VOPDEBUG = 0;
151 : edgomez 932
152 : edgomez 558 #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
153 : chl 376
154 : edgomez 558 #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
155 : edgomez 909 #define SMALL_EPS (1e-10)
156 : chl 376
157 : edgomez 558 #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \
158 :     (((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) )
159 : chl 376
160 : edgomez 558 /****************************************************************************
161 :     * Nasty global vars ;-)
162 :     ***************************************************************************/
163 : chl 376
164 : suxen_drol 920 static int i;
165 : chl 376
166 : edgomez 558 /* the path where to save output */
167 :     static char filepath[256] = "./";
168 : chl 376
169 : edgomez 558 /* Internal structures (handles) for encoding and decoding */
170 :     static void *enc_handle = NULL;
171 :    
172 :     /*****************************************************************************
173 :     * Local prototypes
174 :     ****************************************************************************/
175 :    
176 :     /* Prints program usage message */
177 :     static void usage();
178 :    
179 :     /* Statistical functions */
180 :     static double msecond();
181 :    
182 :     /* PGM related functions */
183 : edgomez 932 static int read_pgmheader(FILE * handle);
184 :     static int read_pgmdata(FILE * handle,
185 :     unsigned char *image);
186 :     static int read_yuvdata(FILE * handle,
187 :     unsigned char *image);
188 : edgomez 558
189 :     /* Encoder related functions */
190 :     static int enc_init(int use_assembler);
191 :     static int enc_stop();
192 : edgomez 932 static int enc_main(unsigned char *image,
193 :     unsigned char *bitstream,
194 :     int *key,
195 : suxen_drol 919 int *stats_type,
196 : edgomez 932 int *stats_quant,
197 :     int *stats_length,
198 : edgomez 913 int stats[3]);
199 : edgomez 558
200 :     /*****************************************************************************
201 :     * Main function
202 :     ****************************************************************************/
203 :    
204 : edgomez 932 int
205 :     main(int argc,
206 :     char *argv[])
207 : edgomez 558 {
208 :    
209 :     unsigned char *mp4_buffer = NULL;
210 :     unsigned char *in_buffer = NULL;
211 :     unsigned char *out_buffer = NULL;
212 :    
213 :     double enctime;
214 : edgomez 932 double totalenctime = 0.;
215 : chl 991 float totalPSNR[3] = {0., 0., 0.};
216 : edgomez 932
217 : suxen_drol 919 int totalsize;
218 : suxen_drol 920 int result;
219 : suxen_drol 919 int m4v_size;
220 : edgomez 932 int key;
221 : suxen_drol 919 int stats_type;
222 : edgomez 932 int stats_quant;
223 :     int stats_length;
224 :     int use_assembler = 0;
225 : suxen_drol 920
226 : edgomez 932 int input_num;
227 :     int output_num;
228 :    
229 : edgomez 558 char filename[256];
230 : edgomez 932
231 : edgomez 558 FILE *in_file = stdin;
232 :     FILE *out_file = NULL;
233 :    
234 : edgomez 741 printf("xvid_encraw - raw mpeg4 bitstream encoder ");
235 : edgomez 851 printf("written by Christoph Lampert 2002-2003\n\n");
236 : edgomez 558
237 : edgomez 1013 /* Is there a dumb XviD coder ? */
238 :     if(ME_ELEMENTS != VOP_ELEMENTS) {
239 :     fprintf(stderr, "Presets' arrays should have the same number of elements -- Please fill a bug to xvid-devel@xvid.org\n");
240 :     return(-1);
241 :     }
242 :    
243 : edgomez 558 /*****************************************************************************
244 :     * Command line parsing
245 :     ****************************************************************************/
246 :    
247 : edgomez 932 for (i = 1; i < argc; i++) {
248 :    
249 :     if (strcmp("-asm", argv[i]) == 0) {
250 : edgomez 558 use_assembler = 1;
251 : edgomez 932 } else if (strcmp("-w", argv[i]) == 0 && i < argc - 1) {
252 : edgomez 558 i++;
253 :     XDIM = atoi(argv[i]);
254 : edgomez 932 } else if (strcmp("-h", argv[i]) == 0 && i < argc - 1) {
255 : edgomez 558 i++;
256 :     YDIM = atoi(argv[i]);
257 : suxen_drol 1019 } else if (strcmp("-bitrate", argv[i]) == 0 && i < argc - 1) {
258 : edgomez 558 i++;
259 :     ARG_BITRATE = atoi(argv[i]);
260 : suxen_drol 1019 } else if (strcmp("-single", argv[i]) == 0) {
261 :     ARG_SINGLE = 1;
262 : suxen_drol 938 } else if (strcmp("-pass1", argv[i]) == 0 && i < argc - 1) {
263 :     i++;
264 :     ARG_PASS1 = argv[i];
265 : suxen_drol 1019 } else if (strcmp("-pass2", argv[i]) == 0 && i < argc - 1) {
266 : suxen_drol 942 i++;
267 : suxen_drol 977 ARG_PASS2 = argv[i];
268 : edgomez 932 } else if (strcmp("-max_bframes", argv[i]) == 0 && i < argc - 1) {
269 : edgomez 851 i++;
270 :     ARG_MAXBFRAMES = atoi(argv[i]);
271 : edgomez 932 } else if (strcmp("-packed", argv[i]) == 0) {
272 :     ARG_PACKED = 1;
273 :     } else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) {
274 : edgomez 851 i++;
275 :     ARG_BQRATIO = atoi(argv[i]);
276 : edgomez 932 } else if (strcmp("-bquant_offset", argv[i]) == 0 && i < argc - 1) {
277 : edgomez 851 i++;
278 :     ARG_BQOFFSET = atoi(argv[i]);
279 : suxen_drol 1019
280 :     } else if ((strcmp("-zq", argv[i]) == 0 || strcmp("-zw", argv[i]) == 0) && i < argc - 2) {
281 :    
282 :     if (NUM_ZONES >= MAX_ZONES) {
283 :     fprintf(stderr,"warning: too many zones; zone ignored\n");
284 :     continue;
285 :     }
286 :     ZONES[NUM_ZONES].mode = strcmp("-zq", argv[i])==0 ? XVID_ZONE_QUANT : XVID_ZONE_WEIGHT;
287 :     i++;
288 :     ZONES[NUM_ZONES].frame = atoi(argv[i]);
289 :     i++;
290 :     ZONES[NUM_ZONES].increment = (int)(atof(argv[i]) * 100);
291 :     ZONES[NUM_ZONES].base = 100;
292 :     NUM_ZONES++;
293 :    
294 : edgomez 932 } else if (strcmp("-quality", argv[i]) == 0 && i < argc - 1) {
295 : edgomez 558 i++;
296 :     ARG_QUALITY = atoi(argv[i]);
297 : edgomez 932 } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {
298 : edgomez 558 i++;
299 : edgomez 932 ARG_FRAMERATE = (float) atof(argv[i]);
300 : suxen_drol 1031 } else if (strcmp("-max_key_interval", argv[i]) == 0 && i < argc - 1) {
301 :     i++;
302 :     ARG_MAXKEYINTERVAL = atoi(argv[i]);
303 : edgomez 932 } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1) {
304 : edgomez 558 i++;
305 :     ARG_INPUTFILE = argv[i];
306 : edgomez 932 } else if (strcmp("-stats", argv[i]) == 0) {
307 : edgomez 916 ARG_STATS = 1;
308 : edgomez 932 } else if (strcmp("-dump", argv[i]) == 0) {
309 : suxen_drol 920 ARG_DUMP = 1;
310 : edgomez 932 } else if (strcmp("-lumimasking", argv[i]) == 0) {
311 : suxen_drol 926 ARG_LUMIMASKING = 1;
312 : edgomez 932 } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {
313 : edgomez 558 i++;
314 :     ARG_INPUTTYPE = atoi(argv[i]);
315 : edgomez 932 } else if (strcmp("-nframes", argv[i]) == 0 && i < argc - 1) {
316 : edgomez 558 i++;
317 : edgomez 932 ARG_MAXFRAMENR = atoi(argv[i]);
318 :     } else if (strcmp("-save", argv[i]) == 0) {
319 : edgomez 916 ARG_SAVEMPEGSTREAM = 1;
320 : edgomez 932 } else if (strcmp("-debug", argv[i]) == 0) {
321 : suxen_drol 1031 i++;
322 :     if (sscanf(argv[i],"0x%x", &ARG_DEBUG) || sscanf(argv[i],"%d", &ARG_DEBUG)) ;
323 : edgomez 932 } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {
324 : edgomez 558 i++;
325 :     ARG_OUTPUTFILE = argv[i];
326 : suxen_drol 1031 } else if (strcmp("-vop_debug", argv[i]) == 0) {
327 :     ARG_VOPDEBUG = 1;
328 : edgomez 932 } else if (strcmp("-help", argv[i])) {
329 : edgomez 558 usage();
330 : edgomez 932 return (0);
331 :     } else {
332 : edgomez 558 usage();
333 :     exit(-1);
334 :     }
335 : edgomez 932
336 : edgomez 558 }
337 : edgomez 932
338 : edgomez 558 /*****************************************************************************
339 :     * Arguments checking
340 :     ****************************************************************************/
341 :    
342 : edgomez 932 if (XDIM <= 0 || XDIM >= 2048 || YDIM <= 0 || YDIM >= 2048) {
343 :     fprintf(stderr,
344 :     "Trying to retreive width and height from PGM header\n");
345 :     ARG_INPUTTYPE = 1; /* pgm */
346 : edgomez 558 }
347 : edgomez 932
348 : edgomez 1013 if (ARG_QUALITY < 0 ) {
349 :     ARG_QUALITY = 0;
350 :     } else if (ARG_QUALITY >= ME_ELEMENTS) {
351 :     ARG_QUALITY = ME_ELEMENTS - 1;
352 : edgomez 558 }
353 :    
354 : edgomez 932 if (ARG_FRAMERATE <= 0) {
355 :     fprintf(stderr, "Wrong Framerate %s \n", argv[5]);
356 :     return (-1);
357 : edgomez 558 }
358 :    
359 : edgomez 932 if (ARG_MAXFRAMENR <= 0) {
360 :     fprintf(stderr, "Wrong number of frames\n");
361 :     return (-1);
362 : edgomez 558 }
363 :    
364 : edgomez 932 if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
365 : edgomez 558 in_file = stdin;
366 : edgomez 932 } else {
367 : edgomez 558
368 :     in_file = fopen(ARG_INPUTFILE, "rb");
369 :     if (in_file == NULL) {
370 :     fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
371 : edgomez 932 return (-1);
372 : edgomez 558 }
373 :     }
374 :    
375 :     if (ARG_INPUTTYPE) {
376 :     if (read_pgmheader(in_file)) {
377 : edgomez 932 fprintf(stderr,
378 :     "Wrong input format, I want YUV encapsulated in PGM\n");
379 :     return (-1);
380 : edgomez 558 }
381 :     }
382 :    
383 :     /* now we know the sizes, so allocate memory */
384 : edgomez 932 in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM, YDIM));
385 : edgomez 558 if (!in_buffer)
386 :     goto free_all_memory;
387 :    
388 :     /* this should really be enough memory ! */
389 : edgomez 932 mp4_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM, YDIM) * 2);
390 : edgomez 558 if (!mp4_buffer)
391 : edgomez 932 goto free_all_memory;
392 : edgomez 558
393 :     /*****************************************************************************
394 :     * XviD PART Start
395 :     ****************************************************************************/
396 :    
397 :    
398 : suxen_drol 920 result = enc_init(use_assembler);
399 : edgomez 932 if (result) {
400 : suxen_drol 920 fprintf(stderr, "Encore INIT problem, return value %d\n", result);
401 : edgomez 558 goto release_all;
402 :     }
403 :    
404 :     /*****************************************************************************
405 :     * Main loop
406 :     ****************************************************************************/
407 :    
408 : edgomez 851 if (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) {
409 : edgomez 561
410 : edgomez 932 if ((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) {
411 : edgomez 558 fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE);
412 :     goto release_all;
413 :     }
414 :    
415 : edgomez 932 } else {
416 : edgomez 558 out_file = NULL;
417 :     }
418 :    
419 :     /*****************************************************************************
420 :     * Encoding loop
421 :     ****************************************************************************/
422 :    
423 :     totalsize = 0;
424 :    
425 : edgomez 932 result = 0;
426 : suxen_drol 920
427 : edgomez 932 input_num = 0; /* input frame counter */
428 :     output_num = 0; /* output frame counter */
429 : suxen_drol 920
430 : edgomez 558 do {
431 :    
432 : edgomez 913 char *type;
433 : edgomez 932 int sse[3];
434 : edgomez 913
435 : edgomez 932 if (input_num >= ARG_MAXFRAMENR) {
436 :     result = 1;
437 :     }
438 : edgomez 558
439 : edgomez 932 if (!result) {
440 :     if (ARG_INPUTTYPE) {
441 :     /* read PGM data (YUV-format) */
442 :     result = read_pgmdata(in_file, in_buffer);
443 :     } else {
444 :     /* read raw data (YUV-format) */
445 :     result = read_yuvdata(in_file, in_buffer);
446 :     }
447 :     }
448 : suxen_drol 920
449 : edgomez 558 /*****************************************************************************
450 :     * Encode and decode this frame
451 :     ****************************************************************************/
452 :    
453 :     enctime = msecond();
454 : edgomez 932 m4v_size =
455 :     enc_main(!result ? in_buffer : 0, mp4_buffer, &key, &stats_type,
456 :     &stats_quant, &stats_length, sse);
457 : edgomez 558 enctime = msecond() - enctime;
458 :    
459 : edgomez 913 /* Write the Frame statistics */
460 : edgomez 932
461 : suxen_drol 1031 printf("%5d: key=%i, time= %6.0f, len= %7d", !result ? input_num : -1,
462 : edgomez 944 key, (float) enctime, (int) m4v_size);
463 : edgomez 851
464 : edgomez 932 if (stats_type > 0) { /* !XVID_TYPE_NOTHING */
465 : suxen_drol 919
466 : edgomez 932 switch (stats_type) {
467 :     case XVID_TYPE_IVOP:
468 :     type = "I";
469 :     break;
470 :     case XVID_TYPE_PVOP:
471 :     type = "P";
472 :     break;
473 :     case XVID_TYPE_BVOP:
474 :     type = "B";
475 :     break;
476 :     case XVID_TYPE_SVOP:
477 :     type = "S";
478 :     break;
479 :     default:
480 :     type = "U";
481 :     break;
482 :     }
483 : suxen_drol 919
484 : suxen_drol 1031 printf(" | type=%s, quant= %2d, len= %7d", type, stats_quant,
485 : edgomez 932 stats_length);
486 : suxen_drol 923
487 : edgomez 932 #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height)))))
488 : suxen_drol 923
489 : edgomez 932 if (ARG_STATS) {
490 :     printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f",
491 : edgomez 944 SSE2PSNR(sse[0], XDIM, YDIM), SSE2PSNR(sse[1], XDIM / 2,
492 :     YDIM / 2),
493 :     SSE2PSNR(sse[2], XDIM / 2, YDIM / 2));
494 : chl 991
495 :     totalPSNR[0] += SSE2PSNR(sse[0], XDIM, YDIM);
496 :     totalPSNR[1] += SSE2PSNR(sse[1], XDIM/2, YDIM/2);
497 :     totalPSNR[2] += SSE2PSNR(sse[2], XDIM/2, YDIM/2);
498 : edgomez 932 }
499 :    
500 : edgomez 916 }
501 : edgomez 932 #undef SSE2PSNR
502 :    
503 : edgomez 916 printf("\n");
504 :    
505 : edgomez 932 if (m4v_size < 0) {
506 :     break;
507 :     }
508 : suxen_drol 919
509 : edgomez 851 /* Update encoding time stats */
510 : edgomez 558 totalenctime += enctime;
511 :     totalsize += m4v_size;
512 :    
513 : edgomez 728 /*****************************************************************************
514 :     * Save stream to file
515 :     ****************************************************************************/
516 :    
517 : edgomez 932 if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {
518 : edgomez 558 /* Save single files */
519 :     if (out_file == NULL) {
520 : suxen_drol 920 sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
521 : edgomez 558 out_file = fopen(filename, "wb");
522 :     fwrite(mp4_buffer, m4v_size, 1, out_file);
523 :     fclose(out_file);
524 :     out_file = NULL;
525 : edgomez 932 output_num++;
526 :     } else {
527 : edgomez 558
528 :     /* Write mp4 data */
529 : edgomez 851 fwrite(mp4_buffer, 1, m4v_size, out_file);
530 : edgomez 558
531 :     }
532 :     }
533 :    
534 : suxen_drol 920 input_num++;
535 : edgomez 918
536 : edgomez 932 /* Read the header if it's pgm stream */
537 :     if (!result && ARG_INPUTTYPE)
538 : suxen_drol 920 result = read_pgmheader(in_file);
539 : edgomez 558
540 : suxen_drol 920 } while (1);
541 : edgomez 558
542 : edgomez 932
543 :    
544 : edgomez 558 /*****************************************************************************
545 :     * Calculate totals and averages for output, print results
546 :     ****************************************************************************/
547 : chl 376
548 : suxen_drol 926 printf("Tot: enctime(ms) =%7.2f, length(bytes) = %7d\n",
549 : edgomez 932 totalenctime, (int) totalsize);
550 : suxen_drol 926
551 : edgomez 932 if (input_num > 0) {
552 :     totalsize /= input_num;
553 :     totalenctime /= input_num;
554 : chl 991 totalPSNR[0] /= input_num;
555 :     totalPSNR[1] /= input_num;
556 :     totalPSNR[2] /= input_num;
557 : edgomez 932 } else {
558 :     totalsize = -1;
559 :     totalenctime = -1;
560 :     }
561 : chl 376
562 : edgomez 997 printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d",
563 : edgomez 932 totalenctime, 1000 / totalenctime, (int) totalsize);
564 : chl 991 if (ARG_STATS) {
565 : edgomez 997 printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f",
566 : chl 991 totalPSNR[0],totalPSNR[1],totalPSNR[2]);
567 :     }
568 :     printf("\n");
569 : chl 376
570 : edgomez 913
571 : edgomez 558 /*****************************************************************************
572 :     * XviD PART Stop
573 :     ****************************************************************************/
574 : chl 376
575 : edgomez 932 release_all:
576 : chl 376
577 : edgomez 932 if (enc_handle) {
578 : suxen_drol 920 result = enc_stop();
579 : edgomez 932 if (result)
580 :     fprintf(stderr, "Encore RELEASE problem return value %d\n",
581 :     result);
582 : edgomez 558 }
583 : chl 376
584 : edgomez 932 if (in_file)
585 : edgomez 728 fclose(in_file);
586 : edgomez 932 if (out_file)
587 : edgomez 558 fclose(out_file);
588 :    
589 : edgomez 932 free_all_memory:
590 : edgomez 558 free(out_buffer);
591 :     free(mp4_buffer);
592 :     free(in_buffer);
593 :    
594 : edgomez 932 return (0);
595 : edgomez 558
596 :     }
597 :    
598 :    
599 :     /*****************************************************************************
600 :     * "statistical" functions
601 :     *
602 :     * these are not needed for encoding or decoding, but for measuring
603 :     * time and quality, there in nothing specific to XviD in these
604 :     *
605 :     *****************************************************************************/
606 :    
607 :     /* Return time elapsed time in miliseconds since the program started */
608 : edgomez 932 static double
609 :     msecond()
610 :     {
611 : edgomez 824 #ifndef WIN32
612 : edgomez 932 struct timeval tv;
613 :    
614 : chl 376 gettimeofday(&tv, 0);
615 : edgomez 932 return (tv.tv_sec * 1.0e3 + tv.tv_usec * 1.0e-3);
616 : edgomez 558 #else
617 :     clock_t clk;
618 : edgomez 932
619 : edgomez 558 clk = clock();
620 : edgomez 932 return (clk * 1000 / CLOCKS_PER_SEC);
621 : edgomez 558 #endif
622 : chl 376 }
623 :    
624 : edgomez 558 /*****************************************************************************
625 :     * Usage message
626 :     *****************************************************************************/
627 : chl 376
628 : edgomez 932 static void
629 :     usage()
630 : edgomez 558 {
631 : edgomez 932 fprintf(stderr, "Usage : xvid_stat [OPTIONS]\n\n");
632 :     fprintf(stderr, "Input options:\n");
633 :     fprintf(stderr, " -i string : input filename (default=stdin)\n");
634 :     fprintf(stderr, " -type integer: input data type (yuv=0, pgm=1)\n");
635 :     fprintf(stderr, " -w integer: frame width ([1.2048])\n");
636 :     fprintf(stderr, " -h integer: frame height ([1.2048])\n");
637 :     fprintf(stderr, " -nframes integer: number of frames to encode\n");
638 :     fprintf(stderr, "\n");
639 :     fprintf(stderr, "Output options:\n");
640 :     fprintf(stderr, " -dump : save decoder output\n");
641 :     fprintf(stderr, " -save : save mpeg4 raw stream\n");
642 : edgomez 944 fprintf(stderr, " -o string: output filename\n");
643 : edgomez 932 fprintf(stderr, "\n");
644 : edgomez 944 fprintf(stderr, "BFrames options:\n");
645 : edgomez 932 fprintf(stderr, " -max_bframes integer: max bframes (default=0)\n");
646 :     fprintf(stderr, " -bquant_ratio integer: bframe quantizer ratio (default=150)\n");
647 :     fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (default=100)\n");
648 :     fprintf(stderr, "\n");
649 : edgomez 944 fprintf(stderr, "Rate control options:\n");
650 : edgomez 1034 fprintf(stderr, " -framerate float : target framerate (>0 | default=25.0)\n");
651 : suxen_drol 1019 fprintf(stderr, " -bitrate integer : target bitrate\n");
652 :     fprintf(stderr, " -single : single pass mode\n");
653 :     fprintf(stderr, " -pass1 filename : twopass mode (first pass)\n");
654 :     fprintf(stderr, " -pass2 filename : twopass mode (2nd pass)\n");
655 : edgomez 1026 fprintf(stderr, " -zq starting_frame float : bitrate zone; quant\n");
656 :     fprintf(stderr, " -zw starting_frame float : bitrate zone; weight\n");
657 : suxen_drol 1031 fprintf(stderr, " -max_key_interval integer : maximum keyframe interval\n");
658 :     fprintf(stderr, "\n");
659 : edgomez 932 fprintf(stderr, "Other options\n");
660 :     fprintf(stderr, " -asm : use assembly optmized code\n");
661 : edgomez 1013 fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1);
662 : edgomez 932 fprintf(stderr, " -packed : packed mode\n");
663 :     fprintf(stderr, " -lumimasking : use lumimasking algorithm\n");
664 :     fprintf(stderr, " -stats : print stats about encoded frames\n");
665 : edgomez 1034 fprintf(stderr, " -debug : activates xvidcore internal debugging output\n");
666 :     fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n");
667 : edgomez 932 fprintf(stderr, " -help : prints this help message\n");
668 : edgomez 1026 fprintf(stderr, "\n");
669 :     fprintf(stderr, "NB: You can define %d zones repeating the -z[qw] option as many times as needed.\n", MAX_ZONES);
670 :     fprintf(stderr, "\n");
671 : edgomez 558 }
672 :    
673 :     /*****************************************************************************
674 :     * Input and output functions
675 :     *
676 :     * the are small and simple routines to read and write PGM and YUV
677 :     * image. It's just for convenience, again nothing specific to XviD
678 :     *
679 :     *****************************************************************************/
680 :    
681 : edgomez 932 static int
682 :     read_pgmheader(FILE * handle)
683 :     {
684 :     int bytes, xsize, ysize, depth;
685 : chl 376 char dummy[2];
686 :    
687 : edgomez 932 bytes = fread(dummy, 1, 2, handle);
688 : edgomez 558
689 : edgomez 932 if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5'))
690 :     return (1);
691 :    
692 :     fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
693 :     if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) {
694 :     fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
695 :     return (2);
696 : chl 376 }
697 : edgomez 932 if ((XDIM == 0) || (YDIM == 0)) {
698 :     XDIM = xsize;
699 :     YDIM = ysize * 2 / 3;
700 : chl 376 }
701 :    
702 : edgomez 932 return (0);
703 : chl 376 }
704 :    
705 : edgomez 932 static int
706 :     read_pgmdata(FILE * handle,
707 :     unsigned char *image)
708 :     {
709 : edgomez 558 int i;
710 : chl 376 char dummy;
711 : edgomez 932
712 : edgomez 558 unsigned char *y = image;
713 : edgomez 932 unsigned char *u = image + XDIM * YDIM;
714 :     unsigned char *v = image + XDIM * YDIM + XDIM / 2 * YDIM / 2;
715 : chl 376
716 : edgomez 558 /* read Y component of picture */
717 : edgomez 932 fread(y, 1, XDIM * YDIM, handle);
718 :    
719 :     for (i = 0; i < YDIM / 2; i++) {
720 : edgomez 558 /* read U */
721 : edgomez 932 fread(u, 1, XDIM / 2, handle);
722 : edgomez 558
723 :     /* read V */
724 : edgomez 932 fread(v, 1, XDIM / 2, handle);
725 : edgomez 558
726 :     /* Update pointers */
727 : edgomez 932 u += XDIM / 2;
728 :     v += XDIM / 2;
729 : chl 376 }
730 : edgomez 558
731 : edgomez 932 /* I don't know why, but this seems needed */
732 : edgomez 558 fread(&dummy, 1, 1, handle);
733 :    
734 : edgomez 932 return (0);
735 : chl 376 }
736 :    
737 : edgomez 932 static int
738 :     read_yuvdata(FILE * handle,
739 :     unsigned char *image)
740 : edgomez 558 {
741 : edgomez 932
742 :     if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) !=
743 :     (unsigned int) IMAGE_SIZE(XDIM, YDIM))
744 :     return (1);
745 :     else
746 :     return (0);
747 : chl 376 }
748 :    
749 : edgomez 558 /*****************************************************************************
750 :     * Routines for encoding: init encoder, frame step, release encoder
751 :     ****************************************************************************/
752 : chl 376
753 : suxen_drol 919 /* sample plugin */
754 :    
755 : edgomez 932 int
756 :     rawenc_debug(void *handle,
757 :     int opt,
758 :     void *param1,
759 :     void *param2)
760 : suxen_drol 919 {
761 : edgomez 932 switch (opt) {
762 :     case XVID_PLG_INFO:
763 :     {
764 :     xvid_plg_info_t *info = (xvid_plg_info_t *) param1;
765 : suxen_drol 926
766 : edgomez 932 info->flags = XVID_REQDQUANTS;
767 :     return 0;
768 :     }
769 : suxen_drol 919
770 : edgomez 932 case XVID_PLG_CREATE:
771 :     case XVID_PLG_DESTROY:
772 :     case XVID_PLG_BEFORE:
773 :     return 0;
774 : suxen_drol 926
775 : edgomez 932 case XVID_PLG_AFTER:
776 :     {
777 :     xvid_plg_data_t *data = (xvid_plg_data_t *) param1;
778 :     int i, j;
779 : suxen_drol 919
780 : edgomez 932 printf("---[ frame: %5i quant: %2i length: %6i ]---\n",
781 :     data->frame_num, data->quant, data->length);
782 :     for (j = 0; j < data->mb_height; j++) {
783 :     for (i = 0; i < data->mb_width; i++)
784 :     printf("%2i ", data->dquant[j * data->dquant_stride + i]);
785 :     printf("\n");
786 :     }
787 :    
788 :     return 0;
789 :     }
790 :     }
791 :    
792 :     return XVID_ERR_FAIL;
793 : suxen_drol 919 }
794 :    
795 :    
796 : chl 376 #define FRAMERATE_INCR 1001
797 :    
798 : suxen_drol 938
799 : edgomez 558 /* Initialize encoder for first use, pass all needed parameters to the codec */
800 : edgomez 932 static int
801 :     enc_init(int use_assembler)
802 : edgomez 558 {
803 : chl 376 int xerr;
804 : suxen_drol 1019 //xvid_plugin_cbr_t cbr;
805 :     xvid_plugin_single_t single;
806 : edgomez 944 xvid_plugin_2pass1_t rc2pass1;
807 :     xvid_plugin_2pass2_t rc2pass2;
808 : suxen_drol 1019 //xvid_plugin_fixed_t rcfixed;
809 : edgomez 944 xvid_enc_plugin_t plugins[7];
810 : edgomez 932 xvid_gbl_init_t xvid_gbl_init;
811 : edgomez 909 xvid_enc_create_t xvid_enc_create;
812 : chl 376
813 : edgomez 909 /*------------------------------------------------------------------------
814 :     * XviD core initialization
815 :     *----------------------------------------------------------------------*/
816 :    
817 : edgomez 932 /* Set version -- version checking will done by xvidcore */
818 :     memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
819 : edgomez 909 xvid_gbl_init.version = XVID_VERSION;
820 : suxen_drol 1031 xvid_gbl_init.debug = ARG_DEBUG;
821 : edgomez 932
822 :    
823 : edgomez 909 /* Do we have to enable ASM optimizations ? */
824 : edgomez 932 if (use_assembler) {
825 : chl 376
826 : suxen_drol 860 #ifdef ARCH_IS_IA64
827 : edgomez 909 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;
828 : chl 376 #else
829 : edgomez 909 xvid_gbl_init.cpu_flags = 0;
830 : chl 376 #endif
831 : edgomez 932 } else {
832 : edgomez 909 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
833 : edgomez 558 }
834 : chl 376
835 : edgomez 909 /* Initialize XviD core -- Should be done once per __process__ */
836 :     xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
837 : chl 376
838 : edgomez 909 /*------------------------------------------------------------------------
839 :     * XviD encoder initialization
840 :     *----------------------------------------------------------------------*/
841 :    
842 :     /* Version again */
843 : edgomez 932 memset(&xvid_enc_create, 0, sizeof(xvid_enc_create));
844 : edgomez 909 xvid_enc_create.version = XVID_VERSION;
845 :    
846 :     /* Width and Height of input frames */
847 :     xvid_enc_create.width = XDIM;
848 :     xvid_enc_create.height = YDIM;
849 :    
850 : edgomez 932 /* init plugins */
851 : suxen_drol 1019 xvid_enc_create.zones = ZONES;
852 :     xvid_enc_create.num_zones = NUM_ZONES;
853 : suxen_drol 919
854 : edgomez 932 xvid_enc_create.plugins = plugins;
855 :     xvid_enc_create.num_plugins = 0;
856 : suxen_drol 926
857 : suxen_drol 1019 if (ARG_SINGLE) {
858 :     memset(&single, 0, sizeof(xvid_plugin_single_t));
859 :     single.version = XVID_VERSION;
860 :     single.bitrate = ARG_BITRATE;
861 : suxen_drol 938
862 : suxen_drol 1019 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
863 :     plugins[xvid_enc_create.num_plugins].param = &single;
864 : suxen_drol 938 xvid_enc_create.num_plugins++;
865 : edgomez 944 }
866 : suxen_drol 938
867 : suxen_drol 977 if (ARG_PASS2) {
868 : edgomez 988 memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t));
869 : edgomez 944 rc2pass2.version = XVID_VERSION;
870 : suxen_drol 977 rc2pass2.filename = ARG_PASS2;
871 : suxen_drol 1019 rc2pass2.bitrate = ARG_BITRATE;
872 : edgomez 944
873 :     plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
874 : suxen_drol 942 plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
875 :     xvid_enc_create.num_plugins++;
876 : suxen_drol 977 }
877 :    
878 :     if (ARG_PASS1) {
879 : edgomez 988 memset(&rc2pass1, 0, sizeof(xvid_plugin_2pass1_t));
880 : edgomez 944 rc2pass1.version = XVID_VERSION;
881 :     rc2pass1.filename = ARG_PASS1;
882 : suxen_drol 938
883 : edgomez 944 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass1;
884 : suxen_drol 938 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
885 :     xvid_enc_create.num_plugins++;
886 : edgomez 944 }
887 : suxen_drol 938
888 : edgomez 944 if (ARG_LUMIMASKING) {
889 : edgomez 932 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
890 :     plugins[xvid_enc_create.num_plugins].param = NULL;
891 :     xvid_enc_create.num_plugins++;
892 :     }
893 : suxen_drol 920
894 : edgomez 932 if (ARG_DUMP) {
895 :     plugins[xvid_enc_create.num_plugins].func = xvid_plugin_dump;
896 :     plugins[xvid_enc_create.num_plugins].param = NULL;
897 :     xvid_enc_create.num_plugins++;
898 :     }
899 : suxen_drol 926
900 : edgomez 1034 #if 0
901 :     if (ARG_DEBUG) {
902 : edgomez 932 plugins[xvid_enc_create.num_plugins].func = rawenc_debug;
903 :     plugins[xvid_enc_create.num_plugins].param = NULL;
904 :     xvid_enc_create.num_plugins++;
905 : edgomez 1034 }
906 :     #endif
907 : edgomez 932
908 : edgomez 909 /* No fancy thread tests */
909 :     xvid_enc_create.num_threads = 0;
910 :    
911 :     /* Frame rate - Do some quick float fps = fincr/fbase hack */
912 : edgomez 932 if ((ARG_FRAMERATE - (int) ARG_FRAMERATE) < SMALL_EPS) {
913 : edgomez 909 xvid_enc_create.fincr = 1;
914 : edgomez 932 xvid_enc_create.fbase = (int) ARG_FRAMERATE;
915 : edgomez 909 } else {
916 :     xvid_enc_create.fincr = FRAMERATE_INCR;
917 : edgomez 932 xvid_enc_create.fbase = (int) (FRAMERATE_INCR * ARG_FRAMERATE);
918 : chl 376 }
919 :    
920 : edgomez 909 /* Maximum key frame interval */
921 : suxen_drol 1031 if (ARG_MAXKEYINTERVAL > 0) {
922 :     xvid_enc_create.max_key_interval = ARG_MAXKEYINTERVAL;
923 :     }else {
924 :     xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10;
925 :     }
926 :    
927 : edgomez 909 /* Bframes settings */
928 :     xvid_enc_create.max_bframes = ARG_MAXBFRAMES;
929 :     xvid_enc_create.bquant_ratio = ARG_BQRATIO;
930 : edgomez 932 xvid_enc_create.bquant_offset = ARG_BQOFFSET;
931 : edgomez 909
932 :     /* Dropping ratio frame -- we don't need that */
933 :     xvid_enc_create.frame_drop_ratio = 0;
934 :    
935 :     /* Global encoder options */
936 : suxen_drol 919 xvid_enc_create.global = 0;
937 : edgomez 909
938 : edgomez 944 if (ARG_PACKED)
939 : edgomez 949 xvid_enc_create.global |=XVID_GLOBAL_PACKED;
940 : edgomez 944
941 :     if (ARG_STATS)
942 : edgomez 949 xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;
943 : edgomez 944
944 : edgomez 558 /* I use a small value here, since will not encode whole movies, but short clips */
945 : edgomez 909 xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
946 : chl 376
947 : edgomez 909 /* Retrieve the encoder instance from the structure */
948 :     enc_handle = xvid_enc_create.handle;
949 : chl 376
950 : edgomez 932 return (xerr);
951 : chl 376 }
952 :    
953 : edgomez 932 static int
954 :     enc_stop()
955 : edgomez 558 {
956 :     int xerr;
957 : chl 376
958 : edgomez 909 /* Destroy the encoder instance */
959 : chl 376 xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL);
960 : edgomez 558
961 : edgomez 932 return (xerr);
962 : chl 376 }
963 :    
964 : edgomez 932 static int
965 :     enc_main(unsigned char *image,
966 :     unsigned char *bitstream,
967 :     int *key,
968 :     int *stats_type,
969 :     int *stats_quant,
970 :     int *stats_length,
971 :     int sse[3])
972 : edgomez 558 {
973 : edgomez 909 int ret;
974 : chl 376
975 : edgomez 909 xvid_enc_frame_t xvid_enc_frame;
976 : suxen_drol 919 xvid_enc_stats_t xvid_enc_stats;
977 : chl 376
978 : edgomez 909 /* Version for the frame and the stats */
979 : edgomez 932 memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame));
980 : edgomez 909 xvid_enc_frame.version = XVID_VERSION;
981 : edgomez 932
982 :     memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats));
983 : suxen_drol 919 xvid_enc_stats.version = XVID_VERSION;
984 : edgomez 932
985 : edgomez 909 /* Bind output buffer */
986 :     xvid_enc_frame.bitstream = bitstream;
987 :     xvid_enc_frame.length = -1;
988 : chl 376
989 : edgomez 909 /* Initialize input image fields */
990 : edgomez 932 if (image) {
991 :     xvid_enc_frame.input.plane[0] = image;
992 :     xvid_enc_frame.input.csp = XVID_CSP_I420;
993 :     xvid_enc_frame.input.stride[0] = XDIM;
994 :     } else {
995 :     xvid_enc_frame.input.csp = XVID_CSP_NULL;
996 :     }
997 : chl 376
998 : edgomez 909 /* Set up core's general features */
999 : edgomez 1013 xvid_enc_frame.vol_flags = 0;
1000 : edgomez 932 if (ARG_STATS)
1001 : edgomez 949 xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS;
1002 : chl 376
1003 : edgomez 909 /* Set up core's general features */
1004 :     xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
1005 : suxen_drol 1031 if (ARG_VOPDEBUG) {
1006 :     xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG;
1007 :     }
1008 : edgomez 728
1009 : edgomez 909 /* Frame type -- let core decide for us */
1010 : edgomez 932 xvid_enc_frame.type = XVID_TYPE_AUTO;
1011 : edgomez 728
1012 : edgomez 944 /* Force the right quantizer -- It is internally managed by RC plugins */
1013 :     xvid_enc_frame.quant = 0;
1014 : edgomez 932
1015 : edgomez 909 /* Set up motion estimation flags */
1016 :     xvid_enc_frame.motion = motion_presets[ARG_QUALITY];
1017 : edgomez 728
1018 : edgomez 909 /* We don't use special matrices */
1019 :     xvid_enc_frame.quant_intra_matrix = NULL;
1020 :     xvid_enc_frame.quant_inter_matrix = NULL;
1021 : chl 376
1022 : edgomez 913 /* Encode the frame */
1023 : edgomez 932 ret =
1024 :     xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
1025 :     &xvid_enc_stats);
1026 : edgomez 728
1027 : edgomez 932 *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);
1028 : suxen_drol 919 *stats_type = xvid_enc_stats.type;
1029 : edgomez 932 *stats_quant = xvid_enc_stats.quant;
1030 :     *stats_length = xvid_enc_stats.length;
1031 :     sse[0] = xvid_enc_stats.sse_y;
1032 :     sse[1] = xvid_enc_stats.sse_u;
1033 :     sse[2] = xvid_enc_stats.sse_v;
1034 : chl 376
1035 : edgomez 932 return (ret);
1036 : chl 376 }

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