Mercurial > mplayer.hg
comparison libmpcodecs/ve_xvid4.c @ 11920:886e33d9dd10
psnr and debug option added
author | iive |
---|---|
date | Wed, 04 Feb 2004 23:18:25 +0000 |
parents | 8eb96d751dcd |
children | d870d266634e |
comparison
equal
deleted
inserted
replaced
11919:f7c2ea48a935 | 11920:886e33d9dd10 |
---|---|
29 #include <stdlib.h> | 29 #include <stdlib.h> |
30 #include <string.h> | 30 #include <string.h> |
31 #include <errno.h> | 31 #include <errno.h> |
32 #include <math.h> | 32 #include <math.h> |
33 #include <limits.h> | 33 #include <limits.h> |
34 #include <time.h> | |
34 | 35 |
35 #include "../config.h" | 36 #include "../config.h" |
36 #include "../mp_msg.h" | 37 #include "../mp_msg.h" |
37 | 38 |
38 #ifdef HAVE_XVID4 | 39 #ifdef HAVE_XVID4 |
163 static int xvidenc_turbo = 0; | 164 static int xvidenc_turbo = 0; |
164 static int xvidenc_stats = 0; | 165 static int xvidenc_stats = 0; |
165 static int xvidenc_max_key_interval = 0; /* Let xvidcore set a 10s interval by default */ | 166 static int xvidenc_max_key_interval = 0; /* Let xvidcore set a 10s interval by default */ |
166 static int xvidenc_frame_drop_ratio = 0; | 167 static int xvidenc_frame_drop_ratio = 0; |
167 static int xvidenc_greyscale = 0; | 168 static int xvidenc_greyscale = 0; |
169 static int xvidenc_debug = 0; | |
170 static int xvidenc_psnr = 0; | |
168 | 171 |
169 static int xvidenc_max_bframes = 2; | 172 static int xvidenc_max_bframes = 2; |
170 static int xvidenc_bquant_ratio = 150; | 173 static int xvidenc_bquant_ratio = 150; |
171 static int xvidenc_bquant_offset = 100; | 174 static int xvidenc_bquant_offset = 100; |
172 static int xvidenc_bframe_threshold = 0; | 175 static int xvidenc_bframe_threshold = 0; |
224 {"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | 227 {"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
225 {"frame_drop_ratio", &xvidenc_frame_drop_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | 228 {"frame_drop_ratio", &xvidenc_frame_drop_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, |
226 {"max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, | 229 {"max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, |
227 {"greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | 230 {"greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
228 {"turbo", &xvidenc_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | 231 {"turbo", &xvidenc_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
232 {"debug", &xvidenc_debug, CONF_TYPE_INT , 0 ,0,-1,NULL}, | |
229 {"stats", &xvidenc_stats, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | 233 {"stats", &xvidenc_stats, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
234 {"psnr", &xvidenc_psnr , CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
230 | 235 |
231 | 236 |
232 /* section [quantizer] */ | 237 /* section [quantizer] */ |
233 {"min_iquant", &xvidenc_min_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | 238 {"min_iquant", &xvidenc_min_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, |
234 {"max_iquant", &xvidenc_max_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | 239 {"max_iquant", &xvidenc_max_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, |
296 | 301 |
297 /* Min & Max PSNR */ | 302 /* Min & Max PSNR */ |
298 int min_sse_y; | 303 int min_sse_y; |
299 int min_sse_u; | 304 int min_sse_u; |
300 int min_sse_v; | 305 int min_sse_v; |
306 int min_framenum; | |
301 int max_sse_y; | 307 int max_sse_y; |
302 int max_sse_u; | 308 int max_sse_u; |
303 int max_sse_v; | 309 int max_sse_v; |
310 int max_framenum; | |
304 | 311 |
312 int pixels; | |
305 int d_width, d_height; | 313 int d_width, d_height; |
306 } xvid_mplayer_module_t; | 314 } xvid_mplayer_module_t; |
307 | 315 |
308 static void dispatch_settings(xvid_mplayer_module_t *mod); | 316 static void dispatch_settings(xvid_mplayer_module_t *mod); |
309 static int set_create_struct(xvid_mplayer_module_t *mod); | 317 static int set_create_struct(xvid_mplayer_module_t *mod); |
385 /* Destroy xvid instance */ | 393 /* Destroy xvid instance */ |
386 xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL); | 394 xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL); |
387 | 395 |
388 /* Display stats */ | 396 /* Display stats */ |
389 if(mod->frames) { | 397 if(mod->frames) { |
390 int pixels; | |
391 | |
392 mod->sse_y /= mod->frames; | 398 mod->sse_y /= mod->frames; |
393 mod->sse_u /= mod->frames; | 399 mod->sse_u /= mod->frames; |
394 mod->sse_v /= mod->frames; | 400 mod->sse_v /= mod->frames; |
395 | |
396 pixels = mod->create.width*mod->create.height; | |
397 | 401 |
398 #define SSE2PSNR(sse, nbpixels) \ | 402 #define SSE2PSNR(sse, nbpixels) \ |
399 ((!(sse)) ? 99.99f : 48.131f - 10*(double)log10((double)(sse)/(double)((nbpixels)))) | 403 ((!(sse)) ? 99.99f : 48.131f - 10*(double)log10((double)(sse)/(double)((nbpixels)))) |
400 mp_msg(MSGT_MENCODER, MSGL_INFO, | 404 mp_msg(MSGT_MENCODER, MSGL_INFO, |
401 "The value 99.99dB is a special value and represents " | 405 "The value 99.99dB is a special value and represents " |
402 "the upper range limit\n"); | 406 "the upper range limit\n"); |
403 mp_msg(MSGT_MENCODER, MSGL_INFO, | 407 mp_msg(MSGT_MENCODER, MSGL_INFO, |
404 "xvid: Min PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB\n", | 408 "xvid: Min PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, in frame %d\n", |
405 SSE2PSNR(mod->max_sse_y, pixels), | 409 SSE2PSNR(mod->max_sse_y, mod->pixels), |
406 SSE2PSNR(mod->max_sse_u, pixels/4), | 410 SSE2PSNR(mod->max_sse_u, mod->pixels/4), |
407 SSE2PSNR(mod->max_sse_v, pixels/4)); | 411 SSE2PSNR(mod->max_sse_v, mod->pixels/4), |
412 mod->max_framenum); | |
408 mp_msg(MSGT_MENCODER, MSGL_INFO, | 413 mp_msg(MSGT_MENCODER, MSGL_INFO, |
409 "xvid: Average PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB\n", | 414 "xvid: Average PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, for %d frames\n", |
410 SSE2PSNR(mod->sse_y, pixels), | 415 SSE2PSNR(mod->sse_y, mod->pixels), |
411 SSE2PSNR(mod->sse_u, pixels/4), | 416 SSE2PSNR(mod->sse_u, mod->pixels/4), |
412 SSE2PSNR(mod->sse_v, pixels/4)); | 417 SSE2PSNR(mod->sse_v, mod->pixels/4), |
418 mod->frames); | |
413 mp_msg(MSGT_MENCODER, MSGL_INFO, | 419 mp_msg(MSGT_MENCODER, MSGL_INFO, |
414 "xvid: Max PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB\n", | 420 "xvid: Max PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, in frame %d\n", |
415 SSE2PSNR(mod->min_sse_y, pixels), | 421 SSE2PSNR(mod->min_sse_y, mod->pixels), |
416 SSE2PSNR(mod->min_sse_u, pixels/4), | 422 SSE2PSNR(mod->min_sse_u, mod->pixels/4), |
417 SSE2PSNR(mod->min_sse_v, pixels/4)); | 423 SSE2PSNR(mod->min_sse_v, mod->pixels/4), |
418 } | 424 mod->min_framenum); |
419 #undef SSE2PSNR | 425 } |
420 | 426 |
421 /* ToDo: free matrices, and some string settings (quant method, matrix | 427 /* ToDo: free matrices, and some string settings (quant method, matrix |
422 * filenames...) */ | 428 * filenames...) */ |
423 | 429 |
424 return; | 430 return; |
493 /* If size is == 0, we're done with that frame */ | 499 /* If size is == 0, we're done with that frame */ |
494 if(size == 0) return(FINE); | 500 if(size == 0) return(FINE); |
495 | 501 |
496 /* Did xvidcore returned stats about an encoded frame ? (asynchronous) */ | 502 /* Did xvidcore returned stats about an encoded frame ? (asynchronous) */ |
497 if(xvidenc_stats && stats.type > 0) { | 503 if(xvidenc_stats && stats.type > 0) { |
498 mod->frames++; | |
499 mod->sse_y += stats.sse_y; | 504 mod->sse_y += stats.sse_y; |
500 mod->sse_u += stats.sse_u; | 505 mod->sse_u += stats.sse_u; |
501 mod->sse_v += stats.sse_v; | 506 mod->sse_v += stats.sse_v; |
502 | 507 |
503 if(mod->min_sse_y > stats.sse_y) { | 508 if(mod->min_sse_y > stats.sse_y) { |
504 mod->min_sse_y = stats.sse_y; | 509 mod->min_sse_y = stats.sse_y; |
505 mod->min_sse_u = stats.sse_u; | 510 mod->min_sse_u = stats.sse_u; |
506 mod->min_sse_v = stats.sse_v; | 511 mod->min_sse_v = stats.sse_v; |
512 mod->min_framenum = mod->frames; | |
507 } | 513 } |
508 | 514 |
509 if(mod->max_sse_y < stats.sse_y) { | 515 if(mod->max_sse_y < stats.sse_y) { |
510 mod->max_sse_y = stats.sse_y; | 516 mod->max_sse_y = stats.sse_y; |
511 mod->max_sse_u = stats.sse_u; | 517 mod->max_sse_u = stats.sse_u; |
512 mod->max_sse_v = stats.sse_v; | 518 mod->max_sse_v = stats.sse_v; |
519 mod->max_framenum = mod->frames; | |
513 } | 520 } |
514 } | 521 if (xvidenc_psnr) { |
522 static FILE *fvstats = NULL; | |
523 char filename[20]; | |
524 | |
525 if (!fvstats) { | |
526 time_t today2; | |
527 struct tm *today; | |
528 today2 = time (NULL); | |
529 today = localtime (&today2); | |
530 sprintf (filename, "psnr_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); | |
531 fvstats = fopen (filename,"w"); | |
532 if (!fvstats) { | |
533 perror ("fopen"); | |
534 xvidenc_psnr = 0; // disable block | |
535 } | |
536 } | |
537 fprintf (fvstats, "%6d, %2d, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n", | |
538 mod->frames, | |
539 stats.quant, | |
540 stats.length, | |
541 SSE2PSNR (stats.sse_y, mod->pixels), | |
542 SSE2PSNR (stats.sse_u, mod->pixels / 4), | |
543 SSE2PSNR (stats.sse_v, mod->pixels / 4), | |
544 SSE2PSNR (stats.sse_y + stats.sse_u + stats.sse_v,(double)mod->pixels * 1.5), | |
545 stats.type==1?'I':stats.type==2?'P':stats.type==3?'B':stats.type?'S':'?' | |
546 ); | |
547 } | |
548 mod->frames++; | |
549 | |
550 } | |
551 #undef SSE2PSNR | |
515 | 552 |
516 /* xvidcore outputed bitstream -- mux it */ | 553 /* xvidcore outputed bitstream -- mux it */ |
517 muxer_write_chunk(mod->mux, | 554 muxer_write_chunk(mod->mux, |
518 size, | 555 size, |
519 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0); | 556 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0); |
588 } | 625 } |
589 | 626 |
590 /* Initialize the xvid_gbl_init structure */ | 627 /* Initialize the xvid_gbl_init structure */ |
591 memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); | 628 memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); |
592 xvid_gbl_init.version = XVID_VERSION; | 629 xvid_gbl_init.version = XVID_VERSION; |
630 xvid_gbl_init.debug = xvidenc_debug; | |
593 | 631 |
594 /* Initialize the xvidcore library */ | 632 /* Initialize the xvidcore library */ |
595 if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) { | 633 if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) { |
596 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n"); | 634 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n"); |
597 return(BAD); | 635 return(BAD); |
642 if(xvidenc_packed) | 680 if(xvidenc_packed) |
643 create->global |= XVID_GLOBAL_PACKED; | 681 create->global |= XVID_GLOBAL_PACKED; |
644 | 682 |
645 if(xvidenc_closed_gop) | 683 if(xvidenc_closed_gop) |
646 create->global |= XVID_GLOBAL_CLOSED_GOP; | 684 create->global |= XVID_GLOBAL_CLOSED_GOP; |
685 | |
686 if(xvidenc_psnr) | |
687 xvidenc_stats = 1; | |
647 | 688 |
648 if(xvidenc_stats) | 689 if(xvidenc_stats) |
649 create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE; | 690 create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE; |
650 | 691 |
651 create->num_zones = 0; | 692 create->num_zones = 0; |
856 | 897 |
857 /* Width and Height */ | 898 /* Width and Height */ |
858 create->width = mod->mux->bih->biWidth; | 899 create->width = mod->mux->bih->biWidth; |
859 create->height = mod->mux->bih->biHeight; | 900 create->height = mod->mux->bih->biHeight; |
860 | 901 |
902 /* Pixels are needed for PSNR calculations */ | |
903 mod->pixels = create->width * create->height; | |
904 | |
861 /* FPS */ | 905 /* FPS */ |
862 create->fincr = mod->mux->h.dwScale; | 906 create->fincr = mod->mux->h.dwScale; |
863 create->fbase = mod->mux->h.dwRate; | 907 create->fbase = mod->mux->h.dwRate; |
864 | 908 |
865 /* Encodings zones */ | 909 /* Encodings zones */ |