FFmpeg  4.4.8
vf_signalstats.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Mark Heath mjpeg0 @ silicontrip dot org
3  * Copyright (c) 2014 Clément Bœsch
4  * Copyright (c) 2014 Dave Rice @dericed
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "internal.h"
27 #include "filters.h"
28 
29 enum FilterMode {
34  FILT_NUMB
35 };
36 
37 typedef struct SignalstatsContext {
38  const AVClass *class;
39  int chromah; // height of chroma plane
40  int chromaw; // width of chroma plane
41  int hsub; // horizontal subsampling
42  int vsub; // vertical subsampling
43  int depth; // pixel depth
44  int fs; // pixel count per frame
45  int cfs; // pixel count per frame of chroma planes
46  int outfilter; // FilterMode
47  int filters;
50  int yuv_color[3];
51  int nb_jobs;
52  int *jobs_rets;
53 
54  int maxsize; // history stats array size
55  int *histy, *histu, *histv, *histsat;
56 
60 
61 typedef struct ThreadData {
62  const AVFrame *in;
63  AVFrame *out;
64 } ThreadData;
65 
66 typedef struct ThreadDataHueSatMetrics {
67  const AVFrame *src;
70 
71 #define OFFSET(x) offsetof(SignalstatsContext, x)
72 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
73 
74 static const AVOption signalstats_options[] = {
75  {"stat", "set statistics filters", OFFSET(filters), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "filters"},
76  {"tout", "analyze pixels for temporal outliers", 0, AV_OPT_TYPE_CONST, {.i64=1<<FILTER_TOUT}, 0, 0, FLAGS, "filters"},
77  {"vrep", "analyze video lines for vertical line repetition", 0, AV_OPT_TYPE_CONST, {.i64=1<<FILTER_VREP}, 0, 0, FLAGS, "filters"},
78  {"brng", "analyze for pixels outside of broadcast range", 0, AV_OPT_TYPE_CONST, {.i64=1<<FILTER_BRNG}, 0, 0, FLAGS, "filters"},
79  {"out", "set video filter", OFFSET(outfilter), AV_OPT_TYPE_INT, {.i64=FILTER_NONE}, -1, FILT_NUMB-1, FLAGS, "out"},
80  {"tout", "highlight pixels that depict temporal outliers", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_TOUT}, 0, 0, FLAGS, "out"},
81  {"vrep", "highlight video lines that depict vertical line repetition", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_VREP}, 0, 0, FLAGS, "out"},
82  {"brng", "highlight pixels that are outside of broadcast range", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_BRNG}, 0, 0, FLAGS, "out"},
83  {"c", "set highlight color", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="yellow"}, .flags=FLAGS},
84  {"color", "set highlight color", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="yellow"}, .flags=FLAGS},
85  {NULL}
86 };
87 
88 AVFILTER_DEFINE_CLASS(signalstats);
89 
91 {
92  uint8_t r, g, b;
93  SignalstatsContext *s = ctx->priv;
94 
95  if (s->outfilter != FILTER_NONE)
96  s->filters |= 1 << s->outfilter;
97 
98  r = s->rgba_color[0];
99  g = s->rgba_color[1];
100  b = s->rgba_color[2];
101  s->yuv_color[0] = (( 66*r + 129*g + 25*b + (1<<7)) >> 8) + 16;
102  s->yuv_color[1] = ((-38*r + -74*g + 112*b + (1<<7)) >> 8) + 128;
103  s->yuv_color[2] = ((112*r + -94*g + -18*b + (1<<7)) >> 8) + 128;
104  return 0;
105 }
106 
108 {
109  SignalstatsContext *s = ctx->priv;
110  av_frame_free(&s->frame_prev);
111  av_frame_free(&s->frame_sat);
112  av_frame_free(&s->frame_hue);
113  av_freep(&s->jobs_rets);
114  av_freep(&s->histy);
115  av_freep(&s->histu);
116  av_freep(&s->histv);
117  av_freep(&s->histsat);
118 }
119 
121 {
122  // TODO: add more
123  static const enum AVPixelFormat pix_fmts[] = {
136  };
137 
139  if (!fmts_list)
140  return AVERROR(ENOMEM);
141  return ff_set_common_formats(ctx, fmts_list);
142 }
143 
144 static AVFrame *alloc_frame(enum AVPixelFormat pixfmt, int w, int h)
145 {
147  if (!frame)
148  return NULL;
149 
150  frame->format = pixfmt;
151  frame->width = w;
152  frame->height = h;
153 
154  if (av_frame_get_buffer(frame, 0) < 0) {
156  return NULL;
157  }
158 
159  return frame;
160 }
161 
162 static int config_output(AVFilterLink *outlink)
163 {
164  AVFilterContext *ctx = outlink->src;
165  SignalstatsContext *s = ctx->priv;
166  AVFilterLink *inlink = outlink->src->inputs[0];
168  s->hsub = desc->log2_chroma_w;
169  s->vsub = desc->log2_chroma_h;
170  s->depth = desc->comp[0].depth;
171  s->maxsize = 1 << s->depth;
172  s->histy = av_malloc_array(s->maxsize, sizeof(*s->histy));
173  s->histu = av_malloc_array(s->maxsize, sizeof(*s->histu));
174  s->histv = av_malloc_array(s->maxsize, sizeof(*s->histv));
175  s->histsat = av_malloc_array(s->maxsize, sizeof(*s->histsat));
176 
177  if (!s->histy || !s->histu || !s->histv || !s->histsat)
178  return AVERROR(ENOMEM);
179 
180  outlink->w = inlink->w;
181  outlink->h = inlink->h;
182 
183  s->chromaw = AV_CEIL_RSHIFT(inlink->w, s->hsub);
184  s->chromah = AV_CEIL_RSHIFT(inlink->h, s->vsub);
185 
186  s->fs = inlink->w * inlink->h;
187  s->cfs = s->chromaw * s->chromah;
188 
189  s->nb_jobs = FFMAX(1, FFMIN(inlink->h, ff_filter_get_nb_threads(ctx)));
190  s->jobs_rets = av_malloc_array(s->nb_jobs, sizeof(*s->jobs_rets));
191  if (!s->jobs_rets)
192  return AVERROR(ENOMEM);
193 
194  s->frame_sat = alloc_frame(s->depth > 8 ? AV_PIX_FMT_GRAY16 : AV_PIX_FMT_GRAY8, inlink->w, inlink->h);
195  s->frame_hue = alloc_frame(AV_PIX_FMT_GRAY16, inlink->w, inlink->h);
196  if (!s->frame_sat || !s->frame_hue)
197  return AVERROR(ENOMEM);
198 
199  return 0;
200 }
201 
202 static void burn_frame8(const SignalstatsContext *s, AVFrame *f, int x, int y)
203 {
204  const int chromax = x >> s->hsub;
205  const int chromay = y >> s->vsub;
206  f->data[0][y * f->linesize[0] + x] = s->yuv_color[0];
207  f->data[1][chromay * f->linesize[1] + chromax] = s->yuv_color[1];
208  f->data[2][chromay * f->linesize[2] + chromax] = s->yuv_color[2];
209 }
210 
211 static void burn_frame16(const SignalstatsContext *s, AVFrame *f, int x, int y)
212 {
213  const int chromax = x >> s->hsub;
214  const int chromay = y >> s->vsub;
215  const int mult = 1 << (s->depth - 8);
216  AV_WN16(f->data[0] + y * f->linesize[0] + x * 2, s->yuv_color[0] * mult);
217  AV_WN16(f->data[1] + chromay * f->linesize[1] + chromax * 2, s->yuv_color[1] * mult);
218  AV_WN16(f->data[2] + chromay * f->linesize[2] + chromax * 2, s->yuv_color[2] * mult);
219 }
220 
221 static int filter8_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
222 {
223  ThreadData *td = arg;
224  const SignalstatsContext *s = ctx->priv;
225  const AVFrame *in = td->in;
226  AVFrame *out = td->out;
227  const int w = in->width;
228  const int h = in->height;
229  const int slice_start = ff_slice_pos(h, jobnr, nb_jobs);
230  const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs);
231  int x, y, score = 0;
232 
233  for (y = slice_start; y < slice_end; y++) {
234  const int yc = y >> s->vsub;
235  const uint8_t *pluma = &in->data[0][y * in->linesize[0]];
236  const uint8_t *pchromau = &in->data[1][yc * in->linesize[1]];
237  const uint8_t *pchromav = &in->data[2][yc * in->linesize[2]];
238 
239  for (x = 0; x < w; x++) {
240  const int xc = x >> s->hsub;
241  const int luma = pluma[x];
242  const int chromau = pchromau[xc];
243  const int chromav = pchromav[xc];
244  const int filt = luma < 16 || luma > 235 ||
245  chromau < 16 || chromau > 240 ||
246  chromav < 16 || chromav > 240;
247  score += filt;
248  if (out && filt)
249  burn_frame8(s, out, x, y);
250  }
251  }
252  return score;
253 }
254 
255 static int filter16_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
256 {
257  ThreadData *td = arg;
258  const SignalstatsContext *s = ctx->priv;
259  const AVFrame *in = td->in;
260  AVFrame *out = td->out;
261  const int mult = 1 << (s->depth - 8);
262  const int w = in->width;
263  const int h = in->height;
264  const int slice_start = ff_slice_pos(h, jobnr, nb_jobs);
265  const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs);
266  int x, y, score = 0;
267 
268  for (y = slice_start; y < slice_end; y++) {
269  const int yc = y >> s->vsub;
270  const uint16_t *pluma = (uint16_t *)&in->data[0][y * in->linesize[0]];
271  const uint16_t *pchromau = (uint16_t *)&in->data[1][yc * in->linesize[1]];
272  const uint16_t *pchromav = (uint16_t *)&in->data[2][yc * in->linesize[2]];
273 
274  for (x = 0; x < w; x++) {
275  const int xc = x >> s->hsub;
276  const int luma = pluma[x];
277  const int chromau = pchromau[xc];
278  const int chromav = pchromav[xc];
279  const int filt = luma < 16 * mult || luma > 235 * mult ||
280  chromau < 16 * mult || chromau > 240 * mult ||
281  chromav < 16 * mult || chromav > 240 * mult;
282  score += filt;
283  if (out && filt)
284  burn_frame16(s, out, x, y);
285  }
286  }
287  return score;
288 }
289 
291 {
292  return ((abs(x - y) + abs (z - y)) / 2) - abs(z - x) > 4; // make 4 configurable?
293 }
294 
295 static int filter8_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
296 {
297  ThreadData *td = arg;
298  const SignalstatsContext *s = ctx->priv;
299  const AVFrame *in = td->in;
300  AVFrame *out = td->out;
301  const int w = in->width;
302  const int h = in->height;
303  const int slice_start = ff_slice_pos(h, jobnr, nb_jobs);
304  const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs);
305  const uint8_t *p = in->data[0];
306  int lw = in->linesize[0];
307  int x, y, score = 0, filt;
308 
309  for (y = slice_start; y < slice_end; y++) {
310 
311  if (y - 1 < 0 || y + 1 >= h)
312  continue;
313 
314  // detect two pixels above and below (to eliminate interlace artefacts)
315  // should check that video format is infact interlaced.
316 
317 #define FILTER(i, j) \
318  filter_tout_outlier(p[(y-j) * lw + x + i], \
319  p[ y * lw + x + i], \
320  p[(y+j) * lw + x + i])
321 
322 #define FILTER3(j) (FILTER(-1, j) && FILTER(0, j) && FILTER(1, j))
323 
324  if (y - 2 >= 0 && y + 2 < h) {
325  for (x = 1; x < w - 1; x++) {
326  filt = FILTER3(2) && FILTER3(1);
327  score += filt;
328  if (filt && out)
329  burn_frame8(s, out, x, y);
330  }
331  } else {
332  for (x = 1; x < w - 1; x++) {
333  filt = FILTER3(1);
334  score += filt;
335  if (filt && out)
336  burn_frame8(s, out, x, y);
337  }
338  }
339  }
340  return score;
341 }
342 
343 static int filter16_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
344 {
345  ThreadData *td = arg;
346  const SignalstatsContext *s = ctx->priv;
347  const AVFrame *in = td->in;
348  AVFrame *out = td->out;
349  const int w = in->width;
350  const int h = in->height;
351  const int slice_start = ff_slice_pos(h, jobnr, nb_jobs);
352  const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs);
353  const uint16_t *p = (uint16_t *)in->data[0];
354  int lw = in->linesize[0] / 2;
355  int x, y, score = 0, filt;
356 
357  for (y = slice_start; y < slice_end; y++) {
358 
359  if (y - 1 < 0 || y + 1 >= h)
360  continue;
361 
362  // detect two pixels above and below (to eliminate interlace artefacts)
363  // should check that video format is infact interlaced.
364 
365  if (y - 2 >= 0 && y + 2 < h) {
366  for (x = 1; x < w - 1; x++) {
367  filt = FILTER3(2) && FILTER3(1);
368  score += filt;
369  if (filt && out)
370  burn_frame16(s, out, x, y);
371  }
372  } else {
373  for (x = 1; x < w - 1; x++) {
374  filt = FILTER3(1);
375  score += filt;
376  if (filt && out)
377  burn_frame16(s, out, x, y);
378  }
379  }
380  }
381  return score;
382 }
383 
384 #define VREP_START 4
385 
386 static int filter8_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
387 {
388  ThreadData *td = arg;
389  const SignalstatsContext *s = ctx->priv;
390  const AVFrame *in = td->in;
391  AVFrame *out = td->out;
392  const int w = in->width;
393  const int h = in->height;
394  const int slice_start = ff_slice_pos(h, jobnr, nb_jobs);
395  const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs);
396  const uint8_t *p = in->data[0];
397  const int lw = in->linesize[0];
398  int x, y, score = 0;
399 
400  for (y = slice_start; y < slice_end; y++) {
401  const int y2lw = (y - VREP_START) * lw;
402  const int ylw = y * lw;
403  int filt, totdiff = 0;
404 
405  if (y < VREP_START)
406  continue;
407 
408  for (x = 0; x < w; x++)
409  totdiff += abs(p[y2lw + x] - p[ylw + x]);
410  filt = totdiff < w;
411 
412  score += filt;
413  if (filt && out)
414  for (x = 0; x < w; x++)
415  burn_frame8(s, out, x, y);
416  }
417  return score * w;
418 }
419 
420 static int filter16_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
421 {
422  ThreadData *td = arg;
423  const SignalstatsContext *s = ctx->priv;
424  const AVFrame *in = td->in;
425  AVFrame *out = td->out;
426  const int w = in->width;
427  const int h = in->height;
428  const int slice_start = ff_slice_pos(h, jobnr, nb_jobs);
429  const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs);
430  const uint16_t *p = (uint16_t *)in->data[0];
431  const int lw = in->linesize[0] / 2;
432  int x, y, score = 0;
433 
434  for (y = slice_start; y < slice_end; y++) {
435  const int y2lw = (y - VREP_START) * lw;
436  const int ylw = y * lw;
437  int64_t totdiff = 0;
438  int filt;
439 
440  if (y < VREP_START)
441  continue;
442 
443  for (x = 0; x < w; x++)
444  totdiff += abs(p[y2lw + x] - p[ylw + x]);
445  filt = totdiff < w;
446 
447  score += filt;
448  if (filt && out)
449  for (x = 0; x < w; x++)
450  burn_frame16(s, out, x, y);
451  }
452  return score * w;
453 }
454 
455 static const struct {
456  const char *name;
457  int (*process8)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
458  int (*process16)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
459 } filters_def[] = {
460  {"TOUT", filter8_tout, filter16_tout},
461  {"VREP", filter8_vrep, filter16_vrep},
462  {"BRNG", filter8_brng, filter16_brng},
463  {NULL}
464 };
465 
466 static int compute_sat_hue_metrics8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
467 {
468  int i, j;
470  const SignalstatsContext *s = ctx->priv;
471  const AVFrame *src = td->src;
472  AVFrame *dst_sat = td->dst_sat;
473  AVFrame *dst_hue = td->dst_hue;
474 
475  const int slice_start = ff_slice_pos(s->chromah, jobnr, nb_jobs);
476  const int slice_end = ff_slice_pos(s->chromah, jobnr + 1, nb_jobs);
477 
478  const int lsz_u = src->linesize[1];
479  const int lsz_v = src->linesize[2];
480  const uint8_t *p_u = src->data[1] + slice_start * lsz_u;
481  const uint8_t *p_v = src->data[2] + slice_start * lsz_v;
482 
483  const int lsz_sat = dst_sat->linesize[0];
484  const int lsz_hue = dst_hue->linesize[0];
485  uint8_t *p_sat = dst_sat->data[0] + slice_start * lsz_sat;
486  uint8_t *p_hue = dst_hue->data[0] + slice_start * lsz_hue;
487 
488  for (j = slice_start; j < slice_end; j++) {
489  for (i = 0; i < s->chromaw; i++) {
490  const int yuvu = p_u[i];
491  const int yuvv = p_v[i];
492  p_sat[i] = hypot(yuvu - 128, yuvv - 128); // int or round?
493  ((int16_t*)p_hue)[i] = fmod(floor((180 / M_PI) * atan2f(yuvu-128, yuvv-128) + 180), 360.);
494  }
495  p_u += lsz_u;
496  p_v += lsz_v;
497  p_sat += lsz_sat;
498  p_hue += lsz_hue;
499  }
500 
501  return 0;
502 }
503 
504 static int compute_sat_hue_metrics16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
505 {
506  int i, j;
508  const SignalstatsContext *s = ctx->priv;
509  const AVFrame *src = td->src;
510  AVFrame *dst_sat = td->dst_sat;
511  AVFrame *dst_hue = td->dst_hue;
512  const int mid = 1 << (s->depth - 1);
513 
514  const int slice_start = ff_slice_pos(s->chromah, jobnr, nb_jobs);
515  const int slice_end = ff_slice_pos(s->chromah, jobnr + 1, nb_jobs);
516 
517  const int lsz_u = src->linesize[1] / 2;
518  const int lsz_v = src->linesize[2] / 2;
519  const uint16_t *p_u = (uint16_t*)src->data[1] + slice_start * lsz_u;
520  const uint16_t *p_v = (uint16_t*)src->data[2] + slice_start * lsz_v;
521 
522  const int lsz_sat = dst_sat->linesize[0] / 2;
523  const int lsz_hue = dst_hue->linesize[0] / 2;
524  uint16_t *p_sat = (uint16_t*)dst_sat->data[0] + slice_start * lsz_sat;
525  uint16_t *p_hue = (uint16_t*)dst_hue->data[0] + slice_start * lsz_hue;
526 
527  for (j = slice_start; j < slice_end; j++) {
528  for (i = 0; i < s->chromaw; i++) {
529  const int yuvu = p_u[i];
530  const int yuvv = p_v[i];
531  p_sat[i] = hypot(yuvu - mid, yuvv - mid); // int or round?
532  ((int16_t*)p_hue)[i] = fmod(floor((180 / M_PI) * atan2f(yuvu-mid, yuvv-mid) + 180), 360.);
533  }
534  p_u += lsz_u;
535  p_v += lsz_v;
536  p_sat += lsz_sat;
537  p_hue += lsz_hue;
538  }
539 
540  return 0;
541 }
542 
543 static unsigned compute_bit_depth(uint16_t mask)
544 {
545  return av_popcount(mask);
546 }
547 
549 {
550  AVFilterContext *ctx = link->dst;
551  SignalstatsContext *s = ctx->priv;
552  AVFilterLink *outlink = ctx->outputs[0];
553  AVFrame *out = in;
554  int i, j;
555  int w = 0, cw = 0, // in
556  pw = 0, cpw = 0; // prev
557  int fil;
558  char metabuf[128];
559  unsigned int *histy = s->histy,
560  *histu = s->histu,
561  *histv = s->histv,
562  histhue[360] = {0},
563  *histsat = s->histsat;
564  int miny = -1, minu = -1, minv = -1;
565  int maxy = -1, maxu = -1, maxv = -1;
566  int lowy = -1, lowu = -1, lowv = -1;
567  int highy = -1, highu = -1, highv = -1;
568  int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
569  int lowp, highp, clowp, chighp;
570  int accy, accu, accv;
571  int accsat, acchue = 0;
572  int medhue, maxhue;
573  int toty = 0, totu = 0, totv = 0, totsat=0;
574  int tothue = 0;
575  int dify = 0, difu = 0, difv = 0;
576  uint16_t masky = 0, masku = 0, maskv = 0;
577 
578  int filtot[FILT_NUMB] = {0};
579  AVFrame *prev;
580 
581  AVFrame *sat = s->frame_sat;
582  AVFrame *hue = s->frame_hue;
583  const uint8_t *p_sat = sat->data[0];
584  const uint8_t *p_hue = hue->data[0];
585  const int lsz_sat = sat->linesize[0];
586  const int lsz_hue = hue->linesize[0];
587  ThreadDataHueSatMetrics td_huesat = {
588  .src = in,
589  .dst_sat = sat,
590  .dst_hue = hue,
591  };
592 
593  if (!s->frame_prev)
594  s->frame_prev = av_frame_clone(in);
595 
596  prev = s->frame_prev;
597 
598  if (s->outfilter != FILTER_NONE) {
599  out = av_frame_clone(in);
601  }
602 
603  ctx->internal->execute(ctx, compute_sat_hue_metrics8, &td_huesat,
604  NULL, FFMIN(s->chromah, ff_filter_get_nb_threads(ctx)));
605 
606  // Calculate luma histogram and difference with previous frame or field.
607  memset(s->histy, 0, s->maxsize * sizeof(*s->histy));
608  for (j = 0; j < link->h; j++) {
609  for (i = 0; i < link->w; i++) {
610  const int yuv = in->data[0][w + i];
611 
612  masky |= yuv;
613  histy[yuv]++;
614  dify += abs(yuv - prev->data[0][pw + i]);
615  }
616  w += in->linesize[0];
617  pw += prev->linesize[0];
618  }
619 
620  // Calculate chroma histogram and difference with previous frame or field.
621  memset(s->histu, 0, s->maxsize * sizeof(*s->histu));
622  memset(s->histv, 0, s->maxsize * sizeof(*s->histv));
623  memset(s->histsat, 0, s->maxsize * sizeof(*s->histsat));
624  for (j = 0; j < s->chromah; j++) {
625  for (i = 0; i < s->chromaw; i++) {
626  const int yuvu = in->data[1][cw+i];
627  const int yuvv = in->data[2][cw+i];
628 
629  masku |= yuvu;
630  maskv |= yuvv;
631  histu[yuvu]++;
632  difu += abs(yuvu - prev->data[1][cpw+i]);
633  histv[yuvv]++;
634  difv += abs(yuvv - prev->data[2][cpw+i]);
635 
636  histsat[p_sat[i]]++;
637  histhue[((int16_t*)p_hue)[i]]++;
638  }
639  cw += in->linesize[1];
640  cpw += prev->linesize[1];
641  p_sat += lsz_sat;
642  p_hue += lsz_hue;
643  }
644 
645  for (fil = 0; fil < FILT_NUMB; fil ++) {
646  if (s->filters & 1<<fil) {
647  ThreadData td = {
648  .in = in,
649  .out = out != in && s->outfilter == fil ? out : NULL,
650  };
651  memset(s->jobs_rets, 0, s->nb_jobs * sizeof(*s->jobs_rets));
652  ctx->internal->execute(ctx, filters_def[fil].process8,
653  &td, s->jobs_rets, s->nb_jobs);
654  for (i = 0; i < s->nb_jobs; i++)
655  filtot[fil] += s->jobs_rets[i];
656  }
657  }
658 
659  // find low / high based on histogram percentile
660  // these only need to be calculated once.
661 
662  lowp = lrint(s->fs * 10 / 100.);
663  highp = lrint(s->fs * 90 / 100.);
664  clowp = lrint(s->cfs * 10 / 100.);
665  chighp = lrint(s->cfs * 90 / 100.);
666 
667  accy = accu = accv = accsat = 0;
668  for (fil = 0; fil < s->maxsize; fil++) {
669  if (miny < 0 && histy[fil]) miny = fil;
670  if (minu < 0 && histu[fil]) minu = fil;
671  if (minv < 0 && histv[fil]) minv = fil;
672  if (minsat < 0 && histsat[fil]) minsat = fil;
673 
674  if (histy[fil]) maxy = fil;
675  if (histu[fil]) maxu = fil;
676  if (histv[fil]) maxv = fil;
677  if (histsat[fil]) maxsat = fil;
678 
679  toty += histy[fil] * fil;
680  totu += histu[fil] * fil;
681  totv += histv[fil] * fil;
682  totsat += histsat[fil] * fil;
683 
684  accy += histy[fil];
685  accu += histu[fil];
686  accv += histv[fil];
687  accsat += histsat[fil];
688 
689  if (lowy == -1 && accy >= lowp) lowy = fil;
690  if (lowu == -1 && accu >= clowp) lowu = fil;
691  if (lowv == -1 && accv >= clowp) lowv = fil;
692  if (lowsat == -1 && accsat >= clowp) lowsat = fil;
693 
694  if (highy == -1 && accy >= highp) highy = fil;
695  if (highu == -1 && accu >= chighp) highu = fil;
696  if (highv == -1 && accv >= chighp) highv = fil;
697  if (highsat == -1 && accsat >= chighp) highsat = fil;
698  }
699 
700  maxhue = histhue[0];
701  medhue = -1;
702  for (fil = 0; fil < 360; fil++) {
703  tothue += histhue[fil] * fil;
704  acchue += histhue[fil];
705 
706  if (medhue == -1 && acchue > s->cfs / 2)
707  medhue = fil;
708  if (histhue[fil] > maxhue) {
709  maxhue = histhue[fil];
710  }
711  }
712 
713  av_frame_free(&s->frame_prev);
714  s->frame_prev = av_frame_clone(in);
715 
716 #define SET_META(key, fmt, val) do { \
717  snprintf(metabuf, sizeof(metabuf), fmt, val); \
718  av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \
719 } while (0)
720 
721  SET_META("YMIN", "%d", miny);
722  SET_META("YLOW", "%d", lowy);
723  SET_META("YAVG", "%g", 1.0 * toty / s->fs);
724  SET_META("YHIGH", "%d", highy);
725  SET_META("YMAX", "%d", maxy);
726 
727  SET_META("UMIN", "%d", minu);
728  SET_META("ULOW", "%d", lowu);
729  SET_META("UAVG", "%g", 1.0 * totu / s->cfs);
730  SET_META("UHIGH", "%d", highu);
731  SET_META("UMAX", "%d", maxu);
732 
733  SET_META("VMIN", "%d", minv);
734  SET_META("VLOW", "%d", lowv);
735  SET_META("VAVG", "%g", 1.0 * totv / s->cfs);
736  SET_META("VHIGH", "%d", highv);
737  SET_META("VMAX", "%d", maxv);
738 
739  SET_META("SATMIN", "%d", minsat);
740  SET_META("SATLOW", "%d", lowsat);
741  SET_META("SATAVG", "%g", 1.0 * totsat / s->cfs);
742  SET_META("SATHIGH", "%d", highsat);
743  SET_META("SATMAX", "%d", maxsat);
744 
745  SET_META("HUEMED", "%d", medhue);
746  SET_META("HUEAVG", "%g", 1.0 * tothue / s->cfs);
747 
748  SET_META("YDIF", "%g", 1.0 * dify / s->fs);
749  SET_META("UDIF", "%g", 1.0 * difu / s->cfs);
750  SET_META("VDIF", "%g", 1.0 * difv / s->cfs);
751 
752  SET_META("YBITDEPTH", "%d", compute_bit_depth(masky));
753  SET_META("UBITDEPTH", "%d", compute_bit_depth(masku));
754  SET_META("VBITDEPTH", "%d", compute_bit_depth(maskv));
755 
756  for (fil = 0; fil < FILT_NUMB; fil ++) {
757  if (s->filters & 1<<fil) {
758  char metaname[128];
759  snprintf(metabuf, sizeof(metabuf), "%g", 1.0 * filtot[fil] / s->fs);
760  snprintf(metaname, sizeof(metaname), "lavfi.signalstats.%s", filters_def[fil].name);
761  av_dict_set(&out->metadata, metaname, metabuf, 0);
762  }
763  }
764 
765  if (in != out)
766  av_frame_free(&in);
767  return ff_filter_frame(outlink, out);
768 }
769 
771 {
772  AVFilterContext *ctx = link->dst;
773  SignalstatsContext *s = ctx->priv;
774  AVFilterLink *outlink = ctx->outputs[0];
775  AVFrame *out = in;
776  int i, j;
777  int w = 0, cw = 0, // in
778  pw = 0, cpw = 0; // prev
779  int fil;
780  char metabuf[128];
781  unsigned int *histy = s->histy,
782  *histu = s->histu,
783  *histv = s->histv,
784  histhue[360] = {0},
785  *histsat = s->histsat;
786  int miny = -1, minu = -1, minv = -1;
787  int maxy = -1, maxu = -1, maxv = -1;
788  int lowy = -1, lowu = -1, lowv = -1;
789  int highy = -1, highu = -1, highv = -1;
790  int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
791  int lowp, highp, clowp, chighp;
792  int accy, accu, accv;
793  int accsat, acchue = 0;
794  int medhue, maxhue;
795  int64_t toty = 0, totu = 0, totv = 0, totsat=0;
796  int64_t tothue = 0;
797  int64_t dify = 0, difu = 0, difv = 0;
798  uint16_t masky = 0, masku = 0, maskv = 0;
799 
800  int filtot[FILT_NUMB] = {0};
801  AVFrame *prev;
802 
803  AVFrame *sat = s->frame_sat;
804  AVFrame *hue = s->frame_hue;
805  const uint16_t *p_sat = (uint16_t *)sat->data[0];
806  const uint16_t *p_hue = (uint16_t *)hue->data[0];
807  const int lsz_sat = sat->linesize[0] / 2;
808  const int lsz_hue = hue->linesize[0] / 2;
809  ThreadDataHueSatMetrics td_huesat = {
810  .src = in,
811  .dst_sat = sat,
812  .dst_hue = hue,
813  };
814 
815  if (!s->frame_prev)
816  s->frame_prev = av_frame_clone(in);
817 
818  prev = s->frame_prev;
819 
820  if (s->outfilter != FILTER_NONE) {
821  out = av_frame_clone(in);
823  }
824 
825  ctx->internal->execute(ctx, compute_sat_hue_metrics16, &td_huesat,
826  NULL, FFMIN(s->chromah, ff_filter_get_nb_threads(ctx)));
827 
828  // Calculate luma histogram and difference with previous frame or field.
829  memset(s->histy, 0, s->maxsize * sizeof(*s->histy));
830  for (j = 0; j < link->h; j++) {
831  for (i = 0; i < link->w; i++) {
832  const int yuv = AV_RN16(in->data[0] + w + i * 2);
833 
834  masky |= yuv;
835  histy[yuv]++;
836  dify += abs(yuv - (int)AV_RN16(prev->data[0] + pw + i * 2));
837  }
838  w += in->linesize[0];
839  pw += prev->linesize[0];
840  }
841 
842  // Calculate chroma histogram and difference with previous frame or field.
843  memset(s->histu, 0, s->maxsize * sizeof(*s->histu));
844  memset(s->histv, 0, s->maxsize * sizeof(*s->histv));
845  memset(s->histsat, 0, s->maxsize * sizeof(*s->histsat));
846  for (j = 0; j < s->chromah; j++) {
847  for (i = 0; i < s->chromaw; i++) {
848  const int yuvu = AV_RN16(in->data[1] + cw + i * 2);
849  const int yuvv = AV_RN16(in->data[2] + cw + i * 2);
850 
851  masku |= yuvu;
852  maskv |= yuvv;
853  histu[yuvu]++;
854  difu += abs(yuvu - (int)AV_RN16(prev->data[1] + cpw + i * 2));
855  histv[yuvv]++;
856  difv += abs(yuvv - (int)AV_RN16(prev->data[2] + cpw + i * 2));
857 
858  histsat[p_sat[i]]++;
859  histhue[((int16_t*)p_hue)[i]]++;
860  }
861  cw += in->linesize[1];
862  cpw += prev->linesize[1];
863  p_sat += lsz_sat;
864  p_hue += lsz_hue;
865  }
866 
867  for (fil = 0; fil < FILT_NUMB; fil ++) {
868  if (s->filters & 1<<fil) {
869  ThreadData td = {
870  .in = in,
871  .out = out != in && s->outfilter == fil ? out : NULL,
872  };
873  memset(s->jobs_rets, 0, s->nb_jobs * sizeof(*s->jobs_rets));
874  ctx->internal->execute(ctx, filters_def[fil].process16,
875  &td, s->jobs_rets, s->nb_jobs);
876  for (i = 0; i < s->nb_jobs; i++)
877  filtot[fil] += s->jobs_rets[i];
878  }
879  }
880 
881  // find low / high based on histogram percentile
882  // these only need to be calculated once.
883 
884  lowp = lrint(s->fs * 10 / 100.);
885  highp = lrint(s->fs * 90 / 100.);
886  clowp = lrint(s->cfs * 10 / 100.);
887  chighp = lrint(s->cfs * 90 / 100.);
888 
889  accy = accu = accv = accsat = 0;
890  for (fil = 0; fil < s->maxsize; fil++) {
891  if (miny < 0 && histy[fil]) miny = fil;
892  if (minu < 0 && histu[fil]) minu = fil;
893  if (minv < 0 && histv[fil]) minv = fil;
894  if (minsat < 0 && histsat[fil]) minsat = fil;
895 
896  if (histy[fil]) maxy = fil;
897  if (histu[fil]) maxu = fil;
898  if (histv[fil]) maxv = fil;
899  if (histsat[fil]) maxsat = fil;
900 
901  toty += histy[fil] * fil;
902  totu += histu[fil] * fil;
903  totv += histv[fil] * fil;
904  totsat += histsat[fil] * fil;
905 
906  accy += histy[fil];
907  accu += histu[fil];
908  accv += histv[fil];
909  accsat += histsat[fil];
910 
911  if (lowy == -1 && accy >= lowp) lowy = fil;
912  if (lowu == -1 && accu >= clowp) lowu = fil;
913  if (lowv == -1 && accv >= clowp) lowv = fil;
914  if (lowsat == -1 && accsat >= clowp) lowsat = fil;
915 
916  if (highy == -1 && accy >= highp) highy = fil;
917  if (highu == -1 && accu >= chighp) highu = fil;
918  if (highv == -1 && accv >= chighp) highv = fil;
919  if (highsat == -1 && accsat >= chighp) highsat = fil;
920  }
921 
922  maxhue = histhue[0];
923  medhue = -1;
924  for (fil = 0; fil < 360; fil++) {
925  tothue += histhue[fil] * fil;
926  acchue += histhue[fil];
927 
928  if (medhue == -1 && acchue > s->cfs / 2)
929  medhue = fil;
930  if (histhue[fil] > maxhue) {
931  maxhue = histhue[fil];
932  }
933  }
934 
935  av_frame_free(&s->frame_prev);
936  s->frame_prev = av_frame_clone(in);
937 
938  SET_META("YMIN", "%d", miny);
939  SET_META("YLOW", "%d", lowy);
940  SET_META("YAVG", "%g", 1.0 * toty / s->fs);
941  SET_META("YHIGH", "%d", highy);
942  SET_META("YMAX", "%d", maxy);
943 
944  SET_META("UMIN", "%d", minu);
945  SET_META("ULOW", "%d", lowu);
946  SET_META("UAVG", "%g", 1.0 * totu / s->cfs);
947  SET_META("UHIGH", "%d", highu);
948  SET_META("UMAX", "%d", maxu);
949 
950  SET_META("VMIN", "%d", minv);
951  SET_META("VLOW", "%d", lowv);
952  SET_META("VAVG", "%g", 1.0 * totv / s->cfs);
953  SET_META("VHIGH", "%d", highv);
954  SET_META("VMAX", "%d", maxv);
955 
956  SET_META("SATMIN", "%d", minsat);
957  SET_META("SATLOW", "%d", lowsat);
958  SET_META("SATAVG", "%g", 1.0 * totsat / s->cfs);
959  SET_META("SATHIGH", "%d", highsat);
960  SET_META("SATMAX", "%d", maxsat);
961 
962  SET_META("HUEMED", "%d", medhue);
963  SET_META("HUEAVG", "%g", 1.0 * tothue / s->cfs);
964 
965  SET_META("YDIF", "%g", 1.0 * dify / s->fs);
966  SET_META("UDIF", "%g", 1.0 * difu / s->cfs);
967  SET_META("VDIF", "%g", 1.0 * difv / s->cfs);
968 
969  SET_META("YBITDEPTH", "%d", compute_bit_depth(masky));
970  SET_META("UBITDEPTH", "%d", compute_bit_depth(masku));
971  SET_META("VBITDEPTH", "%d", compute_bit_depth(maskv));
972 
973  for (fil = 0; fil < FILT_NUMB; fil ++) {
974  if (s->filters & 1<<fil) {
975  char metaname[128];
976  snprintf(metabuf, sizeof(metabuf), "%g", 1.0 * filtot[fil] / s->fs);
977  snprintf(metaname, sizeof(metaname), "lavfi.signalstats.%s", filters_def[fil].name);
978  av_dict_set(&out->metadata, metaname, metabuf, 0);
979  }
980  }
981 
982  if (in != out)
983  av_frame_free(&in);
984  return ff_filter_frame(outlink, out);
985 }
986 
987 static int filter_frame(AVFilterLink *link, AVFrame *in)
988 {
989  AVFilterContext *ctx = link->dst;
990  SignalstatsContext *s = ctx->priv;
991 
992  if (s->depth > 8)
993  return filter_frame16(link, in);
994  else
995  return filter_frame8(link, in);
996 }
997 
998 static const AVFilterPad signalstats_inputs[] = {
999  {
1000  .name = "default",
1001  .type = AVMEDIA_TYPE_VIDEO,
1002  .filter_frame = filter_frame,
1003  },
1004  { NULL }
1005 };
1006 
1008  {
1009  .name = "default",
1010  .config_props = config_output,
1011  .type = AVMEDIA_TYPE_VIDEO,
1012  },
1013  { NULL }
1014 };
1015 
1017  .name = "signalstats",
1018  .description = "Generate statistics from video analysis.",
1019  .init = init,
1020  .uninit = uninit,
1021  .query_formats = query_formats,
1022  .priv_size = sizeof(SignalstatsContext),
1025  .priv_class = &signalstats_class,
1027 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:39
#define av_cold
Definition: attributes.h:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
#define f(width, name)
Definition: cbs_vp9.c:255
#define FFMIN(a, b)
Definition: common.h:105
#define av_popcount
Definition: common.h:176
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
#define abs(x)
Definition: cuda_runtime.h:35
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
static AVFrame * frame
int
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
Definition: filters.h:271
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_COLOR
Definition: opt.h:240
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
#define AVERROR(e)
Definition: error.h:43
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:337
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:611
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
for(j=16;j >0;--j)
int i
Definition: input.c:407
#define AV_WN16(p, v)
Definition: intreadwrite.h:372
#define AV_RN16(p)
Definition: intreadwrite.h:360
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:365
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:55
const char * arg
Definition: jacosubdec.c:66
common internal API header
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
static av_const double hypot(double x, double y)
Definition: libm.h:366
#define atan2f(y, x)
Definition: libm.h:45
const char * desc
Definition: libsvtav1.c:79
uint8_t w
Definition: llviddspenc.c:39
static const uint16_t mask[17]
Definition: lzw.c:38
#define M_PI
Definition: mathematics.h:52
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2033
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:405
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:401
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
static const struct PPFilter filters[]
Definition: postprocess.c:134
#define td
Definition: regdef.h:70
#define snprintf
Definition: snprintf.h:34
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
uint8_t rgba_color[4]
Used for passing data between threads.
Definition: dsddec.c:67
const AVFrame * in
AVFrame * out
Definition: af_adeclick.c:502
#define lrint
Definition: tablegen.h:53
#define av_malloc_array(a, b)
#define av_freep(p)
#define src
Definition: vp8dsp.c:255
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
const char * b
Definition: vf_curves.c:119
const char * g
Definition: vf_curves.c:118
const char * r
Definition: vf_curves.c:117
#define SET_META(key, fmt, val)
static const AVFilterPad signalstats_outputs[]
static int filter8_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void burn_frame8(const SignalstatsContext *s, AVFrame *f, int x, int y)
@ FILT_NUMB
@ FILTER_VREP
@ FILTER_NONE
@ FILTER_BRNG
@ FILTER_TOUT
int(* process16)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad signalstats_inputs[]
static int compute_sat_hue_metrics8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterLink *link, AVFrame *in)
static int compute_sat_hue_metrics16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter8_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int query_formats(AVFilterContext *ctx)
static unsigned compute_bit_depth(uint16_t mask)
static int filter16_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FLAGS
static int filter16_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const char * name
static int filter8_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFilter ff_vf_signalstats
static const struct @235 filters_def[]
static AVFrame * alloc_frame(enum AVPixelFormat pixfmt, int w, int h)
AVFILTER_DEFINE_CLASS(signalstats)
static av_cold int init(AVFilterContext *ctx)
#define VREP_START
static av_cold void uninit(AVFilterContext *ctx)
int(* process8)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame8(AVFilterLink *link, AVFrame *in)
#define OFFSET(x)
static int config_output(AVFilterLink *outlink)
static int filter_frame16(AVFilterLink *link, AVFrame *in)
static void burn_frame16(const SignalstatsContext *s, AVFrame *f, int x, int y)
static const AVOption signalstats_options[]
#define FILTER3(j)
static int filter_tout_outlier(uint8_t x, uint8_t y, uint8_t z)
static int filter16_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
FilterMode
Definition: vp9.h:64