]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_psnr.c
vf_psnr/ssim: don't crash if stats_file is NULL.
[ffmpeg] / libavfilter / vf_psnr.c
index a01b2c12ce5a05f855d198a0a28abe69e553a486..36bbab259fc31a79db762c36eebd646269ba1667 100644 (file)
@@ -194,14 +194,18 @@ static av_cold int init(AVFilterContext *ctx)
     s->max_mse = -INFINITY;
 
     if (s->stats_file_str) {
-        s->stats_file = fopen(s->stats_file_str, "w");
-        if (!s->stats_file) {
-            int err = AVERROR(errno);
-            char buf[128];
-            av_strerror(err, buf, sizeof(buf));
-            av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n",
-                   s->stats_file_str, buf);
-            return err;
+        if (!strcmp(s->stats_file_str, "-")) {
+            s->stats_file = stdout;
+        } else {
+            s->stats_file = fopen(s->stats_file_str, "w");
+            if (!s->stats_file) {
+                int err = AVERROR(errno);
+                char buf[128];
+                av_strerror(err, buf, sizeof(buf));
+                av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n",
+                       s->stats_file_str, buf);
+                return err;
+            }
         }
     }
 
@@ -322,10 +326,10 @@ static av_cold void uninit(AVFilterContext *ctx)
         buf[0] = 0;
         for (j = 0; j < s->nb_components; j++) {
             int c = s->is_rgb ? s->rgba_map[j] : j;
-            av_strlcatf(buf, sizeof(buf), " %c:%0.2f", s->comps[j],
+            av_strlcatf(buf, sizeof(buf), " %c:%f", s->comps[j],
                         get_psnr(s->mse_comp[c], s->nb_frames, s->max[c]));
         }
-        av_log(ctx, AV_LOG_INFO, "PSNR%s average:%0.2f min:%0.2f max:%0.2f\n",
+        av_log(ctx, AV_LOG_INFO, "PSNR%s average:%f min:%f max:%f\n",
                buf,
                get_psnr(s->mse, s->nb_frames, s->average_max),
                get_psnr(s->max_mse, 1, s->average_max),
@@ -334,7 +338,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     ff_dualinput_uninit(&s->dinput);
 
-    if (s->stats_file)
+    if (s->stats_file && s->stats_file != stdout)
         fclose(s->stats_file);
 }