From 3a81775bdee7c02dac0d933f3c2b565ac5d9c97c Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Thu, 11 Aug 2016 18:10:46 +0200 Subject: avfilter/vf_signalstats: measure video bitdepth --- doc/filters.texi | 12 ++++++++++++ libavfilter/vf_signalstats.c | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index dda1c1715b..3a9e251e00 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -11946,6 +11946,18 @@ Expressed in range of [0-255]. Display the average of sample value difference between all values of the V plane in the current frame and corresponding values of the previous input frame. Expressed in range of [0-255]. + +@item YBITDEPTH +Display bit depth of Y plane in current frame. +Expressed in range of [0-16]. + +@item UBITDEPTH +Display bit depth of U plane in current frame. +Expressed in range of [0-16]. + +@item VBITDEPTH +Display bit depth of V plane in current frame. +Expressed in range of [0-16]. @end table The filter accepts the following options: diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c index 259b0a180c..00051f2cab 100644 --- a/libavfilter/vf_signalstats.c +++ b/libavfilter/vf_signalstats.c @@ -541,6 +541,11 @@ static int compute_sat_hue_metrics16(AVFilterContext *ctx, void *arg, int jobnr, return 0; } +static unsigned compute_bit_depth(uint16_t mask) +{ + return av_popcount(mask); +} + static int filter_frame8(AVFilterLink *link, AVFrame *in) { AVFilterContext *ctx = link->dst; @@ -569,6 +574,7 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) int toty = 0, totu = 0, totv = 0, totsat=0; int tothue = 0; int dify = 0, difu = 0, difv = 0; + uint16_t masky = 0, masku = 0, maskv = 0; int filtot[FILT_NUMB] = {0}; AVFrame *prev; @@ -602,6 +608,8 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) for (j = 0; j < link->h; j++) { for (i = 0; i < link->w; i++) { const int yuv = in->data[0][w + i]; + + masky |= yuv; histy[yuv]++; dify += abs(yuv - prev->data[0][pw + i]); } @@ -614,6 +622,9 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) for (i = 0; i < s->chromaw; i++) { const int yuvu = in->data[1][cw+i]; const int yuvv = in->data[2][cw+i]; + + masku |= yuvu; + maskv |= yuvv; histu[yuvu]++; difu += abs(yuvu - prev->data[1][cpw+i]); histv[yuvv]++; @@ -735,6 +746,10 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) SET_META("UDIF", "%g", 1.0 * difu / s->cfs); SET_META("VDIF", "%g", 1.0 * difv / s->cfs); + SET_META("YBITDEPTH", "%d", compute_bit_depth(masky)); + SET_META("UBITDEPTH", "%d", compute_bit_depth(masku)); + SET_META("VBITDEPTH", "%d", compute_bit_depth(maskv)); + for (fil = 0; fil < FILT_NUMB; fil ++) { if (s->filters & 1<h; j++) { for (i = 0; i < link->w; i++) { const int yuv = AV_RN16(in->data[0] + w + i * 2); + + masky |= yuv; histy[yuv]++; dify += abs(yuv - AV_RN16(prev->data[0] + pw + i * 2)); } @@ -826,6 +844,9 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in) for (i = 0; i < s->chromaw; i++) { const int yuvu = AV_RN16(in->data[1] + cw + i * 2); const int yuvv = AV_RN16(in->data[2] + cw + i * 2); + + masku |= yuvu; + maskv |= yuvv; histu[yuvu]++; difu += abs(yuvu - AV_RN16(prev->data[1] + cpw + i * 2)); histv[yuvv]++; @@ -942,6 +963,10 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in) SET_META("UDIF", "%g", 1.0 * difu / s->cfs); SET_META("VDIF", "%g", 1.0 * difv / s->cfs); + SET_META("YBITDEPTH", "%d", compute_bit_depth(masky)); + SET_META("UBITDEPTH", "%d", compute_bit_depth(masku)); + SET_META("VBITDEPTH", "%d", compute_bit_depth(maskv)); + for (fil = 0; fil < FILT_NUMB; fil ++) { if (s->filters & 1<