1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC - Example for encoding and decoding |
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Console based test application - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Christoph Lampert |
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
17 |
* |
* |
18 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
*************************************************************************/ |
* $Id: xvid_encraw.c,v 1.5 2002-11-27 21:09:10 edgomez Exp $ |
|
|
|
|
/************************************************************************ |
|
23 |
* |
* |
24 |
* Speed test routine for XviD using the XviD-API |
****************************************************************************/ |
25 |
* (C) Christoph Lampert, 2002/08/17 |
|
26 |
|
/***************************************************************************** |
27 |
|
* Application notes : |
28 |
* |
* |
29 |
* A sequence of YUV pics in PGM or RAW file format is encoded and the |
* A sequence of YUV pics in PGM file format is encoded and decoded |
30 |
* raw MPEG-4 stream is written to stdout. |
* The speed is measured and PSNR of decoded picture is calculated. |
|
* The encoding speed of this is measured, too. |
|
31 |
* |
* |
32 |
* The program is plain C and needs no libraries except for libxvidcore, |
* The program is plain C and needs no libraries except for libxvidcore, |
33 |
* and maths-lib, so with UN*X you simply compile by |
* and maths-lib. |
|
* |
|
|
* gcc xvid_encraw.c -lxvidcore -lm -o xvid_encraw |
|
|
* |
|
|
* Run without or with illegal parameters, then PGM input input is read |
|
|
* from stdin. |
|
|
* |
|
|
* Parameters are: xvid_stat XDIM YDIM QUALITY BITRATE/QUANTIZER FRAMERATE |
|
|
* |
|
|
* if XDIM or YDIM are illegal (e.g. 0), they are ignored and input is |
|
|
* considered to be PGM. Otherwise (X and Y both greater than 0) raw YUV |
|
|
* is expected, as e.g. the standard MPEG test-files, like "foreman" |
|
|
* |
|
|
* 0 <= QUALITY <= 6 (default 5) |
|
|
* |
|
|
* BITRATE is in kbps (default 900), |
|
|
* if BITRATE<32, then value is taken is fixed QUANTIZER |
|
|
* |
|
|
* FRAMERATE is a float (with or without decimal dot), default is 25.00 |
|
|
* |
|
|
* input/output and m4v-output is saved, if corresponding flags are set |
|
|
* |
|
|
* PGM input must in a very specific format, see read_pgmheader |
|
|
* it can be generated e.g. from MPEG2 by mpeg2dec -o pgmpipe |
|
|
* |
|
|
************************************************************************/ |
|
|
|
|
|
/************************************************************************ |
|
|
* |
|
|
* For EXAMPLES how to use this, see the seperate file xvid_stat.examples |
|
34 |
* |
* |
35 |
************************************************************************/ |
************************************************************************/ |
36 |
|
|
37 |
#include <stdio.h> |
#include <stdio.h> |
38 |
#include <stdlib.h> |
#include <stdlib.h> |
39 |
#include <math.h> // needed for log10 |
#include <string.h> |
40 |
#include <sys/time.h> // only needed for gettimeofday |
#include <math.h> |
41 |
|
#ifndef _MSC_VER |
42 |
|
#include <sys/time.h> |
43 |
|
#else |
44 |
|
#include <time.h> |
45 |
|
#endif |
46 |
|
|
47 |
#include "../src/xvid.h" /* comes with XviD */ |
#include "xvid.h" |
48 |
|
|
49 |
|
/***************************************************************************** |
50 |
|
* Quality presets |
51 |
|
****************************************************************************/ |
52 |
|
|
53 |
|
static int const motion_presets[7] = { |
54 |
|
0, /* Q 0 */ |
55 |
|
PMV_EARLYSTOP16, /* Q 1 */ |
56 |
|
PMV_EARLYSTOP16, /* Q 2 */ |
57 |
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, /* Q 3 */ |
58 |
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, /* Q 4 */ |
59 |
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | /* Q 5 */ |
60 |
|
PMV_HALFPELREFINE8, |
61 |
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | /* Q 6 */ |
62 |
|
PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
63 |
|
}; |
64 |
|
|
65 |
int motion_presets[7] = { |
static int const general_presets[7] = { |
66 |
0, // Q 0 |
XVID_H263QUANT, /* Q 0 */ |
67 |
PMV_EARLYSTOP16, // Q 1 |
XVID_MPEGQUANT, /* Q 1 */ |
68 |
PMV_EARLYSTOP16, // Q 2 |
XVID_H263QUANT, /* Q 2 */ |
69 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 |
XVID_H263QUANT | XVID_HALFPEL, /* Q 3 */ |
70 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 4 */ |
71 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 5 */ |
72 |
| PMV_HALFPELREFINE8, |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V /* Q 6 */ |
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 // Q 6 |
|
|
| PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
|
73 |
}; |
}; |
74 |
|
|
|
int general_presets[7] = { |
|
|
XVID_H263QUANT, /* or use XVID_MPEGQUANT */ // Q 0 |
|
|
XVID_MPEGQUANT, // Q 1 |
|
|
XVID_H263QUANT, // Q 2 |
|
|
XVID_H263QUANT | XVID_HALFPEL, // Q 3 |
|
|
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 |
|
|
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5 |
|
|
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V }; // Q 6 |
|
75 |
|
|
76 |
|
/***************************************************************************** |
77 |
|
* Command line global variables |
78 |
|
****************************************************************************/ |
79 |
|
|
80 |
|
/* Maximum number of frames to encode */ |
81 |
|
#define ABS_MAXFRAMENR 9999 |
82 |
|
|
83 |
|
static int ARG_BITRATE = 900; |
84 |
|
static int ARG_QUANTI = 0; |
85 |
|
static int ARG_QUALITY = 6; |
86 |
|
static int ARG_MINQUANT = 1; |
87 |
|
static int ARG_MAXQUANT = 31; |
88 |
|
static float ARG_FRAMERATE = 25.00f; |
89 |
|
static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; |
90 |
|
static char *ARG_INPUTFILE = NULL; |
91 |
|
static int ARG_INPUTTYPE = 0; |
92 |
|
static int ARG_SAVEMPEGSTREAM = 0; |
93 |
|
static int ARG_OUTPUTTYPE = 0; |
94 |
|
static char *ARG_OUTPUTFILE = NULL; |
95 |
|
static int XDIM = 0; |
96 |
|
static int YDIM = 0; |
97 |
|
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
98 |
|
|
99 |
/* my default values for encoding */ |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
100 |
|
#define SMALL_EPS 1e-10 |
101 |
|
|
102 |
#define ABS_MAXFRAMENR 9999 // max number of frames |
#define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \ |
103 |
|
(((long)(c))<<8) |((long)(d))) |
104 |
|
|
105 |
int ARG_BITRATE=900; |
#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ |
106 |
int ARG_QUANTI=0; |
(((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) |
107 |
|
|
108 |
int ARG_QUALITY =6; |
/**************************************************************************** |
109 |
int ARG_MINQUANT=1; |
* Nasty global vars ;-) |
110 |
int ARG_MAXQUANT=31; |
***************************************************************************/ |
|
float ARG_FRAMERATE=25.00; |
|
111 |
|
|
112 |
int ARG_MAXFRAMENR=ABS_MAXFRAMENR; |
static int i,filenr = 0; |
113 |
|
|
114 |
#ifdef BFRAMES |
/* the path where to save output */ |
115 |
|
static char filepath[256] = "./"; |
116 |
|
|
117 |
int ARG_MAXBFRAMES=1; |
/* Internal structures (handles) for encoding and decoding */ |
118 |
int ARG_BQUANTRATIO=200; |
static void *enc_handle = NULL; |
119 |
|
|
120 |
#endif |
/***************************************************************************** |
121 |
|
* Local prototypes |
122 |
|
****************************************************************************/ |
123 |
|
|
124 |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
/* Prints program usage message */ |
125 |
#define SMALL_EPS 1e-10 |
static void usage(); |
126 |
|
|
127 |
|
/* Statistical functions */ |
128 |
|
static double msecond(); |
129 |
|
|
130 |
|
/* PGM related functions */ |
131 |
|
static int read_pgmheader(FILE* handle); |
132 |
|
static int read_pgmdata(FILE* handle, unsigned char *image); |
133 |
|
static int read_yuvdata(FILE* handle, unsigned char *image); |
134 |
|
|
135 |
|
/* Encoder related functions */ |
136 |
|
static int enc_init(int use_assembler); |
137 |
|
static int enc_stop(); |
138 |
|
static int enc_main(unsigned char* image, unsigned char* bitstream, |
139 |
|
int *streamlength, int* frametype); |
140 |
|
|
141 |
|
/***************************************************************************** |
142 |
|
* Main function |
143 |
|
****************************************************************************/ |
144 |
|
|
145 |
|
int main(int argc, char *argv[]) |
146 |
|
{ |
147 |
|
|
148 |
|
unsigned char *mp4_buffer = NULL; |
149 |
|
unsigned char *in_buffer = NULL; |
150 |
|
unsigned char *out_buffer = NULL; |
151 |
|
|
152 |
|
double enctime; |
153 |
|
double totalenctime=0.; |
154 |
|
|
155 |
|
long totalsize; |
156 |
|
int status; |
157 |
|
int frame_type; |
158 |
|
int bigendian; |
159 |
|
|
160 |
|
int m4v_size; |
161 |
|
int use_assembler=0; |
162 |
|
|
163 |
|
char filename[256]; |
164 |
|
|
165 |
|
FILE *in_file = stdin; |
166 |
|
FILE *out_file = NULL; |
167 |
|
|
168 |
|
printf("xvid_decraw - raw mpeg4 bitstream encoder "); |
169 |
|
printf("written by Christoph Lampert 2002\n\n"); |
170 |
|
|
171 |
|
/***************************************************************************** |
172 |
|
* Command line parsing |
173 |
|
****************************************************************************/ |
174 |
|
|
175 |
|
for (i=1; i< argc; i++) { |
176 |
|
|
177 |
|
if (strcmp("-asm", argv[i]) == 0 ) { |
178 |
|
use_assembler = 1; |
179 |
|
} |
180 |
|
else if (strcmp("-w", argv[i]) == 0 && i < argc - 1 ) { |
181 |
|
i++; |
182 |
|
XDIM = atoi(argv[i]); |
183 |
|
} |
184 |
|
else if (strcmp("-h", argv[i]) == 0 && i < argc - 1 ) { |
185 |
|
i++; |
186 |
|
YDIM = atoi(argv[i]); |
187 |
|
} |
188 |
|
else if (strcmp("-b", argv[i]) == 0 && i < argc - 1 ) { |
189 |
|
i++; |
190 |
|
ARG_BITRATE = atoi(argv[i]); |
191 |
|
} |
192 |
|
else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { |
193 |
|
i++; |
194 |
|
ARG_QUALITY = atoi(argv[i]); |
195 |
|
} |
196 |
|
else if (strcmp("-f", argv[i]) == 0 && i < argc - 1 ) { |
197 |
|
i++; |
198 |
|
ARG_FRAMERATE = (float)atof(argv[i]); |
199 |
|
} |
200 |
|
else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) { |
201 |
|
i++; |
202 |
|
ARG_INPUTFILE = argv[i]; |
203 |
|
} |
204 |
|
else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) { |
205 |
|
i++; |
206 |
|
ARG_INPUTTYPE = atoi(argv[i]); |
207 |
|
} |
208 |
|
else if(strcmp("-n", argv[i]) == 0 && i < argc - 1 ) { |
209 |
|
i++; |
210 |
|
ARG_MAXFRAMENR = atoi(argv[i]); |
211 |
|
} |
212 |
|
else if (strcmp("-quant", argv[i]) == 0 && i < argc - 1 ) { |
213 |
|
i++; |
214 |
|
ARG_QUANTI = atoi(argv[i]); |
215 |
|
} |
216 |
|
else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) { |
217 |
|
i++; |
218 |
|
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
219 |
|
} |
220 |
|
else if (strcmp("-mt", argv[i]) == 0 && i < argc - 1 ) { |
221 |
|
i++; |
222 |
|
ARG_OUTPUTTYPE = atoi(argv[i]); |
223 |
|
} |
224 |
|
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
225 |
|
i++; |
226 |
|
ARG_OUTPUTFILE = argv[i]; |
227 |
|
} |
228 |
|
else if (strcmp("-help", argv[i])) { |
229 |
|
usage(); |
230 |
|
return(0); |
231 |
|
} |
232 |
|
else { |
233 |
|
usage(); |
234 |
|
exit(-1); |
235 |
|
} |
236 |
|
|
237 |
|
} |
238 |
|
|
239 |
|
/***************************************************************************** |
240 |
|
* Arguments checking |
241 |
|
****************************************************************************/ |
242 |
|
|
243 |
|
if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) { |
244 |
|
fprintf(stderr, "Trying to retreive width and height from PGM header\n"); |
245 |
|
ARG_INPUTTYPE = 1; /* pgm */ |
246 |
|
} |
247 |
|
|
248 |
|
if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) { |
249 |
|
fprintf(stderr,"Wrong Quality\n"); |
250 |
|
return -1; |
251 |
|
} |
252 |
|
|
253 |
|
if ( ARG_BITRATE <= 0 && ARG_QUANTI == 0) { |
254 |
|
fprintf(stderr,"Wrong Bitrate\n"); |
255 |
|
return -1; |
256 |
|
} |
257 |
|
|
258 |
|
if ( ARG_FRAMERATE <= 0) { |
259 |
|
fprintf(stderr,"Wrong Framerate %s \n",argv[5]); |
260 |
|
return -1; |
261 |
|
} |
262 |
|
|
263 |
|
if ( ARG_MAXFRAMENR <= 0) { |
264 |
|
fprintf(stderr,"Wrong number of frames\n"); |
265 |
|
return -1; |
266 |
|
} |
267 |
|
|
268 |
|
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
269 |
|
in_file = stdin; |
270 |
|
} |
271 |
|
else { |
272 |
|
|
273 |
|
in_file = fopen(ARG_INPUTFILE, "rb"); |
274 |
|
if (in_file == NULL) { |
275 |
|
fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE); |
276 |
|
return -1; |
277 |
|
} |
278 |
|
} |
279 |
|
|
280 |
|
if (ARG_INPUTTYPE) { |
281 |
|
if (read_pgmheader(in_file)) { |
282 |
|
fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n"); |
283 |
|
return -1; |
284 |
|
} |
285 |
|
} |
286 |
|
|
287 |
|
/* now we know the sizes, so allocate memory */ |
288 |
|
|
289 |
|
in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); |
290 |
|
if (!in_buffer) |
291 |
|
goto free_all_memory; |
292 |
|
|
293 |
|
/* this should really be enough memory ! */ |
294 |
|
mp4_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*2); |
295 |
|
if (!mp4_buffer) |
296 |
|
goto free_all_memory; |
297 |
|
|
298 |
|
/***************************************************************************** |
299 |
|
* XviD PART Start |
300 |
|
****************************************************************************/ |
301 |
|
|
302 |
|
|
303 |
|
status = enc_init(use_assembler); |
304 |
|
if (status) |
305 |
|
{ |
306 |
|
fprintf(stderr, "Encore INIT problem, return value %d\n", status); |
307 |
|
goto release_all; |
308 |
|
} |
309 |
|
|
310 |
|
/***************************************************************************** |
311 |
|
* Main loop |
312 |
|
****************************************************************************/ |
313 |
|
|
314 |
|
totalsize = LONG_PACK('M','P','4','U'); |
315 |
|
if(*((char *)(&totalsize)) == 'M') |
316 |
|
bigendian = 1; |
317 |
|
else |
318 |
|
bigendian = 0; |
319 |
|
|
320 |
|
if (ARG_SAVEMPEGSTREAM && (ARG_OUTPUTTYPE || ARG_OUTPUTFILE)) { |
321 |
|
|
322 |
|
if (ARG_OUTPUTFILE == NULL && ARG_OUTPUTTYPE) |
323 |
|
ARG_OUTPUTFILE = "stream.mp4u"; |
324 |
|
else if(ARG_OUTPUTFILE == NULL && !ARG_OUTPUTTYPE) |
325 |
|
ARG_OUTPUTFILE = "stream.m4v"; |
326 |
|
|
327 |
|
if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) { |
328 |
|
fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE); |
329 |
|
goto release_all; |
330 |
|
} |
331 |
|
|
332 |
|
/* Write header */ |
333 |
|
if (ARG_OUTPUTTYPE) { |
334 |
|
|
335 |
|
long test = LONG_PACK('M','P','4','U'); |
336 |
|
|
337 |
|
test = (!bigendian)?SWAP(test):test; |
338 |
|
|
339 |
|
fwrite(&test, sizeof(test), 1, out_file); |
340 |
|
|
341 |
|
} |
342 |
|
|
343 |
|
} |
344 |
|
else { |
345 |
|
out_file = NULL; |
346 |
|
} |
347 |
|
|
348 |
|
/***************************************************************************** |
349 |
|
* Encoding loop |
350 |
|
****************************************************************************/ |
351 |
|
|
352 |
|
totalsize = 0; |
353 |
|
|
354 |
|
do { |
355 |
|
|
356 |
|
if (ARG_INPUTTYPE) |
357 |
|
status = read_pgmdata(in_file, in_buffer); /* read PGM data (YUV-format) */ |
358 |
|
else |
359 |
|
status = read_yuvdata(in_file, in_buffer); /* read raw data (YUV-format) */ |
360 |
|
|
361 |
|
if (status) |
362 |
|
{ |
363 |
|
/* Couldn't read image, most likely end-of-file */ |
364 |
|
continue; |
365 |
|
} |
366 |
|
|
367 |
|
/***************************************************************************** |
368 |
|
* Encode and decode this frame |
369 |
|
****************************************************************************/ |
370 |
|
|
371 |
|
enctime = msecond(); |
372 |
|
status = enc_main(in_buffer, mp4_buffer, &m4v_size, &frame_type); |
373 |
|
enctime = msecond() - enctime; |
374 |
|
|
375 |
|
totalenctime += enctime; |
376 |
|
totalsize += m4v_size; |
377 |
|
|
378 |
|
printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6dbytes\n", |
379 |
|
(int)filenr, (int)frame_type, (float)enctime, (int)m4v_size); |
380 |
|
|
381 |
|
if (ARG_SAVEMPEGSTREAM) |
382 |
|
{ |
383 |
|
/* Save single files */ |
384 |
|
if (out_file == NULL) { |
385 |
|
sprintf(filename, "%sframe%05d.m4v", filepath, filenr); |
386 |
|
out_file = fopen(filename, "wb"); |
387 |
|
fwrite(mp4_buffer, m4v_size, 1, out_file); |
388 |
|
fclose(out_file); |
389 |
|
out_file = NULL; |
390 |
|
} |
391 |
|
else { |
392 |
|
/* Using mp4u container */ |
393 |
|
if (ARG_OUTPUTTYPE) { |
394 |
|
long size = m4v_size; |
395 |
|
size = (!bigendian)?SWAP(size):size; |
396 |
|
fwrite(&size, sizeof(size), 1, out_file); |
397 |
|
} |
398 |
|
|
399 |
|
/* Write mp4 data */ |
400 |
|
fwrite(mp4_buffer, m4v_size, 1, out_file); |
401 |
|
|
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
/* Read the header if it's pgm stream */ |
406 |
|
if (ARG_INPUTTYPE) |
407 |
|
status = read_pgmheader(in_file); |
408 |
|
|
409 |
|
filenr++; |
410 |
|
|
411 |
|
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
412 |
|
|
|
/* these are global variables. Not very elegant, but easy, and this is an easy program */ |
|
413 |
|
|
|
int XDIM=0; |
|
|
int YDIM=0; // will be set when reading first image |
|
|
int i,filenr = 0; |
|
414 |
|
|
415 |
int save_m4v_flag = 1; // output MPEG4-bytestream? |
/***************************************************************************** |
416 |
int save_ref_flag = 0; // save input image |
* Calculate totals and averages for output, print results |
417 |
|
****************************************************************************/ |
418 |
|
|
419 |
int pgmflag = 0; // a flag, if input is in PGM format, overwritten in init-phase |
totalsize /= filenr; |
420 |
char filepath[256] = "./"; // the path where to save output |
totalenctime /= filenr; |
421 |
|
|
422 |
void *enc_handle = NULL; // internal structures (handles) for encoding |
printf("Avg: enctime %5.2f ms, %5.2f fps, filesize %7d bytes\n", |
423 |
|
totalenctime, 1000/totalenctime, (int)totalsize); |
424 |
|
|
425 |
|
/***************************************************************************** |
426 |
|
* XviD PART Stop |
427 |
|
****************************************************************************/ |
428 |
|
|
429 |
/*********************************************************************/ |
release_all: |
|
/* "statistical" functions */ |
|
|
/* */ |
|
|
/* these are not needed for encoding or decoding, but for measuring */ |
|
|
/* time and quality, there in nothing specific to XviD in these */ |
|
|
/* */ |
|
|
/*********************************************************************/ |
|
430 |
|
|
431 |
double msecond() |
if (enc_handle) |
|
/* return the current time in seconds(!) */ |
|
432 |
{ |
{ |
433 |
|
status = enc_stop(); |
434 |
|
if (status) |
435 |
|
fprintf(stderr, "Encore RELEASE problem return value %d\n", status); |
436 |
|
} |
437 |
|
|
438 |
|
fclose(in_file); |
439 |
|
if(out_file) |
440 |
|
fclose(out_file); |
441 |
|
|
442 |
|
free_all_memory: |
443 |
|
free(out_buffer); |
444 |
|
free(mp4_buffer); |
445 |
|
free(in_buffer); |
446 |
|
|
447 |
|
return 0; |
448 |
|
|
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
/***************************************************************************** |
453 |
|
* "statistical" functions |
454 |
|
* |
455 |
|
* these are not needed for encoding or decoding, but for measuring |
456 |
|
* time and quality, there in nothing specific to XviD in these |
457 |
|
* |
458 |
|
*****************************************************************************/ |
459 |
|
|
460 |
|
/* Return time elapsed time in miliseconds since the program started */ |
461 |
|
static double msecond() |
462 |
|
{ |
463 |
|
#ifndef _MSC_VER |
464 |
struct timeval tv; |
struct timeval tv; |
465 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
466 |
return tv.tv_sec + tv.tv_usec * 1.0e-6; |
return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3; |
467 |
|
#else |
468 |
|
clock_t clk; |
469 |
|
clk = clock(); |
470 |
|
return clk * 1000 / CLOCKS_PER_SEC; |
471 |
|
#endif |
472 |
|
} |
473 |
|
|
474 |
|
/***************************************************************************** |
475 |
|
* Usage message |
476 |
|
*****************************************************************************/ |
477 |
|
|
478 |
|
static void usage() |
479 |
|
{ |
480 |
|
|
481 |
|
fprintf(stderr, "Usage : xvid_stat [OPTIONS]\n"); |
482 |
|
fprintf(stderr, "Options :\n"); |
483 |
|
fprintf(stderr, " -w integer : frame width ([1.2048])\n"); |
484 |
|
fprintf(stderr, " -h integer : frame height ([1.2048])\n"); |
485 |
|
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
486 |
|
fprintf(stderr, " -f float : target framerate (>0)\n"); |
487 |
|
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
488 |
|
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
489 |
|
fprintf(stderr, " -n integer : number of frames to encode\n"); |
490 |
|
fprintf(stderr, " -q integer : quality ([0..5])\n"); |
491 |
|
fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); |
492 |
|
fprintf(stderr, " -m boolean : save mpeg4 raw stream (0 False*, !=0 True)\n"); |
493 |
|
fprintf(stderr, " -o string : output container filename (only usefull when -m 1 is used) :\n"); |
494 |
|
fprintf(stderr, " When this option is not used : one file per encoded frame\n"); |
495 |
|
fprintf(stderr, " When this option is used :\n"); |
496 |
|
fprintf(stderr, " + stream.m4v with -mt 0\n"); |
497 |
|
fprintf(stderr, " + stream.mp4u with -mt 1\n"); |
498 |
|
fprintf(stderr, " -mt integer : output type (m4v=0, mp4u=1)\n"); |
499 |
|
fprintf(stderr, " -help : prints this help message\n"); |
500 |
|
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
501 |
|
fprintf(stderr, " (* means default)\n"); |
502 |
|
|
503 |
} |
} |
504 |
|
|
505 |
/*********************************************************************/ |
/***************************************************************************** |
506 |
/* input and output functions */ |
* Input and output functions |
507 |
/* */ |
* |
508 |
/* the are small and simple routines to read and write PGM and YUV */ |
* the are small and simple routines to read and write PGM and YUV |
509 |
/* image. It's just for convenience, again nothing specific to XviD */ |
* image. It's just for convenience, again nothing specific to XviD |
510 |
/* */ |
* |
511 |
/*********************************************************************/ |
*****************************************************************************/ |
512 |
|
|
513 |
int read_pgmheader(FILE* handle) |
static int read_pgmheader(FILE* handle) |
514 |
{ |
{ |
515 |
int bytes,xsize,ysize,depth; |
int bytes,xsize,ysize,depth; |
516 |
char dummy[2]; |
char dummy[2]; |
519 |
|
|
520 |
if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' )) |
if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' )) |
521 |
return 1; |
return 1; |
522 |
|
|
523 |
fscanf(handle,"%d %d %d",&xsize,&ysize,&depth); |
fscanf(handle,"%d %d %d",&xsize,&ysize,&depth); |
524 |
if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) ) |
if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) ) |
525 |
{ |
{ |
526 |
|
fprintf(stderr,"%d %d %d\n",xsize,ysize,depth); |
527 |
return 2; |
return 2; |
528 |
} |
} |
529 |
if ( (XDIM==0) || (YDIM==0) ) |
if ( (XDIM==0) || (YDIM==0) ) |
530 |
{ XDIM=xsize; |
{ |
531 |
YDIM=ysize; |
XDIM=xsize; |
532 |
|
YDIM=ysize*2/3; |
533 |
} |
} |
534 |
|
|
535 |
return 0; |
return 0; |
536 |
} |
} |
537 |
|
|
538 |
int read_pgmdata(FILE* handle, unsigned char *image) |
static int read_pgmdata(FILE* handle, unsigned char *image) |
539 |
{ |
{ |
540 |
int i,status; |
int i; |
541 |
char dummy; |
char dummy; |
542 |
|
|
543 |
unsigned char* buff1_ptr2 = image + XDIM*YDIM; |
unsigned char *y = image; |
544 |
unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2; |
unsigned char *u = image + XDIM*YDIM; |
545 |
|
unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2; |
546 |
|
|
547 |
fread(image,XDIM*YDIM,1,stdin); // read Y component of picture |
/* read Y component of picture */ |
548 |
|
fread(y, 1, XDIM*YDIM, handle); |
549 |
|
|
550 |
for (i=0;i<YDIM/2;i++) |
for (i=0;i<YDIM/2;i++) |
551 |
{ |
{ |
552 |
fread(buff1_ptr2,XDIM/2,1,stdin); // read U |
/* read U */ |
553 |
buff1_ptr2 += XDIM/2; |
fread(u, 1, XDIM/2, handle); |
|
fread(buff1_ptr3,XDIM/2,1,stdin); // read V |
|
|
buff1_ptr3 += XDIM/2; |
|
|
} |
|
|
fread(&dummy,1,1,handle); // I don't know why, but this seems needed |
|
|
return 0; |
|
|
} |
|
554 |
|
|
555 |
int read_yuvdata(FILE* handle, unsigned char *image) |
/* read V */ |
556 |
{ int i; |
fread(v, 1, XDIM/2, handle); |
|
char dummy; |
|
557 |
|
|
558 |
unsigned char* buff1_ptr2 = image + XDIM*YDIM; |
/* Update pointers */ |
559 |
unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2; |
u += XDIM/2; |
560 |
|
v += XDIM/2; |
561 |
|
} |
562 |
|
|
563 |
|
/* I don't know why, but this seems needed */ |
564 |
|
fread(&dummy, 1, 1, handle); |
565 |
|
|
|
if (fread(image,XDIM,YDIM*3/2,stdin) != YDIM*3/2) |
|
|
return 1; |
|
|
else |
|
566 |
return 0; |
return 0; |
567 |
} |
} |
568 |
|
|
569 |
int write_pgm(char *filename, unsigned char *image) |
static int read_yuvdata(FILE* handle, unsigned char *image) |
570 |
{ |
{ |
571 |
FILE *filehandle; |
|
572 |
filehandle=fopen(filename,"wb"); |
if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != (unsigned int)IMAGE_SIZE(XDIM, YDIM)) |
|
if (filehandle) |
|
|
{ |
|
|
fprintf(filehandle,"P5\n\n"); // |
|
|
fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2); |
|
|
fwrite(image,XDIM,YDIM*3/2,filehandle); |
|
|
fclose(filehandle); |
|
|
return 0; |
|
|
} |
|
|
else |
|
573 |
return 1; |
return 1; |
574 |
|
else |
575 |
|
return 0; |
576 |
} |
} |
577 |
|
|
578 |
/*********************************************************************/ |
/***************************************************************************** |
579 |
/* Routines for encoding: init encoder, frame step, release encoder */ |
* Routines for encoding: init encoder, frame step, release encoder |
580 |
/*********************************************************************/ |
****************************************************************************/ |
581 |
|
|
582 |
#define FRAMERATE_INCR 1001 |
#define FRAMERATE_INCR 1001 |
583 |
|
|
584 |
|
/* Initialize encoder for first use, pass all needed parameters to the codec */ |
585 |
int enc_init(int use_assembler) |
static int enc_init(int use_assembler) |
586 |
{ /* initialize encoder for first use, pass all needed parameters to the codec */ |
{ |
587 |
int xerr; |
int xerr; |
588 |
|
|
589 |
XVID_INIT_PARAM xinit; |
XVID_INIT_PARAM xinit; |
590 |
XVID_ENC_PARAM xparam; |
XVID_ENC_PARAM xparam; |
591 |
|
|
592 |
if(use_assembler) |
if(use_assembler) { |
593 |
|
|
594 |
#ifdef ARCH_IA64 |
#ifdef ARCH_IA64 |
595 |
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
596 |
#else |
#else |
597 |
xinit.cpu_flags = 0; |
xinit.cpu_flags = 0; |
598 |
#endif |
#endif |
599 |
|
} |
600 |
else |
else { |
601 |
xinit.cpu_flags = XVID_CPU_FORCE; |
xinit.cpu_flags = XVID_CPU_FORCE; |
602 |
|
} |
603 |
|
|
604 |
xvid_init(NULL, 0, &xinit, NULL); |
xvid_init(NULL, 0, &xinit, NULL); |
605 |
|
|
619 |
xparam.rc_averaging_period = 100; |
xparam.rc_averaging_period = 100; |
620 |
xparam.rc_buffer = 10; |
xparam.rc_buffer = 10; |
621 |
xparam.rc_bitrate = ARG_BITRATE*1000; |
xparam.rc_bitrate = ARG_BITRATE*1000; |
622 |
xparam.min_quantizer = 1; |
xparam.min_quantizer = ARG_MINQUANT; |
623 |
xparam.max_quantizer = 31; |
xparam.max_quantizer = ARG_MAXQUANT; |
624 |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
625 |
|
|
626 |
#ifdef BFRAMES |
/* I use a small value here, since will not encode whole movies, but short clips */ |
|
xparam.global = XVID_GLOBAL_DX50BVOP; |
|
|
xparam.max_bframes = ARG_MAXBFRAMES; |
|
|
xparam.bquant_ratio = ARG_BQUANTRATIO; |
|
|
xparam.frame_drop_ratio=0; |
|
|
#endif |
|
|
|
|
|
/* I use a small value here, since will not encode whole movies, |
|
|
but short clips */ |
|
627 |
|
|
628 |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); |
629 |
enc_handle=xparam.handle; |
enc_handle=xparam.handle; |
631 |
return xerr; |
return xerr; |
632 |
} |
} |
633 |
|
|
634 |
int enc_stop() |
static int enc_stop() |
635 |
{ int xerr; |
{ |
636 |
|
int xerr; |
637 |
|
|
638 |
xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL); |
xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL); |
639 |
return xerr; |
return xerr; |
640 |
|
|
641 |
} |
} |
642 |
|
|
643 |
int enc_main(unsigned char* image, unsigned char* bitstream, int *streamlength, int* frametype) |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
644 |
{ int xerr; |
int *streamlength, int* frametype) |
645 |
|
{ |
646 |
|
int xerr; |
647 |
|
|
648 |
XVID_ENC_FRAME xframe; |
XVID_ENC_FRAME xframe; |
649 |
XVID_ENC_STATS xstats; |
XVID_ENC_STATS xstats; |
650 |
|
|
651 |
xframe.bitstream = bitstream; |
xframe.bitstream = bitstream; |
652 |
xframe.length = -1; // this is written by the routine |
xframe.length = -1; /* this is written by the routine */ |
653 |
|
|
654 |
xframe.image = image; |
xframe.image = image; |
655 |
xframe.colorspace = XVID_CSP_YV12; // defined in <xvid.h> |
xframe.colorspace = XVID_CSP_YV12; /* defined in <xvid.h> */ |
656 |
|
|
657 |
xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0) |
xframe.intra = -1; /* let the codec decide between I-frame (1) and P-frame (0) */ |
658 |
|
|
659 |
xframe.quant = ARG_QUANTI; // is quant != 0, use a fixed quant (and ignore bitrate) |
xframe.quant = ARG_QUANTI; /* is quant != 0, use a fixed quant (and ignore bitrate) */ |
660 |
|
|
661 |
xframe.motion = motion_presets[ARG_QUALITY]; |
xframe.motion = motion_presets[ARG_QUALITY]; |
662 |
xframe.general = general_presets[ARG_QUALITY]; |
xframe.general = general_presets[ARG_QUALITY]; |
663 |
xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; |
xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; |
664 |
|
|
|
#ifdef BFRAMES |
|
|
xframe.bquant = 0; |
|
|
#endif |
|
|
|
|
665 |
xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); |
xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); |
666 |
|
|
667 |
/* enc_result->is_key_frame = xframe.intra; |
/* |
668 |
enc_result->quantizer = xframe.quant; |
* This is statictical data, e.g. for 2-pass. If you are not |
669 |
enc_result->total_bits = xframe.length * 8; |
* interested in any of this, you can use NULL instead of &xstats |
|
enc_result->motion_bits = xstats.hlength * 8; |
|
|
enc_result->texture_bits = enc_result->total_bits - enc_result->motion_bits; |
|
|
*/ |
|
|
|
|
|
/* This is statictical data, e.g. for 2-pass. |
|
|
If you are not interested in any of this, you can use |
|
|
NULL instead of &xstats |
|
670 |
*/ |
*/ |
671 |
*frametype = xframe.intra; |
*frametype = xframe.intra; |
672 |
*streamlength = xframe.length; |
*streamlength = xframe.length; |
673 |
|
|
674 |
return xerr; |
return xerr; |
675 |
} |
} |
|
|
|
|
/*********************************************************************/ |
|
|
/* Main program */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
{ |
|
|
unsigned char *divx_buffer = NULL; |
|
|
unsigned char *in_buffer = NULL; |
|
|
|
|
|
double enctime; |
|
|
double totalenctime=0.; |
|
|
|
|
|
long totalsize=0; |
|
|
int status; |
|
|
|
|
|
int m4v_size; |
|
|
int frame_type[ABS_MAXFRAMENR]; |
|
|
int Iframes=0, Pframes=0, Bframes=0; |
|
|
int use_assembler=1; |
|
|
|
|
|
char filename[256]; |
|
|
|
|
|
FILE *filehandle; |
|
|
|
|
|
/* read YUV in pgm format from stdin */ |
|
|
if (!pgmflag) |
|
|
{ |
|
|
pgmflag = 1; |
|
|
|
|
|
// if (argc==2 && !strcmp(argv[1],"-noasm")) |
|
|
// use_assembler = 0; |
|
|
|
|
|
if (argc>=3) |
|
|
{ XDIM = atoi(argv[1]); |
|
|
YDIM = atoi(argv[2]); |
|
|
if ( (XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048) ) |
|
|
{ fprintf(stderr,"Wrong frames size %d %d, trying PGM \n",XDIM, YDIM); |
|
|
} |
|
|
else |
|
|
{ |
|
|
YDIM = YDIM*3/2; /* for YUV */ |
|
|
pgmflag = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (pgmflag) |
|
|
{ if (read_pgmheader(stdin)) |
|
|
{ |
|
|
fprintf(stderr,"Wrong input format, I want YUV encapsulated in PGM\n"); |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
if (argc>=4) |
|
|
{ ARG_QUALITY = atoi(argv[3]); |
|
|
if ( (ARG_QUALITY < 0) || (ARG_QUALITY > 6) ) |
|
|
{ fprintf(stderr,"Wrong Quality\n"); return -1; } |
|
|
else |
|
|
fprintf(stderr,"Quality %d\n",ARG_QUALITY); |
|
|
} |
|
|
if (argc>=5) |
|
|
{ ARG_BITRATE = atoi(argv[4]); |
|
|
if ( (ARG_BITRATE <= 0) ) |
|
|
{ fprintf(stderr,"Wrong Bitrate\n"); return -1; } |
|
|
if ( (ARG_BITRATE < 32) ) |
|
|
{ ARG_QUANTI = ARG_BITRATE; |
|
|
ARG_BITRATE=0; |
|
|
fprintf(stderr,"Quantizer %d\n",ARG_QUANTI); |
|
|
} |
|
|
else |
|
|
fprintf(stderr,"Bitrate %d kbps\n",ARG_BITRATE); |
|
|
} |
|
|
if (argc>=6) |
|
|
{ ARG_FRAMERATE = (float)atof(argv[5]); |
|
|
if ( (ARG_FRAMERATE <= 0) ) |
|
|
{ fprintf(stderr,"Wrong Fraterate %s \n",argv[5]); return -1; } |
|
|
fprintf(stderr,"Framerate %6.3f fps\n",ARG_FRAMERATE); |
|
|
} |
|
|
|
|
|
if (argc>=7) |
|
|
{ ARG_MAXFRAMENR = atoi(argv[6]); |
|
|
if ( (ARG_MAXFRAMENR <= 0) ) |
|
|
{ fprintf(stderr,"Wrong number of frames\n"); return -1; } |
|
|
fprintf(stderr,"max. Framenr. %d\n",ARG_MAXFRAMENR); |
|
|
} |
|
|
|
|
|
#ifdef BFRAMES |
|
|
if (argc>=8) |
|
|
{ ARG_MAXBFRAMES = atoi(argv[7]); |
|
|
if ( (ARG_MAXBFRAMES < -1) || ( ARG_MAXBFRAMES > ARG_FRAMERATE) ) |
|
|
{ fprintf(stderr,"Wrong maximumnumber of bframes\n"); return -1; } |
|
|
fprintf(stderr,"max. B-frames %d\n",ARG_MAXBFRAMES); |
|
|
} |
|
|
|
|
|
if (argc>=9) |
|
|
{ ARG_MAXFRAMENR = atoi(argv[8]); |
|
|
if ( (ARG_BQUANTRATIO <= 0) ) |
|
|
{ fprintf(stderr,"Wrong B-frames Quantizer ratio \n"); return -1; } |
|
|
fprintf(stderr,"B-frames quant-ratio %d\n",ARG_BQUANTRATIO); |
|
|
} |
|
|
#endif |
|
|
|
|
|
/* now we know the sizes, so allocate memory */ |
|
|
|
|
|
in_buffer = (unsigned char *) malloc(XDIM*YDIM); |
|
|
if (!in_buffer) |
|
|
goto free_all_memory; |
|
|
|
|
|
divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); |
|
|
if (!divx_buffer) |
|
|
goto free_all_memory; |
|
|
|
|
|
YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture |
|
|
|
|
|
/*********************************************************************/ |
|
|
/* XviD PART Start */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
status = enc_init(use_assembler); |
|
|
if (status) |
|
|
{ |
|
|
fprintf(stderr,"Encore INIT problem, return value %d\n", status); |
|
|
goto release_all; |
|
|
} |
|
|
|
|
|
/*********************************************************************/ |
|
|
/* Main loop */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
do |
|
|
{ |
|
|
if (pgmflag) |
|
|
status = read_pgmdata(stdin, in_buffer); // read PGM data (YUV-format) |
|
|
else |
|
|
status = read_yuvdata(stdin, in_buffer); // read raw data (YUV-format) |
|
|
|
|
|
if (status) |
|
|
{ |
|
|
// Couldn't read image, most likely end-of-file |
|
|
continue; |
|
|
} |
|
|
|
|
|
|
|
|
if (save_ref_flag) |
|
|
{ |
|
|
sprintf(filename, "%s%05d.pgm", filepath, filenr); |
|
|
write_pgm(filename,in_buffer); |
|
|
} |
|
|
|
|
|
|
|
|
/*********************************************************************/ |
|
|
/* analyse this frame before encoding */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
// nothing is done here at the moment, but you could e.g. create |
|
|
// histograms or measure entropy or apply preprocessing filters... |
|
|
|
|
|
/*********************************************************************/ |
|
|
/* encode and decode this frame */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
enctime = -msecond(); |
|
|
status = enc_main(in_buffer, divx_buffer, &m4v_size, &frame_type[filenr]); |
|
|
enctime += msecond(); |
|
|
|
|
|
totalenctime += enctime; |
|
|
totalsize += m4v_size; |
|
|
|
|
|
fprintf(stderr,"Frame %5d: intra %d, enctime =%6.1f ms length=%7d bytes\n", |
|
|
filenr, frame_type[filenr], enctime*1000, m4v_size); |
|
|
|
|
|
if (save_m4v_flag) |
|
|
{ |
|
|
fwrite(divx_buffer, m4v_size, 1, stdout); |
|
|
} |
|
|
|
|
|
if (pgmflag) |
|
|
status = read_pgmheader(stdin); |
|
|
// because if this was the last PGM, stop now |
|
|
|
|
|
filenr++; |
|
|
|
|
|
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/ |
|
|
/* calculate totals and averages for output, print results */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
totalsize /= filenr; |
|
|
totalenctime /= filenr; |
|
|
|
|
|
for (i=0;i<filenr;i++) |
|
|
{ |
|
|
switch (frame_type[i]) |
|
|
{ |
|
|
case 0: |
|
|
Pframes++; |
|
|
break; |
|
|
case 1: |
|
|
Iframes++; |
|
|
break; |
|
|
case 2: |
|
|
default: |
|
|
Bframes++; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
fprintf(stderr,"Avg: enctime %5.2f ms, %5.2f fps, filesize =%d\n", |
|
|
1000*totalenctime, 1./totalenctime, totalsize); |
|
|
|
|
|
/*********************************************************************/ |
|
|
/* XviD PART Stop */ |
|
|
/*********************************************************************/ |
|
|
|
|
|
release_all: |
|
|
|
|
|
if (enc_handle) |
|
|
{ |
|
|
status = enc_stop(); |
|
|
if (status) |
|
|
fprintf(stderr,"Encore RELEASE problem return value %d\n", status); |
|
|
} |
|
|
|
|
|
free_all_memory: |
|
|
free(divx_buffer); |
|
|
free(in_buffer); |
|
|
|
|
|
return 0; |
|
|
} |
|