avfilter/vf_signalstats: measure video bitdepth

pull/230/head
Paul B Mahol 9 years ago
parent ee56d9bc89
commit 3a81775bde
  1. 12
      doc/filters.texi
  2. 25
      libavfilter/vf_signalstats.c

@ -11946,6 +11946,18 @@ Expressed in range of [0-255].
Display the average of sample value difference between all values of the V 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. plane in the current frame and corresponding values of the previous input frame.
Expressed in range of [0-255]. 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 @end table
The filter accepts the following options: The filter accepts the following options:

@ -541,6 +541,11 @@ static int compute_sat_hue_metrics16(AVFilterContext *ctx, void *arg, int jobnr,
return 0; return 0;
} }
static unsigned compute_bit_depth(uint16_t mask)
{
return av_popcount(mask);
}
static int filter_frame8(AVFilterLink *link, AVFrame *in) static int filter_frame8(AVFilterLink *link, AVFrame *in)
{ {
AVFilterContext *ctx = link->dst; 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 toty = 0, totu = 0, totv = 0, totsat=0;
int tothue = 0; int tothue = 0;
int dify = 0, difu = 0, difv = 0; int dify = 0, difu = 0, difv = 0;
uint16_t masky = 0, masku = 0, maskv = 0;
int filtot[FILT_NUMB] = {0}; int filtot[FILT_NUMB] = {0};
AVFrame *prev; AVFrame *prev;
@ -602,6 +608,8 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in)
for (j = 0; j < link->h; j++) { for (j = 0; j < link->h; j++) {
for (i = 0; i < link->w; i++) { for (i = 0; i < link->w; i++) {
const int yuv = in->data[0][w + i]; const int yuv = in->data[0][w + i];
masky |= yuv;
histy[yuv]++; histy[yuv]++;
dify += abs(yuv - prev->data[0][pw + i]); 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++) { for (i = 0; i < s->chromaw; i++) {
const int yuvu = in->data[1][cw+i]; const int yuvu = in->data[1][cw+i];
const int yuvv = in->data[2][cw+i]; const int yuvv = in->data[2][cw+i];
masku |= yuvu;
maskv |= yuvv;
histu[yuvu]++; histu[yuvu]++;
difu += abs(yuvu - prev->data[1][cpw+i]); difu += abs(yuvu - prev->data[1][cpw+i]);
histv[yuvv]++; 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("UDIF", "%g", 1.0 * difu / s->cfs);
SET_META("VDIF", "%g", 1.0 * difv / 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 ++) { for (fil = 0; fil < FILT_NUMB; fil ++) {
if (s->filters & 1<<fil) { if (s->filters & 1<<fil) {
char metaname[128]; char metaname[128];
@ -777,6 +792,7 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in)
int64_t toty = 0, totu = 0, totv = 0, totsat=0; int64_t toty = 0, totu = 0, totv = 0, totsat=0;
int64_t tothue = 0; int64_t tothue = 0;
int64_t dify = 0, difu = 0, difv = 0; int64_t dify = 0, difu = 0, difv = 0;
uint16_t masky = 0, masku = 0, maskv = 0;
int filtot[FILT_NUMB] = {0}; int filtot[FILT_NUMB] = {0};
AVFrame *prev; AVFrame *prev;
@ -811,6 +827,8 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in)
for (j = 0; j < link->h; j++) { for (j = 0; j < link->h; j++) {
for (i = 0; i < link->w; i++) { for (i = 0; i < link->w; i++) {
const int yuv = AV_RN16(in->data[0] + w + i * 2); const int yuv = AV_RN16(in->data[0] + w + i * 2);
masky |= yuv;
histy[yuv]++; histy[yuv]++;
dify += abs(yuv - AV_RN16(prev->data[0] + pw + i * 2)); 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++) { for (i = 0; i < s->chromaw; i++) {
const int yuvu = AV_RN16(in->data[1] + cw + i * 2); const int yuvu = AV_RN16(in->data[1] + cw + i * 2);
const int yuvv = AV_RN16(in->data[2] + cw + i * 2); const int yuvv = AV_RN16(in->data[2] + cw + i * 2);
masku |= yuvu;
maskv |= yuvv;
histu[yuvu]++; histu[yuvu]++;
difu += abs(yuvu - AV_RN16(prev->data[1] + cpw + i * 2)); difu += abs(yuvu - AV_RN16(prev->data[1] + cpw + i * 2));
histv[yuvv]++; 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("UDIF", "%g", 1.0 * difu / s->cfs);
SET_META("VDIF", "%g", 1.0 * difv / 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 ++) { for (fil = 0; fil < FILT_NUMB; fil ++) {
if (s->filters & 1<<fil) { if (s->filters & 1<<fil) {
char metaname[128]; char metaname[128];

Loading…
Cancel
Save