comparison libmpcodecs/vd_ffmpeg.c @ 6828:010be15e48ad

Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified. Data in my tests was 100% the same, only type= is currently missing, as avctx->key_frame isn't set on decoding and I dunno where to get that info from mplayer-core.
author atmos4
date Sun, 28 Jul 2002 15:54:26 +0000
parents 1118278f7644
children a709a7662cd1
comparison
equal deleted inserted replaced
6827:b1f788bca721 6828:010be15e48ad
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <assert.h> 3 #include <assert.h>
4 #include <time.h>
4 5
5 #include "config.h" 6 #include "config.h"
6 #include "mp_msg.h" 7 #include "mp_msg.h"
7 #include "help_mp.h" 8 #include "help_mp.h"
8 9
60 static void get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type); 61 static void get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type);
61 62
62 static int lavc_param_workaround_bugs=0; 63 static int lavc_param_workaround_bugs=0;
63 static int lavc_param_error_resilience=0; 64 static int lavc_param_error_resilience=0;
64 static int lavc_param_gray=0; 65 static int lavc_param_gray=0;
66 static int lavc_param_vstats=0;
65 67
66 struct config lavc_decode_opts_conf[]={ 68 struct config lavc_decode_opts_conf[]={
67 #if LIBAVCODEC_BUILD >= 4611 69 #if LIBAVCODEC_BUILD >= 4611
68 {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, 70 {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL},
69 {"ver", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, -1, 99, NULL}, 71 {"ver", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, -1, 99, NULL},
70 #endif 72 #endif
71 #if LIBAVCODEC_BUILD >= 4614 73 #if LIBAVCODEC_BUILD >= 4614
72 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, 74 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL},
73 #endif 75 #endif
76 {"vstats", &lavc_param_vstats, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL},
74 {NULL, NULL, 0, 0, 0, 0, NULL} 77 {NULL, NULL, 0, 0, 0, 0, NULL}
75 }; 78 };
76 79
77 // to set/get/query special features/parameters 80 // to set/get/query special features/parameters
78 static int control(sh_video_t *sh,int cmd,void* arg,...){ 81 static int control(sh_video_t *sh,int cmd,void* arg,...){
379 #endif 382 #endif
380 383
381 ret = avcodec_decode_video(avctx, &lavc_picture, 384 ret = avcodec_decode_video(avctx, &lavc_picture,
382 &got_picture, data, len); 385 &got_picture, data, len);
383 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); 386 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
387
388 //-- vstats generation
389 while(lavc_param_vstats){ // always one time loop
390 static FILE *fvstats=NULL;
391 char filename[20];
392 static int all_len=0;
393 static int frame_number=0;
394 static double all_frametime=0.0;
395
396 if(!fvstats) {
397 time_t today2;
398 struct tm *today;
399 today2 = time(NULL);
400 today = localtime(&today2);
401 sprintf(filename, "vstats_%02d%02d%02d.log", today->tm_hour,
402 today->tm_min, today->tm_sec);
403 fvstats = fopen(filename,"w");
404 if(!fvstats) {
405 perror("fopen");
406 lavc_param_vstats=0; // disable block
407 break;
408 /*exit(1);*/
409 }
410 }
411
412 all_len+=len;
413 all_frametime+=sh->frametime;
414 fprintf(fvstats, "frame= %5d q= %2d f_size= %6d s_size= %8.0fkB ",
415 ++frame_number, avctx->quality, len, (double)all_len/1024);
416 fprintf(fvstats, "time= %0.3f br= %7.1fkbit/s avg_br= %7.1fkbit/s\n",
417 all_frametime, (double)(len*8)/sh->frametime/1000.0,
418 (double)(all_len*8)/all_frametime/1000.0);
419 // FIXME key_frame isn't set by lavc on decoding! ::atmos
420 //fprintf(fvstats, "type= %c\n", avctx->key_frame == 1 ? 'I' : 'P');
421 break;
422 }
423 //--
424
384 if(!got_picture) return NULL; // skipped image 425 if(!got_picture) return NULL; // skipped image
385 426
386 if(init_vo(sh)<0) return NULL; 427 if(init_vo(sh)<0) return NULL;
387 428
388 #if LIBAVCODEC_BUILD > 4615 429 #if LIBAVCODEC_BUILD > 4615