3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Console based test application - |
* - Console based test application - |
5 |
* |
* |
6 |
* Copyright(C) 2002-2003 Christoph Lampert |
* Copyright(C) 2002 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 |
51 |
****************************************************************************/ |
****************************************************************************/ |
52 |
|
|
53 |
static int const motion_presets[7] = { |
static int const motion_presets[7] = { |
54 |
0, /* Q 0 */ |
0, // Q 0 |
55 |
PMV_EARLYSTOP16, /* Q 1 */ |
PMV_EARLYSTOP16, // Q 1 |
56 |
PMV_EARLYSTOP16, /* Q 2 */ |
PMV_EARLYSTOP16, // Q 2 |
57 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, /* Q 3 */ |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 |
58 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, /* Q 4 */ |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 |
59 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | /* Q 5 */ |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | // Q 5 |
60 |
PMV_HALFPELREFINE8, |
PMV_HALFPELREFINE8, |
61 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | /* Q 6 */ |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | // Q 6 |
62 |
PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
63 |
}; |
}; |
64 |
|
|
65 |
static int const general_presets[7] = { |
static int const general_presets[7] = { |
66 |
XVID_H263QUANT, /* Q 0 */ |
XVID_H263QUANT, // Q 0 |
67 |
XVID_MPEGQUANT, /* Q 1 */ |
XVID_MPEGQUANT, // Q 1 |
68 |
XVID_H263QUANT, /* Q 2 */ |
XVID_H263QUANT, // Q 2 |
69 |
XVID_H263QUANT | XVID_HALFPEL, /* Q 3 */ |
XVID_H263QUANT | XVID_HALFPEL, // Q 3 |
70 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 4 */ |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 |
71 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 5 */ |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5 |
72 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V /* Q 6 */ |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V // Q 6 |
73 |
}; |
}; |
74 |
|
|
75 |
|
|
80 |
/* Maximum number of frames to encode */ |
/* Maximum number of frames to encode */ |
81 |
#define ABS_MAXFRAMENR 9999 |
#define ABS_MAXFRAMENR 9999 |
82 |
|
|
|
/* HINTMODEs */ |
|
|
#define HINT_MODE_NONE 0 |
|
|
#define HINT_MODE_GET 1 |
|
|
#define HINT_MODE_SET 2 |
|
|
#define HINT_FILE "hints.mv" |
|
|
|
|
83 |
static int ARG_BITRATE = 900; |
static int ARG_BITRATE = 900; |
84 |
static int ARG_QUANTI = 0; |
static int ARG_QUANTI = 0; |
85 |
static int ARG_QUALITY = 6; |
static int ARG_QUALITY = 6; |
90 |
static char *ARG_INPUTFILE = NULL; |
static char *ARG_INPUTFILE = NULL; |
91 |
static int ARG_INPUTTYPE = 0; |
static int ARG_INPUTTYPE = 0; |
92 |
static int ARG_SAVEMPEGSTREAM = 0; |
static int ARG_SAVEMPEGSTREAM = 0; |
93 |
|
static int ARG_OUTPUTTYPE = 0; |
94 |
static char *ARG_OUTPUTFILE = NULL; |
static char *ARG_OUTPUTFILE = NULL; |
|
static int ARG_HINTMODE = HINT_MODE_NONE; |
|
95 |
static int XDIM = 0; |
static int XDIM = 0; |
96 |
static int YDIM = 0; |
static int YDIM = 0; |
|
static int ARG_BQRATIO = 120; |
|
|
static int ARG_BQOFFSET = 0; |
|
|
static int ARG_MAXBFRAMES = 0; |
|
97 |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
98 |
|
|
99 |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
100 |
#define SMALL_EPS 1e-10 |
#define SMALL_EPS 1e-10 |
101 |
|
|
102 |
|
#define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \ |
103 |
|
(((long)(c))<<8) |((long)(d))) |
104 |
|
|
105 |
#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ |
#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ |
106 |
(((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) |
(((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) |
107 |
|
|
136 |
static int enc_init(int use_assembler); |
static int enc_init(int use_assembler); |
137 |
static int enc_stop(); |
static int enc_stop(); |
138 |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
139 |
unsigned char *hints_buffer, |
int *streamlength, int* frametype); |
|
long *streamlength, long* frametype, long *hints_size); |
|
140 |
|
|
141 |
/***************************************************************************** |
/***************************************************************************** |
142 |
* Main function |
* Main function |
148 |
unsigned char *mp4_buffer = NULL; |
unsigned char *mp4_buffer = NULL; |
149 |
unsigned char *in_buffer = NULL; |
unsigned char *in_buffer = NULL; |
150 |
unsigned char *out_buffer = NULL; |
unsigned char *out_buffer = NULL; |
|
unsigned char *hints_buffer = NULL; |
|
151 |
|
|
152 |
double enctime; |
double enctime; |
153 |
double totalenctime=0.; |
double totalenctime=0.; |
154 |
|
|
155 |
long totalsize; |
long totalsize; |
|
long hints_size; |
|
156 |
int status; |
int status; |
157 |
long frame_type; |
int frame_type; |
158 |
long bigendian; |
int bigendian; |
159 |
|
|
160 |
long m4v_size; |
int m4v_size; |
161 |
int use_assembler=0; |
int use_assembler=0; |
162 |
|
|
163 |
char filename[256]; |
char filename[256]; |
164 |
|
|
165 |
FILE *in_file = stdin; |
FILE *in_file = stdin; |
166 |
FILE *out_file = NULL; |
FILE *out_file = NULL; |
|
FILE *hints_file = NULL; |
|
167 |
|
|
168 |
printf("xvid_encraw - raw mpeg4 bitstream encoder "); |
printf("xvid_decraw - raw mpeg4 bitstream encoder "); |
169 |
printf("written by Christoph Lampert 2002-2003\n\n"); |
printf("written by Christoph Lampert 2002\n\n"); |
170 |
|
|
171 |
/***************************************************************************** |
/***************************************************************************** |
172 |
* Command line parsing |
* Command line parsing |
189 |
i++; |
i++; |
190 |
ARG_BITRATE = atoi(argv[i]); |
ARG_BITRATE = atoi(argv[i]); |
191 |
} |
} |
|
else if (strcmp("-bn", argv[i]) == 0 && i < argc - 1 ) { |
|
|
i++; |
|
|
ARG_MAXBFRAMES = atoi(argv[i]); |
|
|
} |
|
|
else if (strcmp("-bqr", argv[i]) == 0 && i < argc - 1 ) { |
|
|
i++; |
|
|
ARG_BQRATIO = atoi(argv[i]); |
|
|
} |
|
|
else if (strcmp("-bqo", argv[i]) == 0 && i < argc - 1 ) { |
|
|
i++; |
|
|
ARG_BQOFFSET = atoi(argv[i]); |
|
|
} |
|
192 |
else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { |
193 |
i++; |
i++; |
194 |
ARG_QUALITY = atoi(argv[i]); |
ARG_QUALITY = atoi(argv[i]); |
217 |
i++; |
i++; |
218 |
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
219 |
} |
} |
220 |
else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-mt", argv[i]) == 0 && i < argc - 1 ) { |
221 |
i++; |
i++; |
222 |
ARG_HINTMODE = atoi(argv[i]); |
ARG_OUTPUTTYPE = atoi(argv[i]); |
223 |
} |
} |
224 |
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
225 |
i++; |
i++; |
265 |
return -1; |
return -1; |
266 |
} |
} |
267 |
|
|
|
if ( ARG_HINTMODE != HINT_MODE_NONE && |
|
|
ARG_HINTMODE != HINT_MODE_GET && |
|
|
ARG_HINTMODE != HINT_MODE_SET) |
|
|
ARG_HINTMODE = HINT_MODE_NONE; |
|
|
|
|
|
if( ARG_HINTMODE != HINT_MODE_NONE) { |
|
|
char *rights = "rb"; |
|
|
|
|
|
/* |
|
|
* If we are getting hints from core, we will have to write them to |
|
|
* hint file |
|
|
*/ |
|
|
if(ARG_HINTMODE == HINT_MODE_GET) |
|
|
rights = "w+b"; |
|
|
|
|
|
/* Open the hint file */ |
|
|
hints_file = fopen(HINT_FILE, rights); |
|
|
if(hints_file == NULL) { |
|
|
fprintf(stderr, "Error opening input file %s\n", HINT_FILE); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
/* Allocate hint memory space, we will be using rawhints */ |
|
|
/* NB : Hope 1Mb is enough */ |
|
|
if((hints_buffer = malloc(1024*1024)) == NULL) { |
|
|
fprintf(stderr, "Memory allocation error\n"); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
268 |
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
269 |
in_file = stdin; |
in_file = stdin; |
270 |
} |
} |
285 |
} |
} |
286 |
|
|
287 |
/* now we know the sizes, so allocate memory */ |
/* now we know the sizes, so allocate memory */ |
288 |
|
|
289 |
in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); |
in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); |
290 |
if (!in_buffer) |
if (!in_buffer) |
291 |
goto free_all_memory; |
goto free_all_memory; |
311 |
* Main loop |
* Main loop |
312 |
****************************************************************************/ |
****************************************************************************/ |
313 |
|
|
314 |
if (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) { |
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) { |
if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) { |
328 |
fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE); |
fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE); |
329 |
goto release_all; |
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 { |
else { |
345 |
out_file = NULL; |
out_file = NULL; |
354 |
do { |
do { |
355 |
|
|
356 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
357 |
status = read_pgmdata(in_file, in_buffer); /* read PGM data (YUV-format) */ |
status = read_pgmdata(in_file, in_buffer); // read PGM data (YUV-format) |
358 |
else |
else |
359 |
status = read_yuvdata(in_file, in_buffer); /* read raw data (YUV-format) */ |
status = read_yuvdata(in_file, in_buffer); // read raw data (YUV-format) |
360 |
|
|
361 |
if (status) |
if (status) |
362 |
{ |
{ |
365 |
} |
} |
366 |
|
|
367 |
/***************************************************************************** |
/***************************************************************************** |
|
* Read hints from file |
|
|
****************************************************************************/ |
|
|
|
|
|
if(ARG_HINTMODE == HINT_MODE_SET) { |
|
|
fread(&hints_size, 1, sizeof(long), hints_file); |
|
|
hints_size = (!bigendian)?SWAP(hints_size):hints_size; |
|
|
fread(hints_buffer, 1, hints_size, hints_file); |
|
|
} |
|
|
|
|
|
/***************************************************************************** |
|
368 |
* Encode and decode this frame |
* Encode and decode this frame |
369 |
****************************************************************************/ |
****************************************************************************/ |
370 |
|
|
371 |
enctime = msecond(); |
enctime = msecond(); |
372 |
status = enc_main(in_buffer, mp4_buffer, hints_buffer, |
status = enc_main(in_buffer, mp4_buffer, &m4v_size, &frame_type); |
|
&m4v_size, &frame_type, &hints_size); |
|
373 |
enctime = msecond() - enctime; |
enctime = msecond() - enctime; |
374 |
|
|
|
/* if it's a not coded VOP (aka NVOP) then we write nothing */ |
|
|
if(frame_type == 5) goto next_frame; |
|
|
|
|
|
{ |
|
|
char *type[] = {"P", "I", "B", "S", "Packed", "N", "Unknown"}; |
|
|
|
|
|
if(frame_type<0 || frame_type>5) frame_type = 6; |
|
|
|
|
|
printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d\n", |
|
|
(int)filenr, type[frame_type], (float)enctime, (int)m4v_size); |
|
|
|
|
|
} |
|
|
|
|
|
/* Update encoding time stats */ |
|
375 |
totalenctime += enctime; |
totalenctime += enctime; |
376 |
totalsize += m4v_size; |
totalsize += m4v_size; |
377 |
|
|
378 |
/***************************************************************************** |
printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6dbytes\n", |
379 |
* Save hints to file |
(int)filenr, (int)frame_type, (float)enctime, (int)m4v_size); |
|
****************************************************************************/ |
|
|
|
|
|
if(ARG_HINTMODE == HINT_MODE_GET) { |
|
|
hints_size = (!bigendian)?SWAP(hints_size):hints_size; |
|
|
fwrite(&hints_size, 1, sizeof(long), hints_file); |
|
|
hints_size = (!bigendian)?SWAP(hints_size):hints_size; |
|
|
fwrite(hints_buffer, 1, hints_size, hints_file); |
|
|
} |
|
|
|
|
|
/***************************************************************************** |
|
|
* Save stream to file |
|
|
****************************************************************************/ |
|
380 |
|
|
381 |
if (ARG_SAVEMPEGSTREAM) |
if (ARG_SAVEMPEGSTREAM) |
382 |
{ |
{ |
389 |
out_file = NULL; |
out_file = NULL; |
390 |
} |
} |
391 |
else { |
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 */ |
/* Write mp4 data */ |
400 |
fwrite(mp4_buffer, 1, m4v_size, out_file); |
fwrite(mp4_buffer, m4v_size, 1, out_file); |
401 |
|
|
402 |
} |
} |
403 |
} |
} |
404 |
|
|
|
next_frame: |
|
405 |
/* Read the header if it's pgm stream */ |
/* Read the header if it's pgm stream */ |
406 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
407 |
status = read_pgmheader(in_file); |
status = read_pgmheader(in_file); |
408 |
|
|
409 |
if(frame_type != 5) filenr++; |
filenr++; |
410 |
|
|
411 |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
412 |
|
|
419 |
totalsize /= filenr; |
totalsize /= filenr; |
420 |
totalenctime /= filenr; |
totalenctime /= filenr; |
421 |
|
|
422 |
printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n", |
printf("Avg: enctime %5.2f ms, %5.2f fps, filesize %7d bytes\n", |
423 |
totalenctime, 1000/totalenctime, (int)totalsize); |
totalenctime, 1000/totalenctime, (int)totalsize); |
424 |
|
|
425 |
/***************************************************************************** |
/***************************************************************************** |
435 |
fprintf(stderr, "Encore RELEASE problem return value %d\n", status); |
fprintf(stderr, "Encore RELEASE problem return value %d\n", status); |
436 |
} |
} |
437 |
|
|
|
if(in_file) |
|
438 |
fclose(in_file); |
fclose(in_file); |
439 |
if(out_file) |
if(out_file) |
440 |
fclose(out_file); |
fclose(out_file); |
|
if(hints_file) |
|
|
fclose(hints_file); |
|
441 |
|
|
442 |
free_all_memory: |
free_all_memory: |
443 |
free(out_buffer); |
free(out_buffer); |
444 |
free(mp4_buffer); |
free(mp4_buffer); |
445 |
free(in_buffer); |
free(in_buffer); |
|
if(hints_buffer) free(hints_buffer); |
|
446 |
|
|
447 |
return 0; |
return 0; |
448 |
|
|
483 |
fprintf(stderr, " -w integer : frame width ([1.2048])\n"); |
fprintf(stderr, " -w integer : frame width ([1.2048])\n"); |
484 |
fprintf(stderr, " -h integer : frame height ([1.2048])\n"); |
fprintf(stderr, " -h integer : frame height ([1.2048])\n"); |
485 |
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
|
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
|
|
fprintf(stderr, " -bn integer : max bframes (default=0)\n"); |
|
|
fprintf(stderr, " -bqr integer : bframe quantizer ratio (default=150)\n"); |
|
|
fprintf(stderr, " -bqo integer : bframe quantizer offset (default=100)\n"); |
|
486 |
fprintf(stderr, " -f float : target framerate (>0)\n"); |
fprintf(stderr, " -f float : target framerate (>0)\n"); |
487 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
488 |
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
492 |
fprintf(stderr, " -m boolean : save mpeg4 raw stream (0 False*, !=0 True)\n"); |
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"); |
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"); |
fprintf(stderr, " When this option is not used : one file per encoded frame\n"); |
495 |
fprintf(stderr, " When this option is used : save to 'string' (default=stream.m4v)\n"); |
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"); |
fprintf(stderr, " -mt integer : output type (m4v=0, mp4u=1)\n"); |
|
fprintf(stderr, " -mv integer : Use motion vector hints (no hints=0, get hints=1, set hints=2)\n"); |
|
499 |
fprintf(stderr, " -help : prints this help message\n"); |
fprintf(stderr, " -help : prints this help message\n"); |
500 |
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
501 |
fprintf(stderr, " (* means default)\n"); |
fprintf(stderr, " (* means default)\n"); |
622 |
xparam.min_quantizer = ARG_MINQUANT; |
xparam.min_quantizer = ARG_MINQUANT; |
623 |
xparam.max_quantizer = ARG_MAXQUANT; |
xparam.max_quantizer = ARG_MAXQUANT; |
624 |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
|
xparam.bquant_ratio = ARG_BQRATIO; |
|
|
xparam.bquant_offset = ARG_BQOFFSET; |
|
|
xparam.max_bframes = ARG_MAXBFRAMES; |
|
|
xparam.frame_drop_ratio = 0; |
|
|
xparam.global = 0; |
|
625 |
|
|
626 |
/* I use a small value here, since will not encode whole movies, but short clips */ |
/* I use a small value here, since will not encode whole movies, but short clips */ |
627 |
|
|
641 |
} |
} |
642 |
|
|
643 |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
644 |
unsigned char* hints_buffer, |
int *streamlength, int* frametype) |
|
long *streamlength, long *frametype, long *hints_size) |
|
645 |
{ |
{ |
646 |
int xerr; |
int xerr; |
647 |
|
|
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) |
|
xframe.bquant = 0; |
|
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; |
|
xframe.stride = XDIM; |
|
|
|
|
|
xframe.hint.hintstream = hints_buffer; |
|
|
|
|
|
if(ARG_HINTMODE == HINT_MODE_SET) { |
|
|
xframe.hint.hintlength = *hints_size; |
|
|
xframe.hint.rawhints = 0; |
|
|
xframe.general |= XVID_HINTEDME_SET; |
|
|
} |
|
|
|
|
|
if(ARG_HINTMODE == HINT_MODE_GET) { |
|
|
xframe.hint.rawhints = 0; |
|
|
xframe.general |= XVID_HINTEDME_GET; |
|
|
} |
|
664 |
|
|
665 |
xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); |
xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); |
666 |
|
|
|
if(ARG_HINTMODE == HINT_MODE_GET) |
|
|
*hints_size = xframe.hint.hintlength; |
|
|
|
|
667 |
/* |
/* |
668 |
* This is statictical data, e.g. for 2-pass. If you are not |
* This is statictical data, e.g. for 2-pass. If you are not |
669 |
* interested in any of this, you can use NULL instead of &xstats |
* interested in any of this, you can use NULL instead of &xstats |