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.3 2003-03-11 01:08:10 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[] = { |
84 |
/* Maximum number of frames to encode */ |
/* Maximum number of frames to encode */ |
85 |
#define ABS_MAXFRAMENR 9999 |
#define ABS_MAXFRAMENR 9999 |
86 |
|
|
87 |
|
static int ARG_STATS = 0; |
88 |
static int ARG_BITRATE = 900; |
static int ARG_BITRATE = 900; |
89 |
static int ARG_QUANTI = 0; |
static int ARG_QUANTI = 0; |
90 |
static int ARG_QUALITY = 5; |
static int ARG_QUALITY = 5; |
141 |
static int enc_stop(); |
static int enc_stop(); |
142 |
static int enc_main(unsigned char* image, |
static int enc_main(unsigned char* image, |
143 |
unsigned char* bitstream, |
unsigned char* bitstream, |
144 |
long *frametype); |
long *frametype, |
145 |
|
int stats[3]); |
146 |
|
|
147 |
/***************************************************************************** |
/***************************************************************************** |
148 |
* Main function |
* Main function |
218 |
i++; |
i++; |
219 |
ARG_INPUTFILE = argv[i]; |
ARG_INPUTFILE = argv[i]; |
220 |
} |
} |
221 |
|
else if (strcmp("-s", argv[i]) == 0) { |
222 |
|
ARG_STATS = 1; |
223 |
|
} |
224 |
else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) { |
225 |
i++; |
i++; |
226 |
ARG_INPUTTYPE = atoi(argv[i]); |
ARG_INPUTTYPE = atoi(argv[i]); |
233 |
i++; |
i++; |
234 |
ARG_QUANTI = atoi(argv[i]); |
ARG_QUANTI = atoi(argv[i]); |
235 |
} |
} |
236 |
else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-m", argv[i]) == 0) { |
237 |
i++; |
ARG_SAVEMPEGSTREAM = 1; |
|
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
|
238 |
} |
} |
239 |
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { |
240 |
i++; |
i++; |
345 |
|
|
346 |
do { |
do { |
347 |
|
|
348 |
if (ARG_INPUTTYPE) |
char *type; |
349 |
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) */ |
|
350 |
|
|
351 |
if (status) |
if(ARG_INPUTTYPE) { |
352 |
{ |
/* read PGM data (YUV-format) */ |
353 |
|
status = read_pgmdata(in_file, in_buffer); |
354 |
|
} else { |
355 |
|
/* read raw data (YUV-format) */ |
356 |
|
status = read_yuvdata(in_file, in_buffer); |
357 |
|
} |
358 |
|
|
359 |
|
if(status) { |
360 |
/* Couldn't read image, most likely end-of-file */ |
/* Couldn't read image, most likely end-of-file */ |
361 |
continue; |
continue; |
362 |
} |
} |
366 |
****************************************************************************/ |
****************************************************************************/ |
367 |
|
|
368 |
enctime = msecond(); |
enctime = msecond(); |
369 |
m4v_size = enc_main(in_buffer, mp4_buffer, &frame_type); |
m4v_size = enc_main(in_buffer, mp4_buffer, &frame_type, stats); |
370 |
enctime = msecond() - enctime; |
enctime = msecond() - enctime; |
371 |
|
|
372 |
/* Not coded frames return 0 */ |
/* Not coded frames return 0 */ |
373 |
if(m4v_size == 0) goto next_frame; |
if(m4v_size == 0) goto next_frame; |
374 |
|
|
375 |
{ |
/* Write the Frame statistics */ |
|
char *type; |
|
|
|
|
376 |
switch(frame_type) { |
switch(frame_type) { |
377 |
case XVID_TYPE_IVOP: |
case XVID_TYPE_IVOP: |
378 |
type = "I"; |
type = "I"; |
386 |
case XVID_TYPE_SVOP: |
case XVID_TYPE_SVOP: |
387 |
type = "S"; |
type = "S"; |
388 |
break; |
break; |
389 |
|
case XVID_TYPE_NOTHING: |
390 |
|
type = "N"; |
391 |
|
break; |
392 |
default: |
default: |
393 |
type = "Unknown"; |
type = "U"; |
394 |
break; |
break; |
395 |
} |
} |
396 |
|
|
397 |
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", |
398 |
(int)filenr, type, (float)enctime, (int)m4v_size); |
(int)filenr, |
399 |
|
type, |
400 |
|
(float)enctime, |
401 |
|
(int)m4v_size); |
402 |
|
|
403 |
|
if(ARG_STATS) { |
404 |
|
printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f", |
405 |
|
(stats[0] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[0]/((float)(XDIM)*(YDIM))), |
406 |
|
(stats[1] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[1]/((float)(XDIM)*(YDIM)/4)), |
407 |
|
(stats[2] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[2]/((float)(XDIM)*(YDIM)/4))); |
408 |
} |
} |
409 |
|
|
410 |
|
printf("\n"); |
411 |
|
|
412 |
/* Update encoding time stats */ |
/* Update encoding time stats */ |
413 |
totalenctime += enctime; |
totalenctime += enctime; |
414 |
totalsize += m4v_size; |
totalsize += m4v_size; |
440 |
if (ARG_INPUTTYPE) |
if (ARG_INPUTTYPE) |
441 |
status = read_pgmheader(in_file); |
status = read_pgmheader(in_file); |
442 |
|
|
443 |
if(frame_type != 5) filenr++; |
filenr++; |
444 |
|
|
445 |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
} while ( (!status) && (filenr<ARG_MAXFRAMENR) ); |
446 |
|
|
456 |
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", |
457 |
totalenctime, 1000/totalenctime, (int)totalsize); |
totalenctime, 1000/totalenctime, (int)totalsize); |
458 |
|
|
459 |
|
|
460 |
/***************************************************************************** |
/***************************************************************************** |
461 |
* XviD PART Stop |
* XviD PART Stop |
462 |
****************************************************************************/ |
****************************************************************************/ |
524 |
fprintf(stderr, " -bqo integer : bframe quantizer offset (default=100)\n"); |
fprintf(stderr, " -bqo integer : bframe quantizer offset (default=100)\n"); |
525 |
fprintf(stderr, " -f float : target framerate (>0)\n"); |
fprintf(stderr, " -f float : target framerate (>0)\n"); |
526 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
527 |
|
fprintf(stderr, " -s : print stats about encoded frames\n"); |
528 |
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); |
529 |
fprintf(stderr, " -n integer : number of frames to encode\n"); |
fprintf(stderr, " -n integer : number of frames to encode\n"); |
530 |
fprintf(stderr, " -q integer : quality ([0..5])\n"); |
fprintf(stderr, " -q integer : quality ([0..5])\n"); |
531 |
fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); |
fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); |
532 |
fprintf(stderr, " -m boolean : save mpeg4 raw stream (0 False*, !=0 True)\n"); |
fprintf(stderr, " -m : save mpeg4 raw stream\n"); |
533 |
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"); |
534 |
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"); |
535 |
fprintf(stderr, " When this option is used : save to 'string' file\n"); |
fprintf(stderr, " When this option is used : save to 'string' file\n"); |
684 |
xvid_enc_create.frame_drop_ratio = 0; |
xvid_enc_create.frame_drop_ratio = 0; |
685 |
|
|
686 |
/* Global encoder options */ |
/* Global encoder options */ |
687 |
xvid_enc_create.global = 0; |
xvid_enc_create.global = (ARG_STATS)?XVID_EXTRASTATS_ENABLE:0; |
688 |
|
|
689 |
/* 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 */ |
690 |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); |
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); |
707 |
|
|
708 |
static int enc_main(unsigned char* image, |
static int enc_main(unsigned char* image, |
709 |
unsigned char* bitstream, |
unsigned char* bitstream, |
710 |
long *frametype) |
long *frametype, |
711 |
|
int stats[3]) |
712 |
{ |
{ |
713 |
int ret; |
int ret; |
714 |
|
|
749 |
xvid_enc_frame.quant_intra_matrix = NULL; |
xvid_enc_frame.quant_intra_matrix = NULL; |
750 |
xvid_enc_frame.quant_inter_matrix = NULL; |
xvid_enc_frame.quant_inter_matrix = NULL; |
751 |
|
|
752 |
|
/* Foll proof */ |
753 |
|
xvid_enc_stats[0].sse_y = 0; |
754 |
|
xvid_enc_stats[0].sse_v = 0; |
755 |
|
xvid_enc_stats[0].sse_u = 0; |
756 |
|
|
757 |
|
/* Encode the frame */ |
758 |
|
xvid_enc_frame.vop_flags |= (ARG_STATS)?XVID_EXTRASTATS:0; |
759 |
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); |
760 |
|
|
761 |
*frametype = xvid_enc_stats[0].type; |
*frametype = xvid_enc_stats[0].type; |
762 |
|
stats[0] = xvid_enc_stats[0].sse_y; |
763 |
|
stats[1] = xvid_enc_stats[0].sse_u; |
764 |
|
stats[2] = xvid_enc_stats[0].sse_v; |
765 |
|
|
766 |
return(ret); |
return(ret); |
767 |
} |
} |