65 |
#include <math.h> // needed for log10 |
#include <math.h> // needed for log10 |
66 |
#include <sys/time.h> // only needed for gettimeofday |
#include <sys/time.h> // only needed for gettimeofday |
67 |
|
|
68 |
#include "xvid.h" /* comes with XviD */ |
#include "..\src\xvid.h" /* comes with XviD */ |
69 |
|
|
70 |
int motion_presets[7] = { |
int motion_presets[7] = { |
71 |
0, // Q 0 |
0, // Q 0 |
72 |
PMV_EARLYSTOP16, // Q 1 |
PMV_EARLYSTOP16, // Q 1 |
73 |
PMV_EARLYSTOP16, // Q 2 |
PMV_EARLYSTOP16, // Q 2 |
74 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 |
75 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8, // Q 4 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 |
76 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5 |
77 |
| PMV_HALFPELREFINE8, |
| PMV_HALFPELREFINE8, |
78 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 // Q 6 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 // Q 6 |
81 |
|
|
82 |
int general_presets[7] = { |
int general_presets[7] = { |
83 |
XVID_H263QUANT, /* or use XVID_MPEGQUANT */ // Q 0 |
XVID_H263QUANT, /* or use XVID_MPEGQUANT */ // Q 0 |
84 |
XVID_H263QUANT, // Q 1 |
XVID_MPEGQUANT, // Q 1 |
85 |
XVID_H263QUANT, // Q 2 |
XVID_H263QUANT, // Q 2 |
86 |
XVID_H263QUANT | XVID_HALFPEL, // Q 3 |
XVID_H263QUANT | XVID_HALFPEL, // Q 3 |
87 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 |
91 |
|
|
92 |
/* my default values for encoding */ |
/* my default values for encoding */ |
93 |
|
|
94 |
|
#define ABS_MAXFRAMENR 9999 // max number of frames |
95 |
|
|
96 |
int ARG_BITRATE=900; |
int ARG_BITRATE=900; |
97 |
int ARG_QUANTI=0; |
int ARG_QUANTI=0; |
98 |
|
|
101 |
int ARG_MAXQUANT=31; |
int ARG_MAXQUANT=31; |
102 |
float ARG_FRAMERATE=25.00; |
float ARG_FRAMERATE=25.00; |
103 |
|
|
104 |
|
int ARG_MAXFRAMENR=ABS_MAXFRAMENR; |
105 |
|
|
106 |
|
|
107 |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
108 |
#define SMALL_EPS 1e-10 |
#define SMALL_EPS 1e-10 |
121 |
int pgmflag = 0; // a flag, if input is in PGM format, overwritten in init-phase |
int pgmflag = 0; // a flag, if input is in PGM format, overwritten in init-phase |
122 |
char filepath[256] = "./"; // the path where to save output |
char filepath[256] = "./"; // the path where to save output |
123 |
|
|
|
#define MAXFILENR 9999 // max number of frames (this should be made into an option!) |
|
|
|
|
124 |
void *enc_handle = NULL; // internal structures (handles) for encoding |
void *enc_handle = NULL; // internal structures (handles) for encoding |
125 |
void *dec_handle = NULL; // and decoding |
void *dec_handle = NULL; // and decoding |
126 |
|
|
262 |
#define FRAMERATE_INCR 1001 |
#define FRAMERATE_INCR 1001 |
263 |
|
|
264 |
|
|
265 |
int enc_init() |
int enc_init(int use_assembler) |
266 |
{ /* initialize encoder for first use, pass all needed parameters to the codec */ |
{ /* initialize encoder for first use, pass all needed parameters to the codec */ |
267 |
int xerr; |
int xerr; |
268 |
|
|
269 |
XVID_INIT_PARAM xinit; |
XVID_INIT_PARAM xinit; |
270 |
XVID_ENC_PARAM xparam; |
XVID_ENC_PARAM xparam; |
271 |
|
|
272 |
|
if(use_assembler) |
273 |
|
|
274 |
|
#ifdef ARCH_IA64 |
275 |
|
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
276 |
|
#else |
277 |
|
xinit.cpu_flags = 0; |
278 |
|
#endif |
279 |
|
|
280 |
|
else |
281 |
xinit.cpu_flags = XVID_CPU_FORCE; |
xinit.cpu_flags = XVID_CPU_FORCE; |
282 |
|
|
283 |
xvid_init(NULL, 0, &xinit, NULL); |
xvid_init(NULL, 0, &xinit, NULL); |
284 |
|
|
285 |
xparam.width = XDIM; |
xparam.width = XDIM; |
294 |
xparam.fincr = FRAMERATE_INCR; |
xparam.fincr = FRAMERATE_INCR; |
295 |
xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE); |
xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE); |
296 |
} |
} |
297 |
xparam.bitrate = ARG_BITRATE*1000; |
xparam.rc_reaction_delay_factor = 16; |
298 |
|
xparam.rc_averaging_period = 100; |
299 |
|
xparam.rc_buffer = 10; |
300 |
|
xparam.rc_bitrate = ARG_BITRATE*1000; |
301 |
xparam.min_quantizer = 1; |
xparam.min_quantizer = 1; |
302 |
xparam.max_quantizer = 31; |
xparam.max_quantizer = 31; |
303 |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
xparam.max_key_interval = (int)ARG_FRAMERATE*10; |
304 |
xparam.rc_buffersize = 2; |
|
305 |
/* 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 */ |
306 |
|
|
307 |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); |
360 |
/* Routines for decoding: init encoder, frame step, release encoder */ |
/* Routines for decoding: init encoder, frame step, release encoder */ |
361 |
/*********************************************************************/ |
/*********************************************************************/ |
362 |
|
|
363 |
int dec_init() /* init decoder before first run */ |
int dec_init(int use_assembler) /* init decoder before first run */ |
364 |
{ |
{ |
365 |
int xerr; |
int xerr; |
366 |
|
|
367 |
XVID_INIT_PARAM xinit; |
XVID_INIT_PARAM xinit; |
368 |
XVID_DEC_PARAM xparam; |
XVID_DEC_PARAM xparam; |
369 |
|
|
370 |
|
if(use_assembler) |
371 |
|
|
372 |
|
#ifdef ARCH_IA64 |
373 |
|
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
374 |
|
#else |
375 |
xinit.cpu_flags = 0; |
xinit.cpu_flags = 0; |
376 |
|
#endif |
377 |
|
|
378 |
|
else |
379 |
|
xinit.cpu_flags = XVID_CPU_FORCE; |
380 |
|
|
381 |
xvid_init(NULL, 0, &xinit, NULL); |
xvid_init(NULL, 0, &xinit, NULL); |
382 |
xparam.width = XDIM; |
xparam.width = XDIM; |
383 |
xparam.height = YDIM; |
xparam.height = YDIM; |
432 |
int status; |
int status; |
433 |
|
|
434 |
int m4v_size; |
int m4v_size; |
435 |
int frame_type[MAXFILENR]; |
int frame_type[ABS_MAXFRAMENR]; |
436 |
int Iframes=0, Pframes=0, Bframes=0; |
int Iframes=0, Pframes=0, Bframes=0, use_assembler=0; |
437 |
double framepsnr[MAXFILENR]; |
double framepsnr[ABS_MAXFRAMENR]; |
438 |
|
|
439 |
double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.; |
double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.; |
440 |
double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.; |
double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.; |
449 |
{ |
{ |
450 |
pgmflag = 1; |
pgmflag = 1; |
451 |
|
|
452 |
|
if (argc==2 && !strcmp(argv[1],"-asm")) |
453 |
|
use_assembler = 1; |
454 |
if (argc>=3) |
if (argc>=3) |
455 |
{ XDIM = atoi(argv[1]); |
{ XDIM = atoi(argv[1]); |
456 |
YDIM = atoi(argv[2]); |
YDIM = atoi(argv[2]); |
498 |
printf("Framerate %6.3f fps\n",ARG_FRAMERATE); |
printf("Framerate %6.3f fps\n",ARG_FRAMERATE); |
499 |
} |
} |
500 |
|
|
501 |
|
if (argc>=7) |
502 |
|
{ ARG_MAXFRAMENR = atoi(argv[6]); |
503 |
|
if ( (ARG_MAXFRAMENR <= 0) ) |
504 |
|
{ fprintf(stderr,"Wrong number of frames\n"); return -1; } |
505 |
|
printf("max. Framenr. %d\n",ARG_MAXFRAMENR); |
506 |
|
} |
507 |
|
|
508 |
/* now we know the sizes, so allocate memory */ |
/* now we know the sizes, so allocate memory */ |
509 |
|
|
510 |
in_buffer = (unsigned char *) malloc(XDIM*YDIM); |
in_buffer = (unsigned char *) malloc(XDIM*YDIM); |
527 |
/*********************************************************************/ |
/*********************************************************************/ |
528 |
|
|
529 |
|
|
530 |
status = enc_init(); |
status = enc_init(use_assembler); |
531 |
if (status) |
if (status) |
532 |
{ |
{ |
533 |
printf("Encore INIT problem, return value %d\n", status); |
printf("Encore INIT problem, return value %d\n", status); |
534 |
goto release_all; |
goto release_all; |
535 |
} |
} |
536 |
|
|
537 |
status = dec_init(); |
status = dec_init(use_assembler); |
538 |
if (status) |
if (status) |
539 |
{ |
{ |
540 |
printf("Decore INIT problem, return value %d\n", status); |
printf("Decore INIT problem, return value %d\n", status); |
622 |
|
|
623 |
filenr++; |
filenr++; |
624 |
|
|
625 |
} while ( (!status) && (filenr<MAXFILENR) ); |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
626 |
|
|
627 |
|
|
628 |
|
|