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.11.2.1 2003-03-09 00:28:09 edgomez Exp $ |
* $Id: xvid_encraw.c,v 1.11.2.2 2003-03-09 16:45:24 edgomez Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
56 |
PMV_HALFPELREFINE16, |
PMV_HALFPELREFINE16, |
57 |
PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8, |
PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8, |
58 |
PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16, |
PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16, |
59 |
PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16, |
PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16 | PMV_CHROMA16 | PMV_CHROMA8, |
60 |
}; |
}; |
61 |
|
|
62 |
static xvid_vol_t const vol_presets[] = { |
static xvid_vol_t const vol_presets[] = { |
140 |
static int enc_stop(); |
static int enc_stop(); |
141 |
static int enc_main(unsigned char* image, |
static int enc_main(unsigned char* image, |
142 |
unsigned char* bitstream, |
unsigned char* bitstream, |
143 |
long *frametype); |
long *frametype, |
144 |
|
int stats[3]); |
145 |
|
|
146 |
/***************************************************************************** |
/***************************************************************************** |
147 |
* Main function |
* Main function |
342 |
|
|
343 |
do { |
do { |
344 |
|
|
345 |
if (ARG_INPUTTYPE) |
char *type; |
346 |
status = read_pgmdata(in_file, in_buffer); /* read PGM data (YUV-format) */ |
int stats[3]; |
|
else |
|
|
status = read_yuvdata(in_file, in_buffer); /* read raw data (YUV-format) */ |
|
347 |
|
|
348 |
if (status) |
if(ARG_INPUTTYPE) { |
349 |
{ |
/* read PGM data (YUV-format) */ |
350 |
|
status = read_pgmdata(in_file, in_buffer); |
351 |
|
} else { |
352 |
|
/* read raw data (YUV-format) */ |
353 |
|
status = read_yuvdata(in_file, in_buffer); |
354 |
|
} |
355 |
|
|
356 |
|
if(status) { |
357 |
/* Couldn't read image, most likely end-of-file */ |
/* Couldn't read image, most likely end-of-file */ |
358 |
continue; |
continue; |
359 |
} |
} |
363 |
****************************************************************************/ |
****************************************************************************/ |
364 |
|
|
365 |
enctime = msecond(); |
enctime = msecond(); |
366 |
m4v_size = enc_main(in_buffer, mp4_buffer, &frame_type); |
m4v_size = enc_main(in_buffer, mp4_buffer, &frame_type, stats); |
367 |
enctime = msecond() - enctime; |
enctime = msecond() - enctime; |
368 |
|
|
369 |
/* Not coded frames return 0 */ |
/* Not coded frames return 0 */ |
370 |
if(m4v_size == 0) goto next_frame; |
if(m4v_size == 0) goto next_frame; |
371 |
|
|
372 |
{ |
/* Write the Frame statistics */ |
|
char *type; |
|
|
|
|
373 |
switch(frame_type) { |
switch(frame_type) { |
374 |
case XVID_TYPE_IVOP: |
case XVID_TYPE_IVOP: |
375 |
type = "I"; |
type = "I"; |
383 |
case XVID_TYPE_SVOP: |
case XVID_TYPE_SVOP: |
384 |
type = "S"; |
type = "S"; |
385 |
break; |
break; |
386 |
|
case XVID_TYPE_NOTHING: |
387 |
|
type = "N"; |
388 |
|
break; |
389 |
default: |
default: |
390 |
type = "Unknown"; |
type = "U"; |
391 |
break; |
break; |
392 |
} |
} |
393 |
|
|
394 |
printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d\n", |
printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d, " |
395 |
(int)filenr, type, (float)enctime, (int)m4v_size); |
"psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f\n", |
396 |
|
(int)filenr, |
397 |
} |
type, |
398 |
|
(float)enctime, |
399 |
|
(int)m4v_size, |
400 |
|
(stats[0] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[0]/((float)(XDIM)*(YDIM))), |
401 |
|
(stats[1] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[1]/((float)(XDIM)*(YDIM)/4)), |
402 |
|
(stats[2] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[2]/((float)(XDIM)*(YDIM)/4))); |
403 |
|
|
404 |
/* Update encoding time stats */ |
/* Update encoding time stats */ |
405 |
totalenctime += enctime; |
totalenctime += enctime; |
432 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
433 |
status = read_pgmheader(in_file); |
status = read_pgmheader(in_file); |
434 |
|
|
435 |
if(frame_type != 5) filenr++; |
filenr++; |
436 |
|
|
437 |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
438 |
|
|
448 |
printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n", |
printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n", |
449 |
totalenctime, 1000/totalenctime, (int)totalsize); |
totalenctime, 1000/totalenctime, (int)totalsize); |
450 |
|
|
451 |
|
|
452 |
/***************************************************************************** |
/***************************************************************************** |
453 |
* XviD PART Stop |
* XviD PART Stop |
454 |
****************************************************************************/ |
****************************************************************************/ |
675 |
xvid_enc_create.frame_drop_ratio = 0; |
xvid_enc_create.frame_drop_ratio = 0; |
676 |
|
|
677 |
/* Global encoder options */ |
/* Global encoder options */ |
678 |
xvid_enc_create.global = 0; |
xvid_enc_create.global = XVID_EXTRASTATS_ENABLE; |
679 |
|
|
680 |
/* 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 */ |
681 |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); |
698 |
|
|
699 |
static int enc_main(unsigned char* image, |
static int enc_main(unsigned char* image, |
700 |
unsigned char* bitstream, |
unsigned char* bitstream, |
701 |
long *frametype) |
long *frametype, |
702 |
|
int stats[3]) |
703 |
{ |
{ |
704 |
int ret; |
int ret; |
705 |
|
|
740 |
xvid_enc_frame.quant_intra_matrix = NULL; |
xvid_enc_frame.quant_intra_matrix = NULL; |
741 |
xvid_enc_frame.quant_inter_matrix = NULL; |
xvid_enc_frame.quant_inter_matrix = NULL; |
742 |
|
|
743 |
|
/* Foll proof */ |
744 |
|
xvid_enc_stats[0].sse_y = 0; |
745 |
|
xvid_enc_stats[0].sse_v = 0; |
746 |
|
xvid_enc_stats[0].sse_u = 0; |
747 |
|
|
748 |
|
/* Encode the frame */ |
749 |
|
xvid_enc_frame.vop_flags |= XVID_EXTRASTATS; |
750 |
ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats); |
ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats); |
751 |
|
|
752 |
*frametype = xvid_enc_stats[0].type; |
*frametype = xvid_enc_stats[0].type; |
753 |
|
stats[0] = xvid_enc_stats[0].sse_y; |
754 |
|
stats[1] = xvid_enc_stats[0].sse_u; |
755 |
|
stats[2] = xvid_enc_stats[0].sse_v; |
756 |
|
|
757 |
return(ret); |
return(ret); |
758 |
} |
} |