[FFmpeg-cvslog] avfilter/vf_showinfo: also calculate and show mean and standard deviation

Michael Niedermayer git at videolan.org
Sat May 3 07:00:04 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat May  3 06:02:42 2014 +0200| [09725c1d2bed15b52b7c59dbb208f5f78d325ccc] | committer: Michael Niedermayer

avfilter/vf_showinfo: also calculate and show mean and standard deviation

Fixes Ticket3013

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=09725c1d2bed15b52b7c59dbb208f5f78d325ccc
---

 libavfilter/vf_showinfo.c |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index f0822ec..ec4bed1 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -65,11 +65,23 @@ static void dump_stereo3d(AVFilterContext *ctx, AVFrameSideData *sd)
         av_log(ctx, AV_LOG_INFO, " (inverted)");
 }
 
+static void update_sample_stats(const uint8_t *src, int len, int64_t *sum, int64_t *sum2)
+{
+    int i;
+
+    for (i = 0; i < len; i++) {
+        *sum += src[i];
+        *sum2 += src[i] * src[i];
+    }
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
     AVFilterContext *ctx = inlink->dst;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     uint32_t plane_checksum[4] = {0}, checksum = 0;
+    int64_t sum[4] = {0}, sum2[4] = {0};
+    int32_t pixelcount[4] = {0};
     int i, plane, vsub = desc->log2_chroma_h;
 
     for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
@@ -83,6 +95,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         for (i = 0; i < h; i++) {
             plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
             checksum = av_adler32_update(checksum, data, linesize);
+
+            update_sample_stats(data, linesize, sum+plane, sum2+plane);
+            pixelcount[plane] += linesize;
             data += frame->linesize[plane];
         }
     }
@@ -104,7 +119,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 
     for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
         av_log(ctx, AV_LOG_INFO, " %08"PRIX32, plane_checksum[plane]);
-    av_log(ctx, AV_LOG_INFO, "]\n");
+    av_log(ctx, AV_LOG_INFO, "] mean:[");
+    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
+        av_log(ctx, AV_LOG_INFO, "%"PRId64" ", (sum[plane] + pixelcount[plane]/2) / pixelcount[plane]);
+    av_log(ctx, AV_LOG_INFO, "\b] stdev:[");
+    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
+        av_log(ctx, AV_LOG_INFO, "%3.1f ",
+               sqrt((sum2[plane] - sum[plane]*(double)sum[plane]/pixelcount[plane])/pixelcount[plane]));
+    av_log(ctx, AV_LOG_INFO, "\b]\n");
 
     for (i = 0; i < frame->nb_side_data; i++) {
         AVFrameSideData *sd = frame->side_data[i];



More information about the ffmpeg-cvslog mailing list