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 Christoph Lampert |
* Copyright(C) 2002-2003 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 |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: xvid_encraw.c,v 1.2 2002-09-28 14:26:53 edgomez Exp $ |
* $Id: xvid_encraw.c,v 1.11 2003-02-16 05:11:39 suxen_drol Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
36 |
|
|
37 |
#include <stdio.h> |
#include <stdio.h> |
38 |
#include <stdlib.h> |
#include <stdlib.h> |
39 |
|
#include <string.h> |
40 |
#include <math.h> |
#include <math.h> |
41 |
#ifndef _MSC_VER |
#ifndef WIN32 |
42 |
#include <sys/time.h> |
#include <sys/time.h> |
43 |
#else |
#else |
44 |
#include <time.h> |
#include <time.h> |
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 |
|
|
83 |
|
/* HINTMODEs */ |
84 |
|
#define HINT_MODE_NONE 0 |
85 |
|
#define HINT_MODE_GET 1 |
86 |
|
#define HINT_MODE_SET 2 |
87 |
|
#define HINT_FILE "hints.mv" |
88 |
|
|
89 |
static int ARG_BITRATE = 900; |
static int ARG_BITRATE = 900; |
90 |
static int ARG_QUANTI = 0; |
static int ARG_QUANTI = 0; |
91 |
static int ARG_QUALITY = 6; |
static int ARG_QUALITY = 6; |
96 |
static char *ARG_INPUTFILE = NULL; |
static char *ARG_INPUTFILE = NULL; |
97 |
static int ARG_INPUTTYPE = 0; |
static int ARG_INPUTTYPE = 0; |
98 |
static int ARG_SAVEMPEGSTREAM = 0; |
static int ARG_SAVEMPEGSTREAM = 0; |
|
static int ARG_OUTPUTTYPE = 0; |
|
99 |
static char *ARG_OUTPUTFILE = NULL; |
static char *ARG_OUTPUTFILE = NULL; |
100 |
|
static int ARG_HINTMODE = HINT_MODE_NONE; |
101 |
static int XDIM = 0; |
static int XDIM = 0; |
102 |
static int YDIM = 0; |
static int YDIM = 0; |
103 |
|
static int ARG_BQRATIO = 120; |
104 |
|
static int ARG_BQOFFSET = 0; |
105 |
|
static int ARG_MAXBFRAMES = 0; |
106 |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
107 |
|
|
108 |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
109 |
#define SMALL_EPS 1e-10 |
#define SMALL_EPS 1e-10 |
110 |
|
|
|
#define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \ |
|
|
(((long)(c))<<8) |((long)(d))) |
|
|
|
|
111 |
#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ |
#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ |
112 |
(((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) |
(((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) |
113 |
|
|
142 |
static int enc_init(int use_assembler); |
static int enc_init(int use_assembler); |
143 |
static int enc_stop(); |
static int enc_stop(); |
144 |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
145 |
int *streamlength, int* frametype); |
unsigned char *hints_buffer, |
146 |
|
long *streamlength, long* frametype, long *hints_size); |
147 |
|
|
148 |
/***************************************************************************** |
/***************************************************************************** |
149 |
* Main function |
* Main function |
155 |
unsigned char *mp4_buffer = NULL; |
unsigned char *mp4_buffer = NULL; |
156 |
unsigned char *in_buffer = NULL; |
unsigned char *in_buffer = NULL; |
157 |
unsigned char *out_buffer = NULL; |
unsigned char *out_buffer = NULL; |
158 |
|
unsigned char *hints_buffer = NULL; |
159 |
|
|
160 |
double enctime; |
double enctime; |
161 |
double totalenctime=0.; |
double totalenctime=0.; |
162 |
|
|
163 |
long totalsize; |
long totalsize; |
164 |
|
long hints_size; |
165 |
int status; |
int status; |
166 |
int frame_type; |
long frame_type; |
167 |
int bigendian; |
long bigendian; |
168 |
|
|
169 |
int m4v_size; |
long m4v_size; |
170 |
int use_assembler=0; |
int use_assembler=0; |
171 |
|
|
172 |
char filename[256]; |
char filename[256]; |
173 |
|
|
174 |
FILE *in_file = stdin; |
FILE *in_file = stdin; |
175 |
FILE *out_file = NULL; |
FILE *out_file = NULL; |
176 |
|
FILE *hints_file = NULL; |
177 |
|
|
178 |
printf("xvid_decraw - raw mpeg4 bitstream encoder "); |
printf("xvid_encraw - raw mpeg4 bitstream encoder "); |
179 |
printf("written by Christoph Lampert 2002\n\n"); |
printf("written by Christoph Lampert 2002-2003\n\n"); |
180 |
|
|
181 |
/***************************************************************************** |
/***************************************************************************** |
182 |
* Command line parsing |
* Command line parsing |
199 |
i++; |
i++; |
200 |
ARG_BITRATE = atoi(argv[i]); |
ARG_BITRATE = atoi(argv[i]); |
201 |
} |
} |
202 |
|
else if (strcmp("-bn", argv[i]) == 0 && i < argc - 1 ) { |
203 |
|
i++; |
204 |
|
ARG_MAXBFRAMES = atoi(argv[i]); |
205 |
|
} |
206 |
|
else if (strcmp("-bqr", argv[i]) == 0 && i < argc - 1 ) { |
207 |
|
i++; |
208 |
|
ARG_BQRATIO = atoi(argv[i]); |
209 |
|
} |
210 |
|
else if (strcmp("-bqo", argv[i]) == 0 && i < argc - 1 ) { |
211 |
|
i++; |
212 |
|
ARG_BQOFFSET = atoi(argv[i]); |
213 |
|
} |
214 |
else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { |
215 |
i++; |
i++; |
216 |
ARG_QUALITY = atoi(argv[i]); |
ARG_QUALITY = atoi(argv[i]); |
239 |
i++; |
i++; |
240 |
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
241 |
} |
} |
242 |
else if (strcmp("-mt", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) { |
243 |
i++; |
i++; |
244 |
ARG_OUTPUTTYPE = atoi(argv[i]); |
ARG_HINTMODE = atoi(argv[i]); |
245 |
} |
} |
246 |
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
247 |
i++; |
i++; |
287 |
return -1; |
return -1; |
288 |
} |
} |
289 |
|
|
290 |
|
if ( ARG_HINTMODE != HINT_MODE_NONE && |
291 |
|
ARG_HINTMODE != HINT_MODE_GET && |
292 |
|
ARG_HINTMODE != HINT_MODE_SET) |
293 |
|
ARG_HINTMODE = HINT_MODE_NONE; |
294 |
|
|
295 |
|
if( ARG_HINTMODE != HINT_MODE_NONE) { |
296 |
|
char *rights = "rb"; |
297 |
|
|
298 |
|
/* |
299 |
|
* If we are getting hints from core, we will have to write them to |
300 |
|
* hint file |
301 |
|
*/ |
302 |
|
if(ARG_HINTMODE == HINT_MODE_GET) |
303 |
|
rights = "w+b"; |
304 |
|
|
305 |
|
/* Open the hint file */ |
306 |
|
hints_file = fopen(HINT_FILE, rights); |
307 |
|
if(hints_file == NULL) { |
308 |
|
fprintf(stderr, "Error opening input file %s\n", HINT_FILE); |
309 |
|
return -1; |
310 |
|
} |
311 |
|
|
312 |
|
/* Allocate hint memory space, we will be using rawhints */ |
313 |
|
/* NB : Hope 1Mb is enough */ |
314 |
|
if((hints_buffer = malloc(1024*1024)) == NULL) { |
315 |
|
fprintf(stderr, "Memory allocation error\n"); |
316 |
|
return -1; |
317 |
|
} |
318 |
|
|
319 |
|
} |
320 |
|
|
321 |
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
322 |
in_file = stdin; |
in_file = stdin; |
323 |
} |
} |
338 |
} |
} |
339 |
|
|
340 |
/* now we know the sizes, so allocate memory */ |
/* now we know the sizes, so allocate memory */ |
|
|
|
341 |
in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); |
in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); |
342 |
if (!in_buffer) |
if (!in_buffer) |
343 |
goto free_all_memory; |
goto free_all_memory; |
363 |
* Main loop |
* Main loop |
364 |
****************************************************************************/ |
****************************************************************************/ |
365 |
|
|
366 |
if (ARG_SAVEMPEGSTREAM && (ARG_OUTPUTTYPE || ARG_OUTPUTFILE)) { |
if (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) { |
|
|
|
|
if (ARG_OUTPUTFILE == NULL && ARG_OUTPUTTYPE) |
|
|
ARG_OUTPUTFILE = "stream.mp4u"; |
|
|
else if(ARG_OUTPUTFILE == NULL && !ARG_OUTPUTTYPE) |
|
|
ARG_OUTPUTFILE = "stream.m4v"; |
|
367 |
|
|
368 |
if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) { |
if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) { |
369 |
fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE); |
fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE); |
370 |
goto release_all; |
goto release_all; |
371 |
} |
} |
372 |
|
|
|
/* Write header */ |
|
|
if (ARG_OUTPUTTYPE) { |
|
|
char *ptr; |
|
|
long test; |
|
|
|
|
|
test = LONG_PACK('M','P','4','U'); |
|
|
ptr = (unsigned char *)&test; |
|
|
if(*ptr == 'M') |
|
|
bigendian = 1; |
|
|
else |
|
|
bigendian = 0; |
|
|
|
|
|
test = (!bigendian)?SWAP(test):test; |
|
|
|
|
|
fwrite(&test, sizeof(test), 1, out_file); |
|
|
|
|
|
} |
|
|
|
|
373 |
} |
} |
374 |
else { |
else { |
375 |
out_file = NULL; |
out_file = NULL; |
384 |
do { |
do { |
385 |
|
|
386 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
387 |
status = read_pgmdata(in_file, in_buffer); // read PGM data (YUV-format) |
status = read_pgmdata(in_file, in_buffer); /* read PGM data (YUV-format) */ |
388 |
else |
else |
389 |
status = read_yuvdata(in_file, in_buffer); // read raw data (YUV-format) |
status = read_yuvdata(in_file, in_buffer); /* read raw data (YUV-format) */ |
390 |
|
|
391 |
if (status) |
if (status) |
392 |
{ |
{ |
395 |
} |
} |
396 |
|
|
397 |
/***************************************************************************** |
/***************************************************************************** |
398 |
|
* Read hints from file |
399 |
|
****************************************************************************/ |
400 |
|
|
401 |
|
if(ARG_HINTMODE == HINT_MODE_SET) { |
402 |
|
fread(&hints_size, 1, sizeof(long), hints_file); |
403 |
|
hints_size = (!bigendian)?SWAP(hints_size):hints_size; |
404 |
|
fread(hints_buffer, 1, hints_size, hints_file); |
405 |
|
} |
406 |
|
|
407 |
|
/***************************************************************************** |
408 |
* Encode and decode this frame |
* Encode and decode this frame |
409 |
****************************************************************************/ |
****************************************************************************/ |
410 |
|
|
411 |
enctime = msecond(); |
enctime = msecond(); |
412 |
status = enc_main(in_buffer, mp4_buffer, &m4v_size, &frame_type); |
status = enc_main(in_buffer, mp4_buffer, hints_buffer, |
413 |
|
&m4v_size, &frame_type, &hints_size); |
414 |
enctime = msecond() - enctime; |
enctime = msecond() - enctime; |
415 |
|
|
416 |
|
/* if it's a not coded VOP (aka NVOP) then we write nothing */ |
417 |
|
if(frame_type == 5) goto next_frame; |
418 |
|
|
419 |
|
{ |
420 |
|
char *type[] = {"P", "I", "B", "S", "Packed", "N", "Unknown"}; |
421 |
|
|
422 |
|
if(frame_type<0 || frame_type>5) frame_type = 6; |
423 |
|
|
424 |
|
printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d\n", |
425 |
|
(int)filenr, type[frame_type], (float)enctime, (int)m4v_size); |
426 |
|
|
427 |
|
} |
428 |
|
|
429 |
|
/* Update encoding time stats */ |
430 |
totalenctime += enctime; |
totalenctime += enctime; |
431 |
totalsize += m4v_size; |
totalsize += m4v_size; |
432 |
|
|
433 |
printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6dbytes\n", |
/***************************************************************************** |
434 |
(int)filenr, (int)frame_type, (float)enctime, (int)m4v_size); |
* Save hints to file |
435 |
|
****************************************************************************/ |
436 |
|
|
437 |
|
if(ARG_HINTMODE == HINT_MODE_GET) { |
438 |
|
hints_size = (!bigendian)?SWAP(hints_size):hints_size; |
439 |
|
fwrite(&hints_size, 1, sizeof(long), hints_file); |
440 |
|
hints_size = (!bigendian)?SWAP(hints_size):hints_size; |
441 |
|
fwrite(hints_buffer, 1, hints_size, hints_file); |
442 |
|
} |
443 |
|
|
444 |
|
/***************************************************************************** |
445 |
|
* Save stream to file |
446 |
|
****************************************************************************/ |
447 |
|
|
448 |
if (ARG_SAVEMPEGSTREAM) |
if (ARG_SAVEMPEGSTREAM) |
449 |
{ |
{ |
456 |
out_file = NULL; |
out_file = NULL; |
457 |
} |
} |
458 |
else { |
else { |
|
/* Using mp4u container */ |
|
|
if (ARG_OUTPUTTYPE) { |
|
|
long size = m4v_size; |
|
|
size = (!bigendian)?SWAP(size):size; |
|
|
fwrite(&size, sizeof(size), 1, out_file); |
|
|
} |
|
459 |
|
|
460 |
/* Write mp4 data */ |
/* Write mp4 data */ |
461 |
fwrite(mp4_buffer, m4v_size, 1, out_file); |
fwrite(mp4_buffer, 1, m4v_size, out_file); |
462 |
|
|
463 |
} |
} |
464 |
} |
} |
465 |
|
|
466 |
|
next_frame: |
467 |
/* Read the header if it's pgm stream */ |
/* Read the header if it's pgm stream */ |
468 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
469 |
status = read_pgmheader(in_file); |
status = read_pgmheader(in_file); |
470 |
|
|
471 |
filenr++; |
if(frame_type != 5) filenr++; |
472 |
|
|
473 |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
474 |
|
|
481 |
totalsize /= filenr; |
totalsize /= filenr; |
482 |
totalenctime /= filenr; |
totalenctime /= filenr; |
483 |
|
|
484 |
printf("Avg: enctime %5.2f ms, %5.2f fps, filesize %7d bytes\n", |
printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n", |
485 |
totalenctime, 1000/totalenctime, (int)totalsize); |
totalenctime, 1000/totalenctime, (int)totalsize); |
486 |
|
|
487 |
/***************************************************************************** |
/***************************************************************************** |
497 |
fprintf(stderr, "Encore RELEASE problem return value %d\n", status); |
fprintf(stderr, "Encore RELEASE problem return value %d\n", status); |
498 |
} |
} |
499 |
|
|
500 |
|
if(in_file) |
501 |
fclose(in_file); |
fclose(in_file); |
502 |
if(out_file) |
if(out_file) |
503 |
fclose(out_file); |
fclose(out_file); |
504 |
|
if(hints_file) |
505 |
|
fclose(hints_file); |
506 |
|
|
507 |
free_all_memory: |
free_all_memory: |
508 |
free(out_buffer); |
free(out_buffer); |
509 |
free(mp4_buffer); |
free(mp4_buffer); |
510 |
free(in_buffer); |
free(in_buffer); |
511 |
|
if(hints_buffer) free(hints_buffer); |
512 |
|
|
513 |
return 0; |
return 0; |
514 |
|
|
526 |
/* Return time elapsed time in miliseconds since the program started */ |
/* Return time elapsed time in miliseconds since the program started */ |
527 |
static double msecond() |
static double msecond() |
528 |
{ |
{ |
529 |
#ifndef _MSC_VER |
#ifndef WIN32 |
530 |
struct timeval tv; |
struct timeval tv; |
531 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
532 |
return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3; |
return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3; |
549 |
fprintf(stderr, " -w integer : frame width ([1.2048])\n"); |
fprintf(stderr, " -w integer : frame width ([1.2048])\n"); |
550 |
fprintf(stderr, " -h integer : frame height ([1.2048])\n"); |
fprintf(stderr, " -h integer : frame height ([1.2048])\n"); |
551 |
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
552 |
|
fprintf(stderr, " -b integer : target bitrate (>0 | default=900kbit)\n"); |
553 |
|
fprintf(stderr, " -bn integer : max bframes (default=0)\n"); |
554 |
|
fprintf(stderr, " -bqr integer : bframe quantizer ratio (default=150)\n"); |
555 |
|
fprintf(stderr, " -bqo integer : bframe quantizer offset (default=100)\n"); |
556 |
fprintf(stderr, " -f float : target framerate (>0)\n"); |
fprintf(stderr, " -f float : target framerate (>0)\n"); |
557 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
558 |
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
562 |
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"); |
563 |
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"); |
564 |
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"); |
565 |
fprintf(stderr, " When this option is used :\n"); |
fprintf(stderr, " When this option is used : save to 'string' (default=stream.m4v)\n"); |
|
fprintf(stderr, " + stream.m4v with -mt 0\n"); |
|
|
fprintf(stderr, " + stream.mp4u with -mt 1\n"); |
|
566 |
fprintf(stderr, " -mt integer : output type (m4v=0, mp4u=1)\n"); |
fprintf(stderr, " -mt integer : output type (m4v=0, mp4u=1)\n"); |
567 |
|
fprintf(stderr, " -mv integer : Use motion vector hints (no hints=0, get hints=1, set hints=2)\n"); |
568 |
fprintf(stderr, " -help : prints this help message\n"); |
fprintf(stderr, " -help : prints this help message\n"); |
569 |
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
570 |
fprintf(stderr, " (* means default)\n"); |
fprintf(stderr, " (* means default)\n"); |
660 |
|
|
661 |
if(use_assembler) { |
if(use_assembler) { |
662 |
|
|
663 |
#ifdef ARCH_IA64 |
#ifdef ARCH_IS_IA64 |
664 |
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
665 |
#else |
#else |
666 |
xinit.cpu_flags = 0; |
xinit.cpu_flags = 0; |
691 |
xparam.min_quantizer = ARG_MINQUANT; |
xparam.min_quantizer = ARG_MINQUANT; |
692 |
xparam.max_quantizer = ARG_MAXQUANT; |
xparam.max_quantizer = ARG_MAXQUANT; |
693 |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
694 |
|
xparam.bquant_ratio = ARG_BQRATIO; |
695 |
|
xparam.bquant_offset = ARG_BQOFFSET; |
696 |
|
xparam.max_bframes = ARG_MAXBFRAMES; |
697 |
|
xparam.frame_drop_ratio = 0; |
698 |
|
xparam.global = 0; |
699 |
|
|
700 |
/* 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 */ |
701 |
|
|
715 |
} |
} |
716 |
|
|
717 |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
static int enc_main(unsigned char* image, unsigned char* bitstream, |
718 |
int *streamlength, int* frametype) |
unsigned char* hints_buffer, |
719 |
|
long *streamlength, long *frametype, long *hints_size) |
720 |
{ |
{ |
721 |
int xerr; |
int xerr; |
722 |
|
|
724 |
XVID_ENC_STATS xstats; |
XVID_ENC_STATS xstats; |
725 |
|
|
726 |
xframe.bitstream = bitstream; |
xframe.bitstream = bitstream; |
727 |
xframe.length = -1; // this is written by the routine |
xframe.length = -1; /* this is written by the routine */ |
728 |
|
|
729 |
xframe.image = image; |
xframe.image = image; |
730 |
xframe.colorspace = XVID_CSP_YV12; // defined in <xvid.h> |
xframe.colorspace = XVID_CSP_YV12; /* defined in <xvid.h> */ |
731 |
|
|
732 |
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) */ |
733 |
|
|
734 |
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) */ |
735 |
|
xframe.bquant = 0; |
736 |
|
|
737 |
xframe.motion = motion_presets[ARG_QUALITY]; |
xframe.motion = motion_presets[ARG_QUALITY]; |
738 |
xframe.general = general_presets[ARG_QUALITY]; |
xframe.general = general_presets[ARG_QUALITY]; |
739 |
xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; |
xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; |
740 |
|
xframe.stride = XDIM; |
741 |
|
|
742 |
|
xframe.hint.hintstream = hints_buffer; |
743 |
|
|
744 |
|
if(ARG_HINTMODE == HINT_MODE_SET) { |
745 |
|
xframe.hint.hintlength = *hints_size; |
746 |
|
xframe.hint.rawhints = 0; |
747 |
|
xframe.general |= XVID_HINTEDME_SET; |
748 |
|
} |
749 |
|
|
750 |
|
if(ARG_HINTMODE == HINT_MODE_GET) { |
751 |
|
xframe.hint.rawhints = 0; |
752 |
|
xframe.general |= XVID_HINTEDME_GET; |
753 |
|
} |
754 |
|
|
755 |
xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); |
xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); |
756 |
|
|
757 |
|
if(ARG_HINTMODE == HINT_MODE_GET) |
758 |
|
*hints_size = xframe.hint.hintlength; |
759 |
|
|
760 |
/* |
/* |
761 |
* 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 |
762 |
* interested in any of this, you can use NULL instead of &xstats |
* interested in any of this, you can use NULL instead of &xstats |