44 |
* -q integer : quality ([0..5]) |
* -q integer : quality ([0..5]) |
45 |
* -d boolean : save decoder output (0 False*, !=0 True) |
* -d boolean : save decoder output (0 False*, !=0 True) |
46 |
* -m boolean : save mpeg4 raw stream (0 False*, !=0 True) |
* -m boolean : save mpeg4 raw stream (0 False*, !=0 True) |
47 |
* -h, -help : prints this help message |
* -help : prints this help message |
48 |
* -quant integer : fixed quantizer (disables -b setting) |
* -quant integer : fixed quantizer (disables -b setting) |
49 |
* (* means default) |
* (* means default) |
50 |
* |
* |
65 |
#include <stdlib.h> |
#include <stdlib.h> |
66 |
#include <string.h> |
#include <string.h> |
67 |
#include <math.h> |
#include <math.h> |
68 |
|
#ifndef _MSC_VER |
69 |
|
#include <sys/time.h> |
70 |
|
#else |
71 |
#include <time.h> |
#include <time.h> |
72 |
|
#endif |
73 |
|
|
74 |
#include "../src/xvid.h" |
#include "xvid.h" |
75 |
|
|
76 |
/**************************************************************************** |
/**************************************************************************** |
77 |
* Prototypes |
* Prototypes |
112 |
****************************************************************************/ |
****************************************************************************/ |
113 |
|
|
114 |
static int const motion_presets[7] = { |
static int const motion_presets[7] = { |
115 |
0, // Q 0 |
0, /* Q 0 */ |
116 |
PMV_EARLYSTOP16, // Q 1 |
PMV_EARLYSTOP16, /* Q 1 */ |
117 |
PMV_EARLYSTOP16, // Q 2 |
PMV_EARLYSTOP16, /* Q 2 */ |
118 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, /* Q 3 */ |
119 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, /* Q 4 */ |
120 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | // Q 5 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | /* Q 5 */ |
121 |
PMV_HALFPELREFINE8, |
PMV_HALFPELREFINE8, |
122 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | // Q 6 |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | /* Q 6 */ |
123 |
PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
124 |
}; |
}; |
125 |
|
|
126 |
static int const general_presets[7] = { |
static int const general_presets[7] = { |
127 |
XVID_H263QUANT, // Q 0 |
XVID_H263QUANT, /* Q 0 */ |
128 |
XVID_MPEGQUANT, // Q 1 |
XVID_MPEGQUANT, /* Q 1 */ |
129 |
XVID_H263QUANT, // Q 2 |
XVID_H263QUANT, /* Q 2 */ |
130 |
XVID_H263QUANT | XVID_HALFPEL, // Q 3 |
XVID_H263QUANT | XVID_HALFPEL, /* Q 3 */ |
131 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 4 */ |
132 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 5 */ |
133 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V // Q 6 |
XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V /* Q 6 */ |
134 |
}; |
}; |
135 |
|
|
136 |
|
|
198 |
|
|
199 |
double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.; |
double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.; |
200 |
double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.; |
double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.; |
|
double Bpsnr=0.,Bmaxpsnr=0.,Bminpsnr=999.,Bvarpsnr=0.; |
|
201 |
|
|
202 |
char filename[256]; |
char filename[256]; |
203 |
|
|
260 |
i++; |
i++; |
261 |
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
262 |
} |
} |
263 |
else if (strcmp("-h", argv[i]) == 0 || strcmp("-help", argv[i])) { |
else if (strcmp("-help", argv[i])) { |
264 |
usage(); |
usage(); |
265 |
return(0); |
return(0); |
266 |
} |
} |
276 |
****************************************************************************/ |
****************************************************************************/ |
277 |
|
|
278 |
if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) { |
if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) { |
279 |
fprintf(stderr, |
fprintf(stderr, "Trying to retreive width and height from PGM header\n"); |
|
"Trying to retreive width and height from PGM header\n", |
|
|
XDIM, |
|
|
YDIM); |
|
280 |
ARG_INPUTTYPE = 1; /* pgm */ |
ARG_INPUTTYPE = 1; /* pgm */ |
281 |
} |
} |
282 |
|
|
291 |
} |
} |
292 |
|
|
293 |
if ( ARG_FRAMERATE <= 0) { |
if ( ARG_FRAMERATE <= 0) { |
294 |
fprintf(stderr,"Wrong Fraterate %s \n",argv[5]); |
fprintf(stderr,"Wrong Framerate %s \n",argv[5]); |
295 |
return -1; |
return -1; |
296 |
} |
} |
297 |
|
|
362 |
do { |
do { |
363 |
|
|
364 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
365 |
status = read_pgmdata(in_file, in_buffer); // read PGM data (YUV-format) |
status = read_pgmdata(in_file, in_buffer); /* read PGM data (YUV-format) */ |
366 |
else |
else |
367 |
status = read_yuvdata(in_file, in_buffer); // read raw data (YUV-format) |
status = read_yuvdata(in_file, in_buffer); /* read raw data (YUV-format) */ |
368 |
|
|
369 |
if (status) |
if (status) |
370 |
{ |
{ |
422 |
* Analyse the decoded frame and compare to original |
* Analyse the decoded frame and compare to original |
423 |
****************************************************************************/ |
****************************************************************************/ |
424 |
|
|
425 |
framepsnr[filenr] = PSNR(XDIM,YDIM, in_buffer, XDIM, out_buffer, XDIM); |
framepsnr[filenr] = PSNR(XDIM,YDIM*3/2, in_buffer, XDIM, out_buffer, XDIM); |
426 |
|
|
427 |
printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]); |
printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]); |
428 |
|
|
497 |
|
|
498 |
/* Print all statistics */ |
/* Print all statistics */ |
499 |
printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br")); |
printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br")); |
500 |
printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE)); |
printf("%04d ",(ARG_QUANTI)?ARG_QUANTI:ARG_BITRATE); |
501 |
printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE); |
printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE); |
502 |
printf("size %6d ",totalsize); |
printf("size %6d ", (int)totalsize); |
503 |
printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000)); |
printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000)); |
504 |
printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM); |
printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM); |
505 |
printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime); |
printf("enc: %6.1f fps, dec: %6.1f fps \n",1000/totalenctime, 1000/totaldectime); |
506 |
printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr)); |
printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr)); |
507 |
printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr)); |
printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr)); |
508 |
printf("\n"); |
printf("\n"); |
551 |
/* Return time elapsed time in miliseconds since the program started */ |
/* Return time elapsed time in miliseconds since the program started */ |
552 |
static double msecond() |
static double msecond() |
553 |
{ |
{ |
554 |
|
#ifndef _MSC_VER |
555 |
|
struct timeval tv; |
556 |
|
gettimeofday(&tv, 0); |
557 |
|
return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3; |
558 |
|
#else |
559 |
clock_t clk; |
clock_t clk; |
|
|
|
560 |
clk = clock(); |
clk = clock(); |
|
|
|
561 |
return clk * 1000 / CLOCKS_PER_SEC; |
return clk * 1000 / CLOCKS_PER_SEC; |
562 |
|
#endif |
563 |
} |
} |
564 |
|
|
565 |
|
|
631 |
fprintf(stderr, " -q integer : quality ([0..5])\n"); |
fprintf(stderr, " -q integer : quality ([0..5])\n"); |
632 |
fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); |
fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); |
633 |
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"); |
634 |
fprintf(stderr, " -h, -help : prints this help message\n"); |
fprintf(stderr, " -help : prints this help message\n"); |
635 |
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); |
636 |
fprintf(stderr, " (* means default)\n"); |
fprintf(stderr, " (* means default)\n"); |
637 |
|
|
704 |
static int read_yuvdata(FILE* handle, unsigned char *image) |
static int read_yuvdata(FILE* handle, unsigned char *image) |
705 |
{ |
{ |
706 |
|
|
707 |
if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != IMAGE_SIZE(XDIM, YDIM)) |
if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != (unsigned int)IMAGE_SIZE(XDIM, YDIM)) |
708 |
return 1; |
return 1; |
709 |
else |
else |
710 |
return 0; |
return 0; |
825 |
XVID_ENC_STATS xstats; |
XVID_ENC_STATS xstats; |
826 |
|
|
827 |
xframe.bitstream = bitstream; |
xframe.bitstream = bitstream; |
828 |
xframe.length = -1; // this is written by the routine |
xframe.length = -1; /* this is written by the routine */ |
829 |
|
|
830 |
xframe.image = image; |
xframe.image = image; |
831 |
xframe.colorspace = XVID_CSP_YV12; // defined in <xvid.h> |
xframe.colorspace = XVID_CSP_YV12; /* defined in <xvid.h> */ |
832 |
|
|
833 |
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) */ |
834 |
|
|
835 |
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) */ |
836 |
|
|
837 |
xframe.motion = motion_presets[ARG_QUALITY]; |
xframe.motion = motion_presets[ARG_QUALITY]; |
838 |
xframe.general = general_presets[ARG_QUALITY]; |
xframe.general = general_presets[ARG_QUALITY]; |
894 |
xframe.length = m4v_size; |
xframe.length = m4v_size; |
895 |
xframe.image = out_buffer; |
xframe.image = out_buffer; |
896 |
xframe.stride = XDIM; |
xframe.stride = XDIM; |
897 |
xframe.colorspace = XVID_CSP_YV12; // XVID_CSP_USER is fastest (no memcopy involved) |
xframe.colorspace = XVID_CSP_YV12; /* XVID_CSP_USER is fastest (no memcopy involved) */ |
898 |
|
|
899 |
xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL); |
xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL); |
900 |
|
|