FFmpeg
vf_histogram.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2019 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/colorspace.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/parseutils.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/intreadwrite.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 typedef struct HistogramContext {
33  const AVClass *class; ///< AVClass context for log and options purpose
35  int envelope;
36  int slide;
37  unsigned histogram[256*256];
39  int width;
40  int x_pos;
41  int mult;
42  int ncomp;
43  int dncomp;
44  uint8_t bg_color[4];
45  uint8_t fg_color[4];
46  uint8_t envelope_rgba[4];
47  uint8_t envelope_color[4];
54  float fgopacity;
55  float bgopacity;
56  int planewidth[4];
57  int planeheight[4];
58  int start[4];
61 
62 #define OFFSET(x) offsetof(HistogramContext, x)
63 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
64 
65 #define COMMON_OPTIONS \
66  { "display_mode", "set display mode", OFFSET(display_mode), AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "display_mode"}, \
67  { "d", "set display mode", OFFSET(display_mode), AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "display_mode"}, \
68  { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "display_mode" }, \
69  { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "display_mode" }, \
70  { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "display_mode" }, \
71  { "levels_mode", "set levels mode", OFFSET(levels_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "levels_mode"}, \
72  { "m", "set levels mode", OFFSET(levels_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "levels_mode"}, \
73  { "linear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "levels_mode" }, \
74  { "logarithmic", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "levels_mode" }, \
75  { "components", "set color components to display", OFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 1, 15, FLAGS}, \
76  { "c", "set color components to display", OFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 1, 15, FLAGS},
77 
78 static const AVOption histogram_options[] = {
79  { "level_height", "set level height", OFFSET(level_height), AV_OPT_TYPE_INT, {.i64=200}, 50, 2048, FLAGS},
80  { "scale_height", "set scale height", OFFSET(scale_height), AV_OPT_TYPE_INT, {.i64=12}, 0, 40, FLAGS},
82  { "fgopacity", "set foreground opacity", OFFSET(fgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.7}, 0, 1, FLAGS},
83  { "f", "set foreground opacity", OFFSET(fgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.7}, 0, 1, FLAGS},
84  { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS},
85  { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS},
86  { NULL }
87 };
88 
89 AVFILTER_DEFINE_CLASS(histogram);
90 
91 static const enum AVPixelFormat levels_in_pix_fmts[] = {
108 };
109 
113 };
114 
118 };
119 
123 };
124 
128 };
129 
133 };
134 
138 };
139 
143 };
144 
148 };
149 
151 {
152  AVFilterFormats *avff;
153  const AVPixFmtDescriptor *desc;
154  const enum AVPixelFormat *out_pix_fmts;
155  int rgb, i, bits;
156  int ret;
157 
158  if (!ctx->inputs[0]->incfg.formats ||
159  !ctx->inputs[0]->incfg.formats->nb_formats) {
160  return AVERROR(EAGAIN);
161  }
162 
163  if (!ctx->inputs[0]->outcfg.formats)
164  if ((ret = ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->outcfg.formats)) < 0)
165  return ret;
166  avff = ctx->inputs[0]->incfg.formats;
167  desc = av_pix_fmt_desc_get(avff->formats[0]);
168  rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
169  bits = desc->comp[0].depth;
170  for (i = 1; i < avff->nb_formats; i++) {
171  desc = av_pix_fmt_desc_get(avff->formats[i]);
172  if ((rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB)) ||
173  (bits != desc->comp[0].depth))
174  return AVERROR(EAGAIN);
175  }
176 
177  if (rgb && bits == 8)
179  else if (rgb && bits == 9)
181  else if (rgb && bits == 10)
183  else if (rgb && bits == 12)
185  else if (bits == 8)
187  else if (bits == 9)
189  else if (bits == 10)
191  else if (bits == 12)
193  else
194  return AVERROR(EAGAIN);
195  if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->incfg.formats)) < 0)
196  return ret;
197 
198  return 0;
199 }
200 
201 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
202 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
203 static const uint8_t white_yuva_color[4] = { 255, 127, 127, 255 };
204 static const uint8_t white_gbrp_color[4] = { 255, 255, 255, 255 };
205 
207 {
208  HistogramContext *s = inlink->dst->priv;
209 
210  s->desc = av_pix_fmt_desc_get(inlink->format);
211  s->ncomp = s->desc->nb_components;
212  s->histogram_size = 1 << s->desc->comp[0].depth;
213  s->mult = s->histogram_size / 256;
214 
215  switch (inlink->format) {
216  case AV_PIX_FMT_GBRAP12:
217  case AV_PIX_FMT_GBRP12:
218  case AV_PIX_FMT_GBRAP10:
219  case AV_PIX_FMT_GBRP10:
220  case AV_PIX_FMT_GBRP9:
221  case AV_PIX_FMT_GBRAP:
222  case AV_PIX_FMT_GBRP:
223  memcpy(s->bg_color, black_gbrp_color, 4);
224  memcpy(s->fg_color, white_gbrp_color, 4);
225  s->start[0] = s->start[1] = s->start[2] = s->start[3] = 0;
226  memcpy(s->envelope_color, s->envelope_rgba, 4);
227  break;
228  default:
229  memcpy(s->bg_color, black_yuva_color, 4);
230  memcpy(s->fg_color, white_yuva_color, 4);
231  s->start[0] = s->start[3] = 0;
232  s->start[1] = s->start[2] = s->histogram_size / 2;
233  s->envelope_color[0] = RGB_TO_Y_BT709(s->envelope_rgba[0], s->envelope_rgba[1], s->envelope_rgba[2]);
234  s->envelope_color[1] = RGB_TO_U_BT709(s->envelope_rgba[0], s->envelope_rgba[1], s->envelope_rgba[2], 0);
235  s->envelope_color[2] = RGB_TO_V_BT709(s->envelope_rgba[0], s->envelope_rgba[1], s->envelope_rgba[2], 0);
236  s->envelope_color[3] = s->envelope_rgba[3];
237  }
238 
239  s->fg_color[3] = s->fgopacity * 255;
240  s->bg_color[3] = s->bgopacity * 255;
241 
242  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h);
243  s->planeheight[0] = s->planeheight[3] = inlink->h;
244  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, s->desc->log2_chroma_w);
245  s->planewidth[0] = s->planewidth[3] = inlink->w;
246 
247  return 0;
248 }
249 
250 static int config_output(AVFilterLink *outlink)
251 {
252  AVFilterContext *ctx = outlink->src;
253  HistogramContext *s = ctx->priv;
254  int ncomp = 0, i;
255 
256  if (!strcmp(ctx->filter->name, "thistogram"))
257  s->thistogram = 1;
258 
259  for (i = 0; i < s->ncomp; i++) {
260  if ((1 << i) & s->components)
261  ncomp++;
262  }
263 
264  if (s->thistogram) {
265  if (!s->width)
266  s->width = ctx->inputs[0]->w;
267  outlink->w = s->width * FFMAX(ncomp * (s->display_mode == 1), 1);
268  outlink->h = s->histogram_size * FFMAX(ncomp * (s->display_mode == 2), 1);
269  } else {
270  outlink->w = s->histogram_size * FFMAX(ncomp * (s->display_mode == 1), 1);
271  outlink->h = (s->level_height + s->scale_height) * FFMAX(ncomp * (s->display_mode == 2), 1);
272  }
273 
274  s->odesc = av_pix_fmt_desc_get(outlink->format);
275  s->dncomp = s->odesc->nb_components;
276  outlink->sample_aspect_ratio = (AVRational){1,1};
277 
278  return 0;
279 }
280 
282 {
283  HistogramContext *s = inlink->dst->priv;
284  AVFilterContext *ctx = inlink->dst;
285  AVFilterLink *outlink = ctx->outputs[0];
286  AVFrame *out = s->out;
287  int i, j, k, l, m;
288 
289  if (!s->thistogram || !out) {
290  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
291  if (!out) {
292  av_frame_free(&in);
293  return AVERROR(ENOMEM);
294  }
295  s->out = out;
296 
297  for (k = 0; k < 4 && out->data[k]; k++) {
298  const int is_chroma = (k == 1 || k == 2);
299  const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? s->odesc->log2_chroma_h : 0));
300  const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? s->odesc->log2_chroma_w : 0));
301 
302  if (s->histogram_size <= 256) {
303  for (i = 0; i < dst_h ; i++)
304  memset(out->data[s->odesc->comp[k].plane] +
305  i * out->linesize[s->odesc->comp[k].plane],
306  s->bg_color[k], dst_w);
307  } else {
308  const int mult = s->mult;
309 
310  for (i = 0; i < dst_h ; i++)
311  for (j = 0; j < dst_w; j++)
312  AV_WN16(out->data[s->odesc->comp[k].plane] +
313  i * out->linesize[s->odesc->comp[k].plane] + j * 2,
314  s->bg_color[k] * mult);
315  }
316  }
317  }
318 
319  for (m = 0, k = 0; k < s->ncomp; k++) {
320  const int p = s->desc->comp[k].plane;
321  const int max_value = s->histogram_size - 1 - s->start[p];
322  const int height = s->planeheight[p];
323  const int width = s->planewidth[p];
324  double max_hval_log;
325  unsigned max_hval = 0;
326  int starty, startx;
327 
328  if (!((1 << k) & s->components))
329  continue;
330  if (s->thistogram) {
331  starty = m * s->histogram_size * (s->display_mode == 2);
332  startx = m++ * s->width * (s->display_mode == 1);
333  } else {
334  startx = m * s->histogram_size * (s->display_mode == 1);
335  starty = m++ * (s->level_height + s->scale_height) * (s->display_mode == 2);
336  }
337 
338  if (s->histogram_size <= 256) {
339  for (i = 0; i < height; i++) {
340  const uint8_t *src = in->data[p] + i * in->linesize[p];
341  for (j = 0; j < width; j++)
342  s->histogram[src[j]]++;
343  }
344  } else {
345  for (i = 0; i < height; i++) {
346  const uint16_t *src = (const uint16_t *)(in->data[p] + i * in->linesize[p]);
347  for (j = 0; j < width; j++)
348  s->histogram[src[j]]++;
349  }
350  }
351 
352  for (i = 0; i < s->histogram_size; i++)
353  max_hval = FFMAX(max_hval, s->histogram[i]);
354  max_hval_log = log2(max_hval + 1);
355 
356  if (s->thistogram) {
357  const int bpp = 1 + (s->histogram_size > 256);
358  int minh = s->histogram_size - 1, maxh = 0;
359 
360  if (s->slide == 2) {
361  s->x_pos = out->width - 1;
362  for (j = 0; j < outlink->h; j++) {
363  memmove(out->data[p] + j * out->linesize[p] ,
364  out->data[p] + j * out->linesize[p] + bpp,
365  (outlink->w - 1) * bpp);
366  }
367  } else if (s->slide == 3) {
368  s->x_pos = 0;
369  for (j = 0; j < outlink->h; j++) {
370  memmove(out->data[p] + j * out->linesize[p] + bpp,
371  out->data[p] + j * out->linesize[p],
372  (outlink->w - 1) * bpp);
373  }
374  }
375 
376  for (int i = 0; i < s->histogram_size; i++) {
377  int idx = s->histogram_size - i - 1;
378  int value = s->start[p];
379 
380  if (s->envelope && s->histogram[idx]) {
381  minh = FFMIN(minh, i);
382  maxh = FFMAX(maxh, i);
383  }
384 
385  if (s->levels_mode)
386  value += lrint(max_value * (log2(s->histogram[idx] + 1) / max_hval_log));
387  else
388  value += lrint(max_value * s->histogram[idx] / (float)max_hval);
389 
390  if (s->histogram_size <= 256) {
391  s->out->data[p][(i + starty) * s->out->linesize[p] + startx + s->x_pos] = value;
392  } else {
393  AV_WN16(s->out->data[p] + (i + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, value);
394  }
395  }
396 
397  if (s->envelope) {
398  if (s->histogram_size <= 256) {
399  s->out->data[0][(minh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[0];
400  s->out->data[0][(maxh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[0];
401  if (s->dncomp >= 3) {
402  s->out->data[1][(minh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[1];
403  s->out->data[2][(minh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[2];
404  s->out->data[1][(maxh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[1];
405  s->out->data[2][(maxh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[2];
406  }
407  } else {
408  const int mult = s->mult;
409 
410  AV_WN16(s->out->data[0] + (minh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[0] * mult);
411  AV_WN16(s->out->data[0] + (maxh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[0] * mult);
412  if (s->dncomp >= 3) {
413  AV_WN16(s->out->data[1] + (minh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[1] * mult);
414  AV_WN16(s->out->data[2] + (minh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[2] * mult);
415  AV_WN16(s->out->data[1] + (maxh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[1] * mult);
416  AV_WN16(s->out->data[2] + (maxh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[2] * mult);
417  }
418  }
419  }
420  } else {
421  for (i = 0; i < s->histogram_size; i++) {
422  int col_height;
423 
424  if (s->levels_mode)
425  col_height = lrint(s->level_height * (1. - (log2(s->histogram[i] + 1) / max_hval_log)));
426  else
427  col_height = s->level_height - (s->histogram[i] * (int64_t)s->level_height + max_hval - 1) / max_hval;
428 
429  if (s->histogram_size <= 256) {
430  for (j = s->level_height - 1; j >= col_height; j--) {
431  if (s->display_mode) {
432  for (l = 0; l < s->dncomp; l++)
433  out->data[l][(j + starty) * out->linesize[l] + startx + i] = s->fg_color[l];
434  } else {
435  out->data[p][(j + starty) * out->linesize[p] + startx + i] = 255;
436  }
437  }
438  for (j = s->level_height + s->scale_height - 1; j >= s->level_height; j--)
439  out->data[p][(j + starty) * out->linesize[p] + startx + i] = i;
440  } else {
441  const int mult = s->mult;
442 
443  for (j = s->level_height - 1; j >= col_height; j--) {
444  if (s->display_mode) {
445  for (l = 0; l < s->dncomp; l++)
446  AV_WN16(out->data[l] + (j + starty) * out->linesize[l] + startx * 2 + i * 2, s->fg_color[l] * mult);
447  } else {
448  AV_WN16(out->data[p] + (j + starty) * out->linesize[p] + startx * 2 + i * 2, 255 * mult);
449  }
450  }
451  for (j = s->level_height + s->scale_height - 1; j >= s->level_height; j--)
452  AV_WN16(out->data[p] + (j + starty) * out->linesize[p] + startx * 2 + i * 2, i);
453  }
454  }
455  }
456 
457  memset(s->histogram, 0, s->histogram_size * sizeof(unsigned));
458  }
459 
460  out->pts = in->pts;
461  av_frame_free(&in);
462  s->x_pos++;
463  if (s->x_pos >= s->width) {
464  s->x_pos = 0;
465  if (s->thistogram && (s->slide == 4 || s->slide == 0)) {
466  s->out = NULL;
467  goto end;
468  }
469  } else if (s->thistogram && s->slide == 4) {
470  return 0;
471  }
472 
473  if (s->thistogram) {
474  AVFrame *clone = av_frame_clone(out);
475 
476  if (!clone)
477  return AVERROR(ENOMEM);
478  return ff_filter_frame(outlink, clone);
479  }
480 end:
481  return ff_filter_frame(outlink, out);
482 }
483 
484 static const AVFilterPad inputs[] = {
485  {
486  .name = "default",
487  .type = AVMEDIA_TYPE_VIDEO,
488  .filter_frame = filter_frame,
489  .config_props = config_input,
490  },
491 };
492 
493 static const AVFilterPad outputs[] = {
494  {
495  .name = "default",
496  .type = AVMEDIA_TYPE_VIDEO,
497  .config_props = config_output,
498  },
499 };
500 
501 #if CONFIG_HISTOGRAM_FILTER
502 
503 const AVFilter ff_vf_histogram = {
504  .name = "histogram",
505  .description = NULL_IF_CONFIG_SMALL("Compute and draw a histogram."),
506  .priv_size = sizeof(HistogramContext),
510  .priv_class = &histogram_class,
511 };
512 
513 #endif /* CONFIG_HISTOGRAM_FILTER */
514 
515 #if CONFIG_THISTOGRAM_FILTER
516 
517 static av_cold void uninit(AVFilterContext *ctx)
518 {
519  HistogramContext *s = ctx->priv;
520 
521  av_frame_free(&s->out);
522 }
523 
524 static const AVOption thistogram_options[] = {
525  { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
526  { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
528  { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGS},
529  { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGS},
530  { "envelope", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
531  { "e", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
532  { "ecolor", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
533  { "ec", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
534  { "slide", "set slide mode", OFFSET(slide), AV_OPT_TYPE_INT, {.i64=1}, 0, 4, FLAGS, "slide" },
535  {"frame", "draw new frames", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "slide"},
536  {"replace", "replace old columns with new", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "slide"},
537  {"scroll", "scroll from right to left", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "slide"},
538  {"rscroll", "scroll from left to right", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "slide"},
539  {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"},
540  { NULL }
541 };
542 
543 AVFILTER_DEFINE_CLASS(thistogram);
544 
545 const AVFilter ff_vf_thistogram = {
546  .name = "thistogram",
547  .description = NULL_IF_CONFIG_SMALL("Compute and draw a temporal histogram."),
548  .priv_size = sizeof(HistogramContext),
552  .uninit = uninit,
553  .priv_class = &thistogram_class,
554 };
555 
556 #endif /* CONFIG_THISTOGRAM_FILTER */
FLAGS
#define FLAGS
Definition: vf_histogram.c:63
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:98
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
HistogramContext::ncomp
int ncomp
Definition: vf_histogram.c:42
ff_vf_thistogram
const AVFilter ff_vf_thistogram
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:380
out
FILE * out
Definition: movenc.c:54
HistogramContext::envelope_rgba
uint8_t envelope_rgba[4]
Definition: vf_histogram.c:46
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1019
outputs
static const AVFilterPad outputs[]
Definition: vf_histogram.c:493
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2540
HistogramContext::out
AVFrame * out
Definition: vf_histogram.c:59
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
HistogramContext::odesc
const AVPixFmtDescriptor * odesc
Definition: vf_histogram.c:52
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:424
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_histogram.c:150
HistogramContext::level_height
int level_height
Definition: vf_histogram.c:48
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
black_yuva_color
static const uint8_t black_yuva_color[4]
Definition: vf_histogram.c:201
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:426
AVOption
AVOption.
Definition: opt.h:247
levels_out_yuv8_pix_fmts
static enum AVPixelFormat levels_out_yuv8_pix_fmts[]
Definition: vf_histogram.c:110
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:389
levels_out_yuv9_pix_fmts
static enum AVPixelFormat levels_out_yuv9_pix_fmts[]
Definition: vf_histogram.c:115
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_histogram.c:206
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilterFormats::formats
int * formats
list of media formats
Definition: formats.h:66
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_histogram.c:281
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
white_gbrp_color
static const uint8_t white_gbrp_color[4]
Definition: vf_histogram.c:204
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:427
HistogramContext::display_mode
int display_mode
Definition: vf_histogram.c:50
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
HistogramContext::envelope
int envelope
Definition: vf_histogram.c:35
HistogramContext
Definition: vf_histogram.c:32
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:423
rgb
Definition: rpzaenc.c:59
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:405
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:387
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
levels_out_rgb10_pix_fmts
static enum AVPixelFormat levels_out_rgb10_pix_fmts[]
Definition: vf_histogram.c:140
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:392
AV_PIX_FMT_YUVJ411P
@ 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:248
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:56
lrint
#define lrint
Definition: tablegen.h:53
colorspace.h
av_cold
#define av_cold
Definition: attributes.h:90
HistogramContext::levels_mode
int levels_mode
Definition: vf_histogram.c:51
HistogramContext::slide
int slide
Definition: vf_histogram.c:36
AV_PIX_FMT_YUVJ422P
@ 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_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:409
width
#define width
HistogramContext::scale_height
int scale_height
Definition: vf_histogram.c:49
RGB_TO_Y_BT709
#define RGB_TO_Y_BT709(r, g, b)
Definition: vf_pseudocolor.c:558
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
histogram_options
static const AVOption histogram_options[]
Definition: vf_histogram.c:78
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:410
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
RGB_TO_U_BT709
#define RGB_TO_U_BT709(r1, g1, b1, max)
Definition: vf_pseudocolor.c:562
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:553
HistogramContext::envelope_color
uint8_t envelope_color[4]
Definition: vf_histogram.c:47
HistogramContext::bgopacity
float bgopacity
Definition: vf_histogram.c:55
bits
uint8_t bits
Definition: vp3data.h:141
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:430
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:386
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:424
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
HistogramContext::bg_color
uint8_t bg_color[4]
Definition: vf_histogram.c:44
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:152
AV_PIX_FMT_YUVJ444P
@ 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
HistogramContext::mult
int mult
Definition: vf_histogram.c:41
HistogramContext::start
int start[4]
Definition: vf_histogram.c:58
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_YUVJ420P
@ 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
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:239
src
#define src
Definition: vp8dsp.c:255
levels_out_rgb12_pix_fmts
static enum AVPixelFormat levels_out_rgb12_pix_fmts[]
Definition: vf_histogram.c:145
parseutils.h
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
HistogramContext::thistogram
int thistogram
Definition: vf_histogram.c:34
HistogramContext::histogram_size
int histogram_size
Definition: vf_histogram.c:38
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:390
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:404
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_histogram.c:250
ff_vf_histogram
const AVFilter ff_vf_histogram
HistogramContext::width
int width
Definition: vf_histogram.c:39
RGB_TO_V_BT709
#define RGB_TO_V_BT709(r1, g1, b1, max)
Definition: vf_pseudocolor.c:566
inputs
static const AVFilterPad inputs[]
Definition: vf_histogram.c:484
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(histogram)
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:394
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:396
HistogramContext::dncomp
int dncomp
Definition: vf_histogram.c:43
OFFSET
#define OFFSET(x)
Definition: vf_histogram.c:62
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:428
levels_in_pix_fmts
static enum AVPixelFormat levels_in_pix_fmts[]
Definition: vf_histogram.c:91
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
i
int i
Definition: input.c:406
envelope
static float envelope(const float x)
Definition: vf_monochrome.c:46
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:406
HistogramContext::fgopacity
float fgopacity
Definition: vf_histogram.c:54
out_pix_fmts
static enum AVPixelFormat out_pix_fmts[]
Definition: vf_ciescope.c:133
HistogramContext::planeheight
int planeheight[4]
Definition: vf_histogram.c:57
levels_out_yuv10_pix_fmts
static enum AVPixelFormat levels_out_yuv10_pix_fmts[]
Definition: vf_histogram.c:120
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
HistogramContext::x_pos
int x_pos
Definition: vf_histogram.c:40
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
HistogramContext::desc
const AVPixFmtDescriptor * desc
Definition: vf_histogram.c:52
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
HistogramContext::components
int components
Definition: vf_histogram.c:53
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:388
log2
#define log2(x)
Definition: libm.h:404
COMMON_OPTIONS
#define COMMON_OPTIONS
Definition: vf_histogram.c:65
AVFilter
Filter definition.
Definition: avfilter.h:149
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:425
HistogramContext::fg_color
uint8_t fg_color[4]
Definition: vf_histogram.c:45
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:393
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:429
levels_out_rgb8_pix_fmts
static enum AVPixelFormat levels_out_rgb8_pix_fmts[]
Definition: vf_histogram.c:130
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
HistogramContext::planewidth
int planewidth[4]
Definition: vf_histogram.c:56
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:346
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
levels_out_yuv12_pix_fmts
static enum AVPixelFormat levels_out_yuv12_pix_fmts[]
Definition: vf_histogram.c:125
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:334
rgb
static const SheerTable rgb[2]
Definition: sheervideodata.h:32
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
levels_out_rgb9_pix_fmts
static enum AVPixelFormat levels_out_rgb9_pix_fmts[]
Definition: vf_histogram.c:135
HistogramContext::histogram
unsigned histogram[256 *256]
Definition: vf_histogram.c:37
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:395
black_gbrp_color
static const uint8_t black_gbrp_color[4]
Definition: vf_histogram.c:202
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:166
white_yuva_color
static const uint8_t white_yuva_color[4]
Definition: vf_histogram.c:203
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:372