diff mbox series

[FFmpeg-devel] ffplay: always show stats at all log levels if requested by user

Message ID 20200403111108.9309-1-ffmpeg@gyani.pro
State Superseded
Headers show
Series [FFmpeg-devel] ffplay: always show stats at all log levels if requested by user | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Gyan Doshi April 3, 2020, 11:11 a.m. UTC
Since 3b491c5a500, stats would be hidden if loglevel was lower than
info, even if -stats was set.
---
 fftools/ffplay.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

Comments

Marton Balint April 3, 2020, 3:56 p.m. UTC | #1
On Fri, 3 Apr 2020, Gyan Doshi wrote:

> Since 3b491c5a500, stats would be hidden if loglevel was lower than
> info, even if -stats was set.

Please mention ticket #6962.

> ---
> fftools/ffplay.c | 36 ++++++++++++++++++++++++------------
> 1 file changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/fftools/ffplay.c b/fftools/ffplay.c
> index 2ed4b22d3e..d529c60e81 100644
> --- a/fftools/ffplay.c
> +++ b/fftools/ffplay.c
> @@ -40,6 +40,7 @@
> #include "libavutil/samplefmt.h"
> #include "libavutil/avassert.h"
> #include "libavutil/time.h"
> +#include "libavutil/bprint.h"
> #include "libavformat/avformat.h"
> #include "libavdevice/avdevice.h"
> #include "libswscale/swscale.h"
> @@ -326,7 +327,7 @@ static int display_disable;
> static int borderless;
> static int alwaysontop;
> static int startup_volume = 100;
> -static int show_status = 1;
> +static int show_status = -1;
> static int av_sync_type = AV_SYNC_AUDIO_MASTER;
> static int64_t start_time = AV_NOPTS_VALUE;
> static int64_t duration = AV_NOPTS_VALUE;
> @@ -1692,6 +1693,7 @@ display:
>     }
>     is->force_refresh = 0;
>     if (show_status) {
> +        AVBPrint buf;
>         static int64_t last_time;
>         int64_t cur_time;
>         int aqsize, vqsize, sqsize;
> @@ -1715,18 +1717,28 @@ display:
>                 av_diff = get_master_clock(is) - get_clock(&is->vidclk);
>             else if (is->audio_st)
>                 av_diff = get_master_clock(is) - get_clock(&is->audclk);
> -            av_log(NULL, AV_LOG_INFO,
> -                   "%7.2f %s:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64"   \r",
> -                   get_master_clock(is),
> -                   (is->audio_st && is->video_st) ? "A-V" : (is->video_st ? "M-V" : (is->audio_st ? "M-A" : "   ")),
> -                   av_diff,
> -                   is->frame_drops_early + is->frame_drops_late,
> -                   aqsize / 1024,
> -                   vqsize / 1024,
> -                   sqsize,
> -                   is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
> -                   is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
> +
> +            av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
> +            av_bprintf(&buf,
> +                      "%7.2f %s:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64"   \r",
> +                      get_master_clock(is),
> +                      (is->audio_st && is->video_st) ? "A-V" : (is->video_st ? "M-V" : (is->audio_st ? "M-A" : "   ")),
> +                      av_diff,
> +                      is->frame_drops_early + is->frame_drops_late,
> +                      aqsize / 1024,
> +                      vqsize / 1024,
> +                      sqsize,
> +                      is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
> +                      is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
> +
> +            if (show_status == 1 && AV_LOG_INFO > av_log_get_level())
> +                printf("%s", buf.str);
> +            else
> +                av_log(NULL, AV_LOG_INFO, "%s", buf.str);

This is kind of strange that stats are sometimes stdout, sometimes stderr, 
we should at least try to be consistent with ffmpeg.c:

         if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
             fprintf(stderr, "%s    %c", buf.str, end);
         } else
             av_log(NULL, AV_LOG_INFO, "%s    %c", buf.str, end);

         fflush(stderr);

At least only stderr is used there...


> +
>             fflush(stdout);

And in that case this needs to be stderr.

> +            av_bprint_finalize(&buf, NULL);
> +
>             last_time = cur_time;
>         }
>     }
> --

Also the docs of the -stats option also need updating (may can be a 
separate patch because ffmpeg.c -stats docs is also outdated...)

Thanks,
Marton
Gyan Doshi April 3, 2020, 4:27 p.m. UTC | #2
On 03-04-2020 09:26 pm, Marton Balint wrote:
>
>
> On Fri, 3 Apr 2020, Gyan Doshi wrote:
>
>> Since 3b491c5a500, stats would be hidden if loglevel was lower than
>> info, even if -stats was set.
>
> Please mention ticket #6962.

Revised patch sent. I'll change the flush target in a separate patch as 
it's an independent change.

Thanks,
Gyan
diff mbox series

Patch

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 2ed4b22d3e..d529c60e81 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -40,6 +40,7 @@ 
 #include "libavutil/samplefmt.h"
 #include "libavutil/avassert.h"
 #include "libavutil/time.h"
+#include "libavutil/bprint.h"
 #include "libavformat/avformat.h"
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
@@ -326,7 +327,7 @@  static int display_disable;
 static int borderless;
 static int alwaysontop;
 static int startup_volume = 100;
-static int show_status = 1;
+static int show_status = -1;
 static int av_sync_type = AV_SYNC_AUDIO_MASTER;
 static int64_t start_time = AV_NOPTS_VALUE;
 static int64_t duration = AV_NOPTS_VALUE;
@@ -1692,6 +1693,7 @@  display:
     }
     is->force_refresh = 0;
     if (show_status) {
+        AVBPrint buf;
         static int64_t last_time;
         int64_t cur_time;
         int aqsize, vqsize, sqsize;
@@ -1715,18 +1717,28 @@  display:
                 av_diff = get_master_clock(is) - get_clock(&is->vidclk);
             else if (is->audio_st)
                 av_diff = get_master_clock(is) - get_clock(&is->audclk);
-            av_log(NULL, AV_LOG_INFO,
-                   "%7.2f %s:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64"   \r",
-                   get_master_clock(is),
-                   (is->audio_st && is->video_st) ? "A-V" : (is->video_st ? "M-V" : (is->audio_st ? "M-A" : "   ")),
-                   av_diff,
-                   is->frame_drops_early + is->frame_drops_late,
-                   aqsize / 1024,
-                   vqsize / 1024,
-                   sqsize,
-                   is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
-                   is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
+
+            av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
+            av_bprintf(&buf,
+                      "%7.2f %s:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64"   \r",
+                      get_master_clock(is),
+                      (is->audio_st && is->video_st) ? "A-V" : (is->video_st ? "M-V" : (is->audio_st ? "M-A" : "   ")),
+                      av_diff,
+                      is->frame_drops_early + is->frame_drops_late,
+                      aqsize / 1024,
+                      vqsize / 1024,
+                      sqsize,
+                      is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
+                      is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
+
+            if (show_status == 1 && AV_LOG_INFO > av_log_get_level())
+                printf("%s", buf.str);
+            else
+                av_log(NULL, AV_LOG_INFO, "%s", buf.str);
+
             fflush(stdout);
+            av_bprint_finalize(&buf, NULL);
+
             last_time = cur_time;
         }
     }