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

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