[Ffmpeg-devel] Changing "-vstats" option behaviour

Benoit Fouet benoit.fouet
Wed Apr 25 11:00:23 CEST 2007


Hi,

Stefano Sabatini wrote:
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 8759)
> +++ ffmpeg.c	(working copy)
> @@ -166,7 +166,6 @@
>  static int do_hex_dump = 0;
>  static int do_pkt_dump = 0;
>  static int do_psnr = 0;
> -static int do_vstats = 0;
>  static int do_pass = 0;
>  static char *pass_logfilename = NULL;
>  static int audio_stream_copy = 0;
> @@ -177,6 +176,8 @@
>  static int copy_ts= 0;
>  static int opt_shortest = 0; //
>  static int video_global_header = 0;
> +static char *vstats_filename;
> +static FILE *fvstats;
>  
>  static int rate_emu = 0;
>  
> @@ -841,22 +842,14 @@
>  static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
>                             int frame_size)
>  {
> -    static FILE *fvstats=NULL;
> -    char filename[40];
> -    time_t today2;
> -    struct tm *today;
>      AVCodecContext *enc;
>      int frame_number;
>      int64_t ti;
>      double ti1, bitrate, avg_bitrate;
>  
> +    /* this is executed just the first time do_video_stats is called */
>      if (!fvstats) {
> -        today2 = time(NULL);
> -        today = localtime(&today2);
> -        snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour,
> -                                               today->tm_min,
> -                                               today->tm_sec);
> -        fvstats = fopen(filename,"w");
> +        fvstats = fopen(vstats_filename, "w");
>          if (!fvstats) {
>              perror("fopen");
>              exit(1);
> @@ -1197,7 +1190,7 @@
>                          case CODEC_TYPE_VIDEO:
>                              do_video_out(os, ost, ist, &picture, &frame_size);
>                              video_size += frame_size;
> -                            if (do_vstats && frame_size)
> +                            if (vstats_filename && frame_size)
>                                  do_video_stats(os, ost, frame_size);
>                              break;
>                          case CODEC_TYPE_SUBTITLE:
> @@ -3449,6 +3442,23 @@
>      }
>  }
>  
> +static void opt_vstats_file (const char *arg)
> +{
> +    av_free (vstats_filename);
> +    vstats_filename=av_strdup (arg);
> +}
> +
> +static void opt_vstats (void)
> +{
> +    char filename[40];
> +    time_t today2 = time(NULL);
> +    struct tm *today = localtime(&today2);
> +
> +    snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
> +             today->tm_sec);
> +    opt_vstats_file(filename);
> +}
> +
>  static void opt_video_bsf(const char *arg)
>  {
>      AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
> @@ -3610,7 +3620,8 @@
>      { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
>        "deinterlace pictures" },
>      { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
> -    { "vstats", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_vstats}, "dump video coding statistics to file" },
> +    { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
> +    { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
>      { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" },
>      { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
>      { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
> @@ -3806,6 +3817,11 @@
>  
>      av_free(intra_matrix);
>      av_free(inter_matrix);
> +
> +    if (fvstats)
> +        fclose(fvstats);
> +    av_free(vstats_filename);
> +
>      av_free(opt_names);
>  
>  #ifdef CONFIG_POWERPC_PERF
> Index: doc/ffmpeg-doc.texi
> ===================================================================
> --- doc/ffmpeg-doc.texi	(revision 8759)
> +++ doc/ffmpeg-doc.texi	(working copy)
> @@ -537,6 +537,8 @@
>  Calculate PSNR of compressed frames.
>  @item -vstats
>  Dump video coding statistics to @file{vstats_HHMMSS.log}.
> + at item -vstats_file file
> +Dump video coding statistics to @var{file}.
>  @item -vhook module
>  Insert video processing @var{module}. @var{module} contains the module
>  name and its parameters separated by spaces.
>   
Michael, is it ok for you ?

-- 
Purple Labs S.A.
www.purplelabs.com




More information about the ffmpeg-devel mailing list