FFmpeg
vf_fftdnoiz.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <float.h>
20 
21 #include "libavutil/common.h"
22 #include "libavutil/imgutils.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/pixdesc.h"
25 #include "internal.h"
26 #include "libavcodec/avfft.h"
27 
33 };
34 
35 typedef struct PlaneContext {
37  int nox, noy;
38  int b;
39  int o;
40  float n;
41 
42  float *buffer[BSIZE];
46 
48 } PlaneContext;
49 
50 typedef struct FFTdnoizContext {
51  const AVClass *class;
52 
53  float sigma;
54  float amount;
56  float overlap;
57  int nb_prev;
58  int nb_next;
59  int planesf;
60 
62 
63  int depth;
64  int nb_planes;
66 
67  void (*import_row)(FFTComplex *dst, uint8_t *src, int rw);
68  void (*export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth);
70 
71 #define OFFSET(x) offsetof(FFTdnoizContext, x)
72 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
73 static const AVOption fftdnoiz_options[] = {
74  { "sigma", "set denoise strength",
75  OFFSET(sigma), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 30, .flags = FLAGS },
76  { "amount", "set amount of denoising",
77  OFFSET(amount), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0.01, 1, .flags = FLAGS },
78  { "block", "set block log2(size)",
79  OFFSET(block_bits), AV_OPT_TYPE_INT, {.i64=4}, 3, 6, .flags = FLAGS },
80  { "overlap", "set block overlap",
81  OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0.2, 0.8, .flags = FLAGS },
82  { "prev", "set number of previous frames for temporal denoising",
83  OFFSET(nb_prev), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = FLAGS },
84  { "next", "set number of next frames for temporal denoising",
85  OFFSET(nb_next), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = FLAGS },
86  { "planes", "set planes to filter",
87  OFFSET(planesf), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, .flags = FLAGS },
88  { NULL }
89 };
90 
91 AVFILTER_DEFINE_CLASS(fftdnoiz);
92 
94 {
95  FFTdnoizContext *s = ctx->priv;
96  int i;
97 
98  for (i = 0; i < 4; i++) {
99  PlaneContext *p = &s->planes[i];
100 
101  p->fft = av_fft_init(s->block_bits, 0);
102  p->ifft = av_fft_init(s->block_bits, 1);
103  if (!p->fft || !p->ifft)
104  return AVERROR(ENOMEM);
105  }
106 
107  return 0;
108 }
109 
111 {
112  static const enum AVPixelFormat pix_fmts[] = {
137  };
139 }
140 
141 typedef struct ThreadData {
142  float *src, *dst;
143 } ThreadData;
144 
145 static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
146 {
147  int j;
148 
149  for (j = 0; j < rw; j++) {
150  dst[j].re = src[j];
151  dst[j].im = 0;
152  }
153 }
154 
155 static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
156 {
157  int j;
158 
159  for (j = 0; j < rw; j++)
160  dst[j] = av_clip_uint8(lrintf(src[j].re * scale));
161 }
162 
163 static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
164 {
165  uint16_t *src = (uint16_t *)srcp;
166  int j;
167 
168  for (j = 0; j < rw; j++) {
169  dst[j].re = src[j];
170  dst[j].im = 0;
171  }
172 }
173 
174 static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
175 {
176  uint16_t *dst = (uint16_t *)dstp;
177  int j;
178 
179  for (j = 0; j < rw; j++)
180  dst[j] = av_clip_uintp2_c(src[j].re * scale + 0.5f, depth);
181 }
182 
184 {
185  AVFilterContext *ctx = inlink->dst;
186  const AVPixFmtDescriptor *desc;
187  FFTdnoizContext *s = ctx->priv;
188  int i;
189 
190  desc = av_pix_fmt_desc_get(inlink->format);
191  s->depth = desc->comp[0].depth;
192 
193  if (s->depth <= 8) {
194  s->import_row = import_row8;
195  s->export_row = export_row8;
196  } else {
197  s->import_row = import_row16;
198  s->export_row = export_row16;
199  s->sigma *= 1 << (s->depth - 8) * (1 + s->nb_prev + s->nb_next);
200  }
201 
202  s->planes[1].planewidth = s->planes[2].planewidth = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
203  s->planes[0].planewidth = s->planes[3].planewidth = inlink->w;
204  s->planes[1].planeheight = s->planes[2].planeheight = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
205  s->planes[0].planeheight = s->planes[3].planeheight = inlink->h;
206 
207  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
208 
209  for (i = 0; i < s->nb_planes; i++) {
210  PlaneContext *p = &s->planes[i];
211  int size;
212 
213  p->b = 1 << s->block_bits;
214  p->n = 1.f / (p->b * p->b);
215  p->o = p->b * s->overlap;
216  size = p->b - p->o;
217  p->nox = (p->planewidth + (size - 1)) / size;
218  p->noy = (p->planeheight + (size - 1)) / size;
219 
220  av_log(ctx, AV_LOG_DEBUG, "nox:%d noy:%d size:%d\n", p->nox, p->noy, size);
221 
222  p->buffer_linesize = p->b * p->nox * sizeof(FFTComplex);
223  p->buffer[CURRENT] = av_calloc(p->b * p->noy, p->buffer_linesize);
224  if (!p->buffer[CURRENT])
225  return AVERROR(ENOMEM);
226  if (s->nb_prev > 0) {
227  p->buffer[PREV] = av_calloc(p->b * p->noy, p->buffer_linesize);
228  if (!p->buffer[PREV])
229  return AVERROR(ENOMEM);
230  }
231  if (s->nb_next > 0) {
232  p->buffer[NEXT] = av_calloc(p->b * p->noy, p->buffer_linesize);
233  if (!p->buffer[NEXT])
234  return AVERROR(ENOMEM);
235  }
236  p->data_linesize = 2 * p->b * sizeof(float);
237  p->hdata = av_calloc(p->b, p->data_linesize);
238  p->vdata = av_calloc(p->b, p->data_linesize);
239  if (!p->hdata || !p->vdata)
240  return AVERROR(ENOMEM);
241  }
242 
243  return 0;
244 }
245 
247  uint8_t *srcp, int src_linesize,
248  float *buffer, int buffer_linesize, int plane)
249 {
250  PlaneContext *p = &s->planes[plane];
251  const int width = p->planewidth;
252  const int height = p->planeheight;
253  const int block = p->b;
254  const int overlap = p->o;
255  const int size = block - overlap;
256  const int nox = p->nox;
257  const int noy = p->noy;
258  const int bpp = (s->depth + 7) / 8;
259  const int data_linesize = p->data_linesize / sizeof(FFTComplex);
260  FFTComplex *hdata = p->hdata;
261  FFTComplex *vdata = p->vdata;
262  int x, y, i, j;
263 
264  buffer_linesize /= sizeof(float);
265  for (y = 0; y < noy; y++) {
266  for (x = 0; x < nox; x++) {
267  const int rh = FFMIN(block, height - y * size);
268  const int rw = FFMIN(block, width - x * size);
269  uint8_t *src = srcp + src_linesize * y * size + x * size * bpp;
270  float *bdst = buffer + buffer_linesize * y * block + x * block * 2;
271  FFTComplex *ssrc, *dst = hdata;
272 
273  for (i = 0; i < rh; i++) {
274  s->import_row(dst, src, rw);
275  for (j = rw; j < block; j++) {
276  dst[j].re = dst[block - j - 1].re;
277  dst[j].im = 0;
278  }
279  av_fft_permute(p->fft, dst);
280  av_fft_calc(p->fft, dst);
281 
282  src += src_linesize;
283  dst += data_linesize;
284  }
285 
286  dst = hdata;
287  for (; i < block; i++) {
288  for (j = 0; j < block; j++) {
289  dst[j].re = dst[(block - i - 1) * data_linesize + j].re;
290  dst[j].im = dst[(block - i - 1) * data_linesize + j].im;
291  }
292  }
293 
294  ssrc = hdata;
295  dst = vdata;
296  for (i = 0; i < block; i++) {
297  for (j = 0; j < block; j++)
298  dst[j] = ssrc[j * data_linesize + i];
299  av_fft_permute(p->fft, dst);
300  av_fft_calc(p->fft, dst);
301  memcpy(bdst, dst, block * sizeof(FFTComplex));
302 
303  dst += data_linesize;
304  bdst += buffer_linesize;
305  }
306  }
307  }
308 }
309 
311  uint8_t *dstp, int dst_linesize,
312  float *buffer, int buffer_linesize, int plane)
313 {
314  PlaneContext *p = &s->planes[plane];
315  const int depth = s->depth;
316  const int bpp = (depth + 7) / 8;
317  const int width = p->planewidth;
318  const int height = p->planeheight;
319  const int block = p->b;
320  const int overlap = p->o;
321  const int hoverlap = overlap / 2;
322  const int size = block - overlap;
323  const int nox = p->nox;
324  const int noy = p->noy;
325  const int data_linesize = p->data_linesize / sizeof(FFTComplex);
326  const float scale = 1.f / (block * block);
327  FFTComplex *hdata = p->hdata;
328  FFTComplex *vdata = p->vdata;
329  int x, y, i, j;
330 
331  buffer_linesize /= sizeof(float);
332  for (y = 0; y < noy; y++) {
333  for (x = 0; x < nox; x++) {
334  const int woff = x == 0 ? 0 : hoverlap;
335  const int hoff = y == 0 ? 0 : hoverlap;
336  const int rw = x == 0 ? block : FFMIN(size, width - x * size - woff);
337  const int rh = y == 0 ? block : FFMIN(size, height - y * size - hoff);
338  float *bsrc = buffer + buffer_linesize * y * block + x * block * 2;
339  uint8_t *dst = dstp + dst_linesize * (y * size + hoff) + (x * size + woff) * bpp;
340  FFTComplex *hdst, *ddst = vdata;
341 
342  hdst = hdata;
343  for (i = 0; i < block; i++) {
344  memcpy(ddst, bsrc, block * sizeof(FFTComplex));
345  av_fft_permute(p->ifft, ddst);
346  av_fft_calc(p->ifft, ddst);
347  for (j = 0; j < block; j++) {
348  hdst[j * data_linesize + i] = ddst[j];
349  }
350 
351  ddst += data_linesize;
352  bsrc += buffer_linesize;
353  }
354 
355  hdst = hdata + hoff * data_linesize;
356  for (i = 0; i < rh; i++) {
357  av_fft_permute(p->ifft, hdst);
358  av_fft_calc(p->ifft, hdst);
359  s->export_row(hdst + woff, dst, rw, scale, depth);
360 
361  hdst += data_linesize;
362  dst += dst_linesize;
363  }
364  }
365  }
366 }
367 
368 static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
369 {
370  PlaneContext *p = &s->planes[plane];
371  const int block = p->b;
372  const int nox = p->nox;
373  const int noy = p->noy;
374  const int buffer_linesize = p->buffer_linesize / sizeof(float);
375  const float sigma = s->sigma * s->sigma * block * block;
376  const float limit = 1.f - s->amount;
377  float *cbuffer = p->buffer[CURRENT];
378  const float cfactor = sqrtf(3.f) * 0.5f;
379  const float scale = 1.f / 3.f;
380  int y, x, i, j;
381 
382  for (y = 0; y < noy; y++) {
383  for (x = 0; x < nox; x++) {
384  float *cbuff = cbuffer + buffer_linesize * y * block + x * block * 2;
385  float *pbuff = pbuffer + buffer_linesize * y * block + x * block * 2;
386  float *nbuff = nbuffer + buffer_linesize * y * block + x * block * 2;
387 
388  for (i = 0; i < block; i++) {
389  for (j = 0; j < block; j++) {
390  float sumr, sumi, difr, difi, mpr, mpi, mnr, mni;
391  float factor, power, sumpnr, sumpni;
392 
393  sumpnr = pbuff[2 * j ] + nbuff[2 * j ];
394  sumpni = pbuff[2 * j + 1] + nbuff[2 * j + 1];
395  sumr = cbuff[2 * j ] + sumpnr;
396  sumi = cbuff[2 * j + 1] + sumpni;
397  difr = cfactor * (nbuff[2 * j ] - pbuff[2 * j ]);
398  difi = cfactor * (pbuff[2 * j + 1] - nbuff[2 * j + 1]);
399  mpr = cbuff[2 * j ] - 0.5f * sumpnr + difi;
400  mnr = mpr - difi - difi;
401  mpi = cbuff[2 * j + 1] - 0.5f * sumpni + difr;
402  mni = mpi - difr - difr;
403  power = sumr * sumr + sumi * sumi + 1e-15f;
404  factor = FFMAX((power - sigma) / power, limit);
405  sumr *= factor;
406  sumi *= factor;
407  power = mpr * mpr + mpi * mpi + 1e-15f;
408  factor = FFMAX((power - sigma) / power, limit);
409  mpr *= factor;
410  mpi *= factor;
411  power = mnr * mnr + mni * mni + 1e-15f;
412  factor = FFMAX((power - sigma) / power, limit);
413  mnr *= factor;
414  mni *= factor;
415  cbuff[2 * j ] = (sumr + mpr + mnr) * scale;
416  cbuff[2 * j + 1] = (sumi + mpi + mni) * scale;
417 
418  }
419 
420  cbuff += buffer_linesize;
421  pbuff += buffer_linesize;
422  nbuff += buffer_linesize;
423  }
424  }
425  }
426 }
427 
428 static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
429 {
430  PlaneContext *p = &s->planes[plane];
431  const int block = p->b;
432  const int nox = p->nox;
433  const int noy = p->noy;
434  const int buffer_linesize = p->buffer_linesize / sizeof(float);
435  const float sigma = s->sigma * s->sigma * block * block;
436  const float limit = 1.f - s->amount;
437  float *cbuffer = p->buffer[CURRENT];
438  int y, x, i, j;
439 
440  for (y = 0; y < noy; y++) {
441  for (x = 0; x < nox; x++) {
442  float *cbuff = cbuffer + buffer_linesize * y * block + x * block * 2;
443  float *pbuff = pbuffer + buffer_linesize * y * block + x * block * 2;
444 
445  for (i = 0; i < block; i++) {
446  for (j = 0; j < block; j++) {
447  float factor, power, re, im, pre, pim;
448  float sumr, sumi, difr, difi;
449 
450  re = cbuff[j * 2 ];
451  pre = pbuff[j * 2 ];
452  im = cbuff[j * 2 + 1];
453  pim = pbuff[j * 2 + 1];
454 
455  sumr = re + pre;
456  sumi = im + pim;
457  difr = re - pre;
458  difi = im - pim;
459 
460  power = sumr * sumr + sumi * sumi + 1e-15f;
461  factor = FFMAX(limit, (power - sigma) / power);
462  sumr *= factor;
463  sumi *= factor;
464  power = difr * difr + difi * difi + 1e-15f;
465  factor = FFMAX(limit, (power - sigma) / power);
466  difr *= factor;
467  difi *= factor;
468 
469  cbuff[j * 2 ] = (sumr + difr) * 0.5f;
470  cbuff[j * 2 + 1] = (sumi + difi) * 0.5f;
471  }
472 
473  cbuff += buffer_linesize;
474  pbuff += buffer_linesize;
475  }
476  }
477  }
478 }
479 
480 static void filter_plane2d(FFTdnoizContext *s, int plane)
481 {
482  PlaneContext *p = &s->planes[plane];
483  const int block = p->b;
484  const int nox = p->nox;
485  const int noy = p->noy;
486  const int buffer_linesize = p->buffer_linesize / 4;
487  const float sigma = s->sigma * s->sigma * block * block;
488  const float limit = 1.f - s->amount;
489  float *buffer = p->buffer[CURRENT];
490  int y, x, i, j;
491 
492  for (y = 0; y < noy; y++) {
493  for (x = 0; x < nox; x++) {
494  float *buff = buffer + buffer_linesize * y * block + x * block * 2;
495 
496  for (i = 0; i < block; i++) {
497  for (j = 0; j < block; j++) {
498  float factor, power, re, im;
499 
500  re = buff[j * 2 ];
501  im = buff[j * 2 + 1];
502  power = re * re + im * im + 1e-15f;
503  factor = FFMAX(limit, (power - sigma) / power);
504  buff[j * 2 ] *= factor;
505  buff[j * 2 + 1] *= factor;
506  }
507 
508  buff += buffer_linesize;
509  }
510  }
511  }
512 }
513 
515 {
516  AVFilterContext *ctx = inlink->dst;
517  FFTdnoizContext *s = ctx->priv;
518  AVFilterLink *outlink = ctx->outputs[0];
519  int direct, plane;
520  AVFrame *out;
521 
522  if (s->nb_next > 0 && s->nb_prev > 0) {
523  av_frame_free(&s->prev);
524  s->prev = s->cur;
525  s->cur = s->next;
526  s->next = in;
527 
528  if (!s->prev && s->cur) {
529  s->prev = av_frame_clone(s->cur);
530  if (!s->prev)
531  return AVERROR(ENOMEM);
532  }
533  if (!s->cur)
534  return 0;
535  } else if (s->nb_next > 0) {
536  av_frame_free(&s->cur);
537  s->cur = s->next;
538  s->next = in;
539 
540  if (!s->cur)
541  return 0;
542  } else if (s->nb_prev > 0) {
543  av_frame_free(&s->prev);
544  s->prev = s->cur;
545  s->cur = in;
546 
547  if (!s->prev)
548  s->prev = av_frame_clone(s->cur);
549  if (!s->prev)
550  return AVERROR(ENOMEM);
551  } else {
552  s->cur = in;
553  }
554 
555  if (av_frame_is_writable(in) && s->nb_next == 0 && s->nb_prev == 0) {
556  direct = 1;
557  out = in;
558  } else {
559  direct = 0;
560  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
561  if (!out)
562  return AVERROR(ENOMEM);
563  av_frame_copy_props(out, s->cur);
564  }
565 
566  for (plane = 0; plane < s->nb_planes; plane++) {
567  PlaneContext *p = &s->planes[plane];
568 
569  if (!((1 << plane) & s->planesf) || ctx->is_disabled) {
570  if (!direct)
571  av_image_copy_plane(out->data[plane], out->linesize[plane],
572  s->cur->data[plane], s->cur->linesize[plane],
573  p->planewidth, p->planeheight);
574  continue;
575  }
576 
577  if (s->next) {
578  import_plane(s, s->next->data[plane], s->next->linesize[plane],
579  p->buffer[NEXT], p->buffer_linesize, plane);
580  }
581 
582  if (s->prev) {
583  import_plane(s, s->prev->data[plane], s->prev->linesize[plane],
584  p->buffer[PREV], p->buffer_linesize, plane);
585  }
586 
587  import_plane(s, s->cur->data[plane], s->cur->linesize[plane],
588  p->buffer[CURRENT], p->buffer_linesize, plane);
589 
590  if (s->next && s->prev) {
591  filter_plane3d2(s, plane, p->buffer[PREV], p->buffer[NEXT]);
592  } else if (s->next) {
593  filter_plane3d1(s, plane, p->buffer[NEXT]);
594  } else if (s->prev) {
595  filter_plane3d1(s, plane, p->buffer[PREV]);
596  } else {
597  filter_plane2d(s, plane);
598  }
599 
600  export_plane(s, out->data[plane], out->linesize[plane],
601  p->buffer[CURRENT], p->buffer_linesize, plane);
602  }
603 
604  if (s->nb_next == 0 && s->nb_prev == 0) {
605  if (direct) {
606  s->cur = NULL;
607  } else {
608  av_frame_free(&s->cur);
609  }
610  }
611  return ff_filter_frame(outlink, out);
612 }
613 
614 static int request_frame(AVFilterLink *outlink)
615 {
616  AVFilterContext *ctx = outlink->src;
617  FFTdnoizContext *s = ctx->priv;
618  int ret = 0;
619 
620  ret = ff_request_frame(ctx->inputs[0]);
621 
622  if (ret == AVERROR_EOF && (s->nb_next > 0)) {
623  AVFrame *buf;
624 
625  if (s->next && s->nb_next > 0)
626  buf = av_frame_clone(s->next);
627  else if (s->cur)
628  buf = av_frame_clone(s->cur);
629  else
630  buf = av_frame_clone(s->prev);
631  if (!buf)
632  return AVERROR(ENOMEM);
633 
634  ret = filter_frame(ctx->inputs[0], buf);
635  if (ret < 0)
636  return ret;
637  ret = AVERROR_EOF;
638  }
639 
640  return ret;
641 }
642 
644 {
645  FFTdnoizContext *s = ctx->priv;
646  int i;
647 
648  for (i = 0; i < 4; i++) {
649  PlaneContext *p = &s->planes[i];
650 
651  av_freep(&p->hdata);
652  av_freep(&p->vdata);
653  av_freep(&p->buffer[PREV]);
654  av_freep(&p->buffer[CURRENT]);
655  av_freep(&p->buffer[NEXT]);
656  av_fft_end(p->fft);
657  av_fft_end(p->ifft);
658  }
659 
660  av_frame_free(&s->prev);
661  av_frame_free(&s->cur);
662  av_frame_free(&s->next);
663 }
664 
665 static const AVFilterPad fftdnoiz_inputs[] = {
666  {
667  .name = "default",
668  .type = AVMEDIA_TYPE_VIDEO,
669  .filter_frame = filter_frame,
670  .config_props = config_input,
671  },
672 };
673 
674 static const AVFilterPad fftdnoiz_outputs[] = {
675  {
676  .name = "default",
677  .type = AVMEDIA_TYPE_VIDEO,
678  .request_frame = request_frame,
679  },
680 };
681 
683  .name = "fftdnoiz",
684  .description = NULL_IF_CONFIG_SMALL("Denoise frames using 3D FFT."),
685  .priv_size = sizeof(FFTdnoizContext),
686  .init = init,
687  .uninit = uninit,
691  .priv_class = &fftdnoiz_class,
693 };
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
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:432
CURRENT
@ CURRENT
Definition: vf_fftdnoiz.c:29
av_fft_end
av_cold void av_fft_end(FFTContext *s)
Definition: avfft.c:48
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:411
direct
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
Definition: af_afir.c:61
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
PlaneContext::buffer_linesize
int buffer_linesize
Definition: vf_fftdnoiz.c:45
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
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: vf_fftdnoiz.c:614
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1019
FFTdnoizContext::nb_next
int nb_next
Definition: vf_fftdnoiz.c:58
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2540
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
bsrc
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT uint8_t const uint8_t const uint8_t * bsrc
Definition: input.c:398
block_bits
static const uint8_t block_bits[]
Definition: imm4.c:103
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
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
filter_plane2d
static void filter_plane2d(FFTdnoizContext *s, int plane)
Definition: vf_fftdnoiz.c:480
im
float im
Definition: fft.c:78
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
av_clip_uintp2_c
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.
Definition: common.h:276
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:431
export_plane
static void export_plane(FFTdnoizContext *s, uint8_t *dstp, int dst_linesize, float *buffer, int buffer_linesize, int plane)
Definition: vf_fftdnoiz.c:310
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:426
AVOption
AVOption.
Definition: opt.h:247
PlaneContext::b
int b
Definition: vf_fftdnoiz.c:38
fftdnoiz_outputs
static const AVFilterPad fftdnoiz_outputs[]
Definition: vf_fftdnoiz.c:674
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:389
FFTdnoizContext::sigma
float sigma
Definition: vf_fftdnoiz.c:53
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:421
av_fft_permute
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:38
PlaneContext::vdata
FFTComplex * vdata
Definition: vf_fftdnoiz.c:43
float.h
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
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:427
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:369
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
FFTdnoizContext::cur
AVFrame * cur
Definition: vf_fftdnoiz.c:61
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2580
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:423
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:407
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
PlaneContext::planeheight
int planeheight
Definition: vf_fftdnoiz.c:36
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:405
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:433
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:387
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:373
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
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
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:401
FFTdnoizContext::overlap
float overlap
Definition: vf_fftdnoiz.c:56
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
s
#define s(width, name)
Definition: cbs_vp9.c:257
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
PlaneContext::ifft
FFTContext * ifft
Definition: vf_fftdnoiz.c:47
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:402
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:703
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
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
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:400
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:372
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
f
#define f(width, name)
Definition: cbs_vp9.c:255
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
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:370
ThreadData::dst
AVFrame * dst
Definition: vf_blend.c:56
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:408
FFTdnoizContext::next
AVFrame * next
Definition: vf_fftdnoiz.c:61
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
PlaneContext::planewidth
int planewidth
Definition: vf_fftdnoiz.c:36
ThreadData::src
const uint8_t * src
Definition: vf_bm3d.c:55
FFTdnoizContext
Definition: vf_fftdnoiz.c:50
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
FFTdnoizContext::prev
AVFrame * prev
Definition: vf_fftdnoiz.c:61
src
#define src
Definition: vp8dsp.c:255
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:391
PlaneContext
Definition: ffv1.h:66
PlaneContext::data_linesize
int data_linesize
Definition: vf_fftdnoiz.c:44
avfft.h
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:390
PlaneContext::fft
FFTContext * fft
Definition: vf_fftdnoiz.c:47
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
FFTdnoizContext::depth
int depth
Definition: vf_fftdnoiz.c:63
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_fftdnoiz.c:183
FFTComplex
void FFTComplex
Definition: tx_priv.h:43
BSIZE
@ BSIZE
Definition: vf_fftdnoiz.c:32
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
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_fftdnoiz.c:93
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:394
size
int size
Definition: twinvq_data.h:10344
PlaneContext::o
int o
Definition: vf_fftdnoiz.c:39
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:396
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:473
FLAGS
#define FLAGS
Definition: vf_fftdnoiz.c:72
FFTComplex::im
FFTSample im
Definition: avfft.h:38
FFTComplex::re
FFTSample re
Definition: avfft.h:38
PREV
@ PREV
Definition: vf_fftdnoiz.c:30
FFTdnoizContext::import_row
void(* import_row)(FFTComplex *dst, uint8_t *src, int rw)
Definition: vf_fftdnoiz.c:67
export_row16
static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
Definition: vf_fftdnoiz.c:174
height
#define height
FFTdnoizContext::block_bits
int block_bits
Definition: vf_fftdnoiz.c:55
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
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_fftdnoiz.c:110
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
filter_plane3d2
static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
Definition: vf_fftdnoiz.c:368
PlaneContext::buffer
float * buffer[BSIZE]
Definition: vf_fftdnoiz.c:42
FFTdnoizContext::amount
float amount
Definition: vf_fftdnoiz.c:54
FFTdnoizContext::nb_planes
int nb_planes
Definition: vf_fftdnoiz.c:64
FFTdnoizContext::planes
PlaneContext planes[4]
Definition: vf_fftdnoiz.c:65
FFTContext
Definition: fft.h:75
i
int i
Definition: input.c:406
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
export_row8
static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
Definition: vf_fftdnoiz.c:155
FFTdnoizContext::planesf
int planesf
Definition: vf_fftdnoiz.c:59
import_row8
static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
Definition: vf_fftdnoiz.c:145
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:406
common.h
PlaneContext::nox
int nox
Definition: vf_fftdnoiz.c:37
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
import_row16
static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
Definition: vf_fftdnoiz.c:163
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_YUVJ440P
@ 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
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
OFFSET
#define OFFSET(x)
Definition: vf_fftdnoiz.c:71
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:388
limit
static double limit(double x)
Definition: vf_pseudocolor.c:128
NEXT
@ NEXT
Definition: vf_fftdnoiz.c:31
AVFilter
Filter definition.
Definition: avfilter.h:149
FFTdnoizContext::nb_prev
int nb_prev
Definition: vf_fftdnoiz.c:57
ret
ret
Definition: filter_design.txt:187
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_fftdnoiz.c:643
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:425
fftdnoiz_inputs
static const AVFilterPad fftdnoiz_inputs[]
Definition: vf_fftdnoiz.c:665
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:393
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:398
av_fft_init
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:28
PlaneContext::noy
int noy
Definition: vf_fftdnoiz.c:37
ff_vf_fftdnoiz
const AVFilter ff_vf_fftdnoiz
Definition: vf_fftdnoiz.c:682
import_plane
static void import_plane(FFTdnoizContext *s, uint8_t *srcp, int src_linesize, float *buffer, int buffer_linesize, int plane)
Definition: vf_fftdnoiz.c:246
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
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
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
av_clip_uint8
#define av_clip_uint8
Definition: common.h:102
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
factor
static const int factor[16]
Definition: vf_pp7.c:76
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
filter_plane3d1
static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
Definition: vf_fftdnoiz.c:428
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_fftdnoiz.c:514
PlaneContext::n
float n
Definition: vf_fftdnoiz.c:40
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:138
imgutils.h
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
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
PlaneContext::hdata
FFTComplex * hdata
Definition: vf_fftdnoiz.c:43
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:395
FFTdnoizContext::export_row
void(* export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
Definition: vf_fftdnoiz.c:68
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:399
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(fftdnoiz)
fftdnoiz_options
static const AVOption fftdnoiz_options[]
Definition: vf_fftdnoiz.c:73
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:371
av_fft_calc
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
Definition: avfft.c:43
BufferTypes
BufferTypes
Definition: vf_fftdnoiz.c:28
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
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:397
FFTComplex
Definition: avfft.h:37
re
float re
Definition: fft.c:78