FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/opt.h"
24 #include "libavutil/pixdesc.h"
25 #include "internal.h"
26 
27 enum FilterMode {
33 };
34 
35 typedef struct {
36  const AVClass *class;
37  int chromah; // height of chroma plane
38  int chromaw; // width of chroma plane
39  int hsub; // horizontal subsampling
40  int vsub; // vertical subsampling
41  int fs; // pixel count per frame
42  int cfs; // pixel count per frame of chroma planes
43  int outfilter; // FilterMode
44  int filters;
46  uint8_t rgba_color[4];
47  int yuv_color[3];
48  int nb_jobs;
49  int *jobs_rets;
50 
54 
55 typedef struct ThreadData {
56  const AVFrame *in;
57  AVFrame *out;
58 } ThreadData;
59 
60 typedef struct ThreadDataHueSatMetrics {
61  const AVFrame *src;
64 
65 #define OFFSET(x) offsetof(SignalstatsContext, x)
66 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
67 
68 static const AVOption signalstats_options[] = {
69  {"stat", "set statistics filters", OFFSET(filters), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "filters"},
70  {"tout", "analyze pixels for temporal outliers", 0, AV_OPT_TYPE_CONST, {.i64=1<<FILTER_TOUT}, 0, 0, FLAGS, "filters"},
71  {"vrep", "analyze video lines for vertical line repetition", 0, AV_OPT_TYPE_CONST, {.i64=1<<FILTER_VREP}, 0, 0, FLAGS, "filters"},
72  {"brng", "analyze for pixels outside of broadcast range", 0, AV_OPT_TYPE_CONST, {.i64=1<<FILTER_BRNG}, 0, 0, FLAGS, "filters"},
73  {"out", "set video filter", OFFSET(outfilter), AV_OPT_TYPE_INT, {.i64=FILTER_NONE}, -1, FILT_NUMB-1, FLAGS, "out"},
74  {"tout", "highlight pixels that depict temporal outliers", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_TOUT}, 0, 0, FLAGS, "out"},
75  {"vrep", "highlight video lines that depict vertical line repetition", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_VREP}, 0, 0, FLAGS, "out"},
76  {"brng", "highlight pixels that are outside of broadcast range", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_BRNG}, 0, 0, FLAGS, "out"},
77  {"c", "set highlight color", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="yellow"}, .flags=FLAGS},
78  {"color", "set highlight color", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="yellow"}, .flags=FLAGS},
79  {NULL}
80 };
81 
82 AVFILTER_DEFINE_CLASS(signalstats);
83 
84 static av_cold int init(AVFilterContext *ctx)
85 {
86  uint8_t r, g, b;
87  SignalstatsContext *s = ctx->priv;
88 
89  if (s->outfilter != FILTER_NONE)
90  s->filters |= 1 << s->outfilter;
91 
92  r = s->rgba_color[0];
93  g = s->rgba_color[1];
94  b = s->rgba_color[2];
95  s->yuv_color[0] = (( 66*r + 129*g + 25*b + (1<<7)) >> 8) + 16;
96  s->yuv_color[1] = ((-38*r + -74*g + 112*b + (1<<7)) >> 8) + 128;
97  s->yuv_color[2] = ((112*r + -94*g + -18*b + (1<<7)) >> 8) + 128;
98  return 0;
99 }
100 
101 static av_cold void uninit(AVFilterContext *ctx)
102 {
103  SignalstatsContext *s = ctx->priv;
107  av_freep(&s->jobs_rets);
108 }
109 
111 {
112  // TODO: add more
113  static const enum AVPixelFormat pix_fmts[] = {
119  };
120 
121  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
122  if (!fmts_list)
123  return AVERROR(ENOMEM);
124  return ff_set_common_formats(ctx, fmts_list);
125 }
126 
127 static AVFrame *alloc_frame(enum AVPixelFormat pixfmt, int w, int h)
128 {
130  if (!frame)
131  return NULL;
132 
133  frame->format = pixfmt;
134  frame->width = w;
135  frame->height = h;
136 
137  if (av_frame_get_buffer(frame, 32) < 0) {
138  av_frame_free(&frame);
139  return NULL;
140  }
141 
142  return frame;
143 }
144 
145 static int config_props(AVFilterLink *outlink)
146 {
147  AVFilterContext *ctx = outlink->src;
148  SignalstatsContext *s = ctx->priv;
149  AVFilterLink *inlink = outlink->src->inputs[0];
150  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
151  s->hsub = desc->log2_chroma_w;
152  s->vsub = desc->log2_chroma_h;
153 
154  outlink->w = inlink->w;
155  outlink->h = inlink->h;
156 
157  s->chromaw = FF_CEIL_RSHIFT(inlink->w, s->hsub);
158  s->chromah = FF_CEIL_RSHIFT(inlink->h, s->vsub);
159 
160  s->fs = inlink->w * inlink->h;
161  s->cfs = s->chromaw * s->chromah;
162 
163  s->nb_jobs = FFMAX(1, FFMIN(inlink->h, ctx->graph->nb_threads));
164  s->jobs_rets = av_malloc_array(s->nb_jobs, sizeof(*s->jobs_rets));
165  if (!s->jobs_rets)
166  return AVERROR(ENOMEM);
167 
168  s->frame_sat = alloc_frame(AV_PIX_FMT_GRAY8, inlink->w, inlink->h);
169  s->frame_hue = alloc_frame(AV_PIX_FMT_GRAY16, inlink->w, inlink->h);
170  if (!s->frame_sat || !s->frame_hue)
171  return AVERROR(ENOMEM);
172 
173  return 0;
174 }
175 
176 static void burn_frame(const SignalstatsContext *s, AVFrame *f, int x, int y)
177 {
178  const int chromax = x >> s->hsub;
179  const int chromay = y >> s->vsub;
180  f->data[0][y * f->linesize[0] + x] = s->yuv_color[0];
181  f->data[1][chromay * f->linesize[1] + chromax] = s->yuv_color[1];
182  f->data[2][chromay * f->linesize[2] + chromax] = s->yuv_color[2];
183 }
184 
185 static int filter_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
186 {
187  ThreadData *td = arg;
188  const SignalstatsContext *s = ctx->priv;
189  const AVFrame *in = td->in;
190  AVFrame *out = td->out;
191  const int w = in->width;
192  const int h = in->height;
193  const int slice_start = (h * jobnr ) / nb_jobs;
194  const int slice_end = (h * (jobnr+1)) / nb_jobs;
195  int x, y, score = 0;
196 
197  for (y = slice_start; y < slice_end; y++) {
198  const int yc = y >> s->vsub;
199  const uint8_t *pluma = &in->data[0][y * in->linesize[0]];
200  const uint8_t *pchromau = &in->data[1][yc * in->linesize[1]];
201  const uint8_t *pchromav = &in->data[2][yc * in->linesize[2]];
202 
203  for (x = 0; x < w; x++) {
204  const int xc = x >> s->hsub;
205  const int luma = pluma[x];
206  const int chromau = pchromau[xc];
207  const int chromav = pchromav[xc];
208  const int filt = luma < 16 || luma > 235 ||
209  chromau < 16 || chromau > 240 ||
210  chromav < 16 || chromav > 240;
211  score += filt;
212  if (out && filt)
213  burn_frame(s, out, x, y);
214  }
215  }
216  return score;
217 }
218 
220 {
221  return ((abs(x - y) + abs (z - y)) / 2) - abs(z - x) > 4; // make 4 configurable?
222 }
223 
224 static int filter_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
225 {
226  ThreadData *td = arg;
227  const SignalstatsContext *s = ctx->priv;
228  const AVFrame *in = td->in;
229  AVFrame *out = td->out;
230  const int w = in->width;
231  const int h = in->height;
232  const int slice_start = (h * jobnr ) / nb_jobs;
233  const int slice_end = (h * (jobnr+1)) / nb_jobs;
234  const uint8_t *p = in->data[0];
235  int lw = in->linesize[0];
236  int x, y, score = 0, filt;
237 
238  for (y = slice_start; y < slice_end; y++) {
239 
240  if (y - 1 < 0 || y + 1 >= h)
241  continue;
242 
243  // detect two pixels above and below (to eliminate interlace artefacts)
244  // should check that video format is infact interlaced.
245 
246 #define FILTER(i, j) \
247  filter_tout_outlier(p[(y-j) * lw + x + i], \
248  p[ y * lw + x + i], \
249  p[(y+j) * lw + x + i])
250 
251 #define FILTER3(j) (FILTER(-1, j) && FILTER(0, j) && FILTER(1, j))
252 
253  if (y - 2 >= 0 && y + 2 < h) {
254  for (x = 1; x < w - 1; x++) {
255  filt = FILTER3(2) && FILTER3(1);
256  score += filt;
257  if (filt && out)
258  burn_frame(s, out, x, y);
259  }
260  } else {
261  for (x = 1; x < w - 1; x++) {
262  filt = FILTER3(1);
263  score += filt;
264  if (filt && out)
265  burn_frame(s, out, x, y);
266  }
267  }
268  }
269  return score;
270 }
271 
272 #define VREP_START 4
273 
274 static int filter_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
275 {
276  ThreadData *td = arg;
277  const SignalstatsContext *s = ctx->priv;
278  const AVFrame *in = td->in;
279  AVFrame *out = td->out;
280  const int w = in->width;
281  const int h = in->height;
282  const int slice_start = (h * jobnr ) / nb_jobs;
283  const int slice_end = (h * (jobnr+1)) / nb_jobs;
284  const uint8_t *p = in->data[0];
285  const int lw = in->linesize[0];
286  int x, y, score = 0;
287 
288  for (y = slice_start; y < slice_end; y++) {
289  const int y2lw = (y - VREP_START) * lw;
290  const int ylw = y * lw;
291  int filt, totdiff = 0;
292 
293  if (y < VREP_START)
294  continue;
295 
296  for (x = 0; x < w; x++)
297  totdiff += abs(p[y2lw + x] - p[ylw + x]);
298  filt = totdiff < w;
299 
300  score += filt;
301  if (filt && out)
302  for (x = 0; x < w; x++)
303  burn_frame(s, out, x, y);
304  }
305  return score * w;
306 }
307 
308 static const struct {
309  const char *name;
310  int (*process)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
311 } filters_def[] = {
312  {"TOUT", filter_tout},
313  {"VREP", filter_vrep},
314  {"BRNG", filter_brng},
315  {NULL}
316 };
317 
318 #define DEPTH 256
319 
320 static int compute_sat_hue_metrics(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
321 {
322  int i, j;
324  const SignalstatsContext *s = ctx->priv;
325  const AVFrame *src = td->src;
326  AVFrame *dst_sat = td->dst_sat;
327  AVFrame *dst_hue = td->dst_hue;
328 
329  const int slice_start = (s->chromah * jobnr ) / nb_jobs;
330  const int slice_end = (s->chromah * (jobnr+1)) / nb_jobs;
331 
332  const int lsz_u = src->linesize[1];
333  const int lsz_v = src->linesize[2];
334  const uint8_t *p_u = src->data[1] + slice_start * lsz_u;
335  const uint8_t *p_v = src->data[2] + slice_start * lsz_v;
336 
337  const int lsz_sat = dst_sat->linesize[0];
338  const int lsz_hue = dst_hue->linesize[0];
339  uint8_t *p_sat = dst_sat->data[0] + slice_start * lsz_sat;
340  uint8_t *p_hue = dst_hue->data[0] + slice_start * lsz_hue;
341 
342  for (j = slice_start; j < slice_end; j++) {
343  for (i = 0; i < s->chromaw; i++) {
344  const int yuvu = p_u[i];
345  const int yuvv = p_v[i];
346  p_sat[i] = hypot(yuvu - 128, yuvv - 128); // int or round?
347  ((int16_t*)p_hue)[i] = floor((180 / M_PI) * atan2f(yuvu-128, yuvv-128) + 180);
348  }
349  p_u += lsz_u;
350  p_v += lsz_v;
351  p_sat += lsz_sat;
352  p_hue += lsz_hue;
353  }
354 
355  return 0;
356 }
357 
358 static int filter_frame(AVFilterLink *link, AVFrame *in)
359 {
360  AVFilterContext *ctx = link->dst;
361  SignalstatsContext *s = ctx->priv;
362  AVFilterLink *outlink = ctx->outputs[0];
363  AVFrame *out = in;
364  int i, j;
365  int w = 0, cw = 0, // in
366  pw = 0, cpw = 0; // prev
367  int fil;
368  char metabuf[128];
369  unsigned int histy[DEPTH] = {0},
370  histu[DEPTH] = {0},
371  histv[DEPTH] = {0},
372  histhue[360] = {0},
373  histsat[DEPTH] = {0}; // limited to 8 bit data.
374  int miny = -1, minu = -1, minv = -1;
375  int maxy = -1, maxu = -1, maxv = -1;
376  int lowy = -1, lowu = -1, lowv = -1;
377  int highy = -1, highu = -1, highv = -1;
378  int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
379  int lowp, highp, clowp, chighp;
380  int accy, accu, accv;
381  int accsat, acchue = 0;
382  int medhue, maxhue;
383  int toty = 0, totu = 0, totv = 0, totsat=0;
384  int tothue = 0;
385  int dify = 0, difu = 0, difv = 0;
386 
387  int filtot[FILT_NUMB] = {0};
388  AVFrame *prev;
389 
390  AVFrame *sat = s->frame_sat;
391  AVFrame *hue = s->frame_hue;
392  const uint8_t *p_sat = sat->data[0];
393  const uint8_t *p_hue = hue->data[0];
394  const int lsz_sat = sat->linesize[0];
395  const int lsz_hue = hue->linesize[0];
396  ThreadDataHueSatMetrics td_huesat = {
397  .src = in,
398  .dst_sat = sat,
399  .dst_hue = hue,
400  };
401 
402  if (!s->frame_prev)
403  s->frame_prev = av_frame_clone(in);
404 
405  prev = s->frame_prev;
406 
407  if (s->outfilter != FILTER_NONE) {
408  out = av_frame_clone(in);
410  }
411 
412  ctx->internal->execute(ctx, compute_sat_hue_metrics, &td_huesat,
413  NULL, FFMIN(s->chromah, ctx->graph->nb_threads));
414 
415  // Calculate luma histogram and difference with previous frame or field.
416  for (j = 0; j < link->h; j++) {
417  for (i = 0; i < link->w; i++) {
418  const int yuv = in->data[0][w + i];
419  histy[yuv]++;
420  dify += abs(yuv - prev->data[0][pw + i]);
421  }
422  w += in->linesize[0];
423  pw += prev->linesize[0];
424  }
425 
426  // Calculate chroma histogram and difference with previous frame or field.
427  for (j = 0; j < s->chromah; j++) {
428  for (i = 0; i < s->chromaw; i++) {
429  const int yuvu = in->data[1][cw+i];
430  const int yuvv = in->data[2][cw+i];
431  histu[yuvu]++;
432  difu += abs(yuvu - prev->data[1][cpw+i]);
433  histv[yuvv]++;
434  difv += abs(yuvv - prev->data[2][cpw+i]);
435 
436  histsat[p_sat[i]]++;
437  histhue[((int16_t*)p_hue)[i]]++;
438  }
439  cw += in->linesize[1];
440  cpw += prev->linesize[1];
441  p_sat += lsz_sat;
442  p_hue += lsz_hue;
443  }
444 
445  for (fil = 0; fil < FILT_NUMB; fil ++) {
446  if (s->filters & 1<<fil) {
447  ThreadData td = {
448  .in = in,
449  .out = out != in && s->outfilter == fil ? out : NULL,
450  };
451  memset(s->jobs_rets, 0, s->nb_jobs * sizeof(*s->jobs_rets));
452  ctx->internal->execute(ctx, filters_def[fil].process,
453  &td, s->jobs_rets, s->nb_jobs);
454  for (i = 0; i < s->nb_jobs; i++)
455  filtot[fil] += s->jobs_rets[i];
456  }
457  }
458 
459  // find low / high based on histogram percentile
460  // these only need to be calculated once.
461 
462  lowp = lrint(s->fs * 10 / 100.);
463  highp = lrint(s->fs * 90 / 100.);
464  clowp = lrint(s->cfs * 10 / 100.);
465  chighp = lrint(s->cfs * 90 / 100.);
466 
467  accy = accu = accv = accsat = 0;
468  for (fil = 0; fil < DEPTH; fil++) {
469  if (miny < 0 && histy[fil]) miny = fil;
470  if (minu < 0 && histu[fil]) minu = fil;
471  if (minv < 0 && histv[fil]) minv = fil;
472  if (minsat < 0 && histsat[fil]) minsat = fil;
473 
474  if (histy[fil]) maxy = fil;
475  if (histu[fil]) maxu = fil;
476  if (histv[fil]) maxv = fil;
477  if (histsat[fil]) maxsat = fil;
478 
479  toty += histy[fil] * fil;
480  totu += histu[fil] * fil;
481  totv += histv[fil] * fil;
482  totsat += histsat[fil] * fil;
483 
484  accy += histy[fil];
485  accu += histu[fil];
486  accv += histv[fil];
487  accsat += histsat[fil];
488 
489  if (lowy == -1 && accy >= lowp) lowy = fil;
490  if (lowu == -1 && accu >= clowp) lowu = fil;
491  if (lowv == -1 && accv >= clowp) lowv = fil;
492  if (lowsat == -1 && accsat >= clowp) lowsat = fil;
493 
494  if (highy == -1 && accy >= highp) highy = fil;
495  if (highu == -1 && accu >= chighp) highu = fil;
496  if (highv == -1 && accv >= chighp) highv = fil;
497  if (highsat == -1 && accsat >= chighp) highsat = fil;
498  }
499 
500  maxhue = histhue[0];
501  medhue = -1;
502  for (fil = 0; fil < 360; fil++) {
503  tothue += histhue[fil] * fil;
504  acchue += histhue[fil];
505 
506  if (medhue == -1 && acchue > s->cfs / 2)
507  medhue = fil;
508  if (histhue[fil] > maxhue) {
509  maxhue = histhue[fil];
510  }
511  }
512 
514  s->frame_prev = av_frame_clone(in);
515 
516 #define SET_META(key, fmt, val) do { \
517  snprintf(metabuf, sizeof(metabuf), fmt, val); \
518  av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \
519 } while (0)
520 
521  SET_META("YMIN", "%d", miny);
522  SET_META("YLOW", "%d", lowy);
523  SET_META("YAVG", "%g", 1.0 * toty / s->fs);
524  SET_META("YHIGH", "%d", highy);
525  SET_META("YMAX", "%d", maxy);
526 
527  SET_META("UMIN", "%d", minu);
528  SET_META("ULOW", "%d", lowu);
529  SET_META("UAVG", "%g", 1.0 * totu / s->cfs);
530  SET_META("UHIGH", "%d", highu);
531  SET_META("UMAX", "%d", maxu);
532 
533  SET_META("VMIN", "%d", minv);
534  SET_META("VLOW", "%d", lowv);
535  SET_META("VAVG", "%g", 1.0 * totv / s->cfs);
536  SET_META("VHIGH", "%d", highv);
537  SET_META("VMAX", "%d", maxv);
538 
539  SET_META("SATMIN", "%d", minsat);
540  SET_META("SATLOW", "%d", lowsat);
541  SET_META("SATAVG", "%g", 1.0 * totsat / s->cfs);
542  SET_META("SATHIGH", "%d", highsat);
543  SET_META("SATMAX", "%d", maxsat);
544 
545  SET_META("HUEMED", "%d", medhue);
546  SET_META("HUEAVG", "%g", 1.0 * tothue / s->cfs);
547 
548  SET_META("YDIF", "%g", 1.0 * dify / s->fs);
549  SET_META("UDIF", "%g", 1.0 * difu / s->cfs);
550  SET_META("VDIF", "%g", 1.0 * difv / s->cfs);
551 
552  for (fil = 0; fil < FILT_NUMB; fil ++) {
553  if (s->filters & 1<<fil) {
554  char metaname[128];
555  snprintf(metabuf, sizeof(metabuf), "%g", 1.0 * filtot[fil] / s->fs);
556  snprintf(metaname, sizeof(metaname), "lavfi.signalstats.%s", filters_def[fil].name);
557  av_dict_set(&out->metadata, metaname, metabuf, 0);
558  }
559  }
560 
561  if (in != out)
562  av_frame_free(&in);
563  return ff_filter_frame(outlink, out);
564 }
565 
566 static const AVFilterPad signalstats_inputs[] = {
567  {
568  .name = "default",
569  .type = AVMEDIA_TYPE_VIDEO,
570  .filter_frame = filter_frame,
571  },
572  { NULL }
573 };
574 
576  {
577  .name = "default",
578  .config_props = config_props,
579  .type = AVMEDIA_TYPE_VIDEO,
580  },
581  { NULL }
582 };
583 
585  .name = "signalstats",
586  .description = "Generate statistics from video analysis.",
587  .init = init,
588  .uninit = uninit,
589  .query_formats = query_formats,
590  .priv_size = sizeof(SignalstatsContext),
591  .inputs = signalstats_inputs,
592  .outputs = signalstats_outputs,
593  .priv_class = &signalstats_class,
595 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
AVFrame * out
Definition: vf_curves.c:73
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
const char * g
Definition: vf_curves.c:108
static int filter_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const char * b
Definition: vf_curves.c:109
const char * name
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
static const AVFilterPad signalstats_outputs[]
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:656
#define OFFSET(x)
const char * name
Pad name.
Definition: internal.h:67
static int filter_frame(AVFilterLink *link, AVFrame *in)
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
AVFrame * in
Definition: vf_curves.c:73
uint8_t
#define DEPTH
#define av_cold
Definition: attributes.h:74
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
AVOptions.
uint8_t rgba_color[4]
static AVFrame * frame
const AVFrame * in
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:102
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:1203
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:76
#define atan2f(y, x)
Definition: libm.h:43
AVDictionary * metadata
metadata.
Definition: frame.h:543
static int compute_sat_hue_metrics(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
Definition: internal.h:61
int width
width and height of the video frame
Definition: frame.h:220
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:542
#define td
Definition: regdef.h:70
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define VREP_START
const char * r
Definition: vf_curves.c:107
static void burn_frame(const SignalstatsContext *s, AVFrame *f, int x, int y)
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:442
const char * arg
Definition: jacosubdec.c:66
AVFilter ff_vf_signalstats
#define FFMAX(a, b)
Definition: common.h:64
static int filter_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:348
#define FFMIN(a, b)
Definition: common.h:66
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:75
int(* process)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
#define FILTER3(j)
#define SET_META(key, fmt, val)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:449
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
FilterMode
Definition: vp9.h:64
AVS_Value src
Definition: avisynth_c.h:482
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static const AVFilterPad signalstats_inputs[]
#define FLAGS
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:69
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
static av_always_inline av_const long int lrint(double x)
Definition: libm.h:148
const char * name
Filter name.
Definition: avfilter.h:474
#define snprintf
Definition: snprintf.h:34
static AVFrame * alloc_frame(enum AVPixelFormat pixfmt, int w, int h)
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static int filter_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:265
static int filter_tout_outlier(uint8_t x, uint8_t y, uint8_t z)
static const int8_t filt[NUMTAPS]
Definition: af_earwax.c:39
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:505
static const struct @140 filters_def[]
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:679
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
static int config_props(AVFilterLink *outlink)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:77
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
avfilter_execute_func * execute
Definition: internal.h:162
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2073
static const struct PPFilter filters[]
Definition: postprocess.c:136
A list of supported formats for one end of a filter link.
Definition: formats.h:64
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:290
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
An instance of a filter.
Definition: avfilter.h:633
static int query_formats(AVFilterContext *ctx)
int height
Definition: frame.h:220
AVFILTER_DEFINE_CLASS(signalstats)
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
#define M_PI
Definition: mathematics.h:46
#define av_malloc_array(a, b)
static av_cold int init(AVFilterContext *ctx)
static const AVOption signalstats_options[]
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
const char * name
Definition: opengl_enc.c:103