FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/avassert.h"
22 #include "libavutil/common.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "internal.h"
27 #include "libavcodec/avfft.h"
28 
34 };
35 
36 typedef struct PlaneContext {
38  int nox, noy;
39  int b;
40  int o;
41  float n;
42 
43  float *buffer[BSIZE];
47 
49 } PlaneContext;
50 
51 typedef struct FFTdnoizContext {
52  const AVClass *class;
53 
54  float sigma;
55  float amount;
57  float overlap;
58  int nb_prev;
59  int nb_next;
60  int planesf;
61 
63 
64  int depth;
65  int nb_planes;
67 
68  void (*import_row)(FFTComplex *dst, uint8_t *src, int rw);
69  void (*export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth);
71 
72 #define OFFSET(x) offsetof(FFTdnoizContext, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
74 static const AVOption fftdnoiz_options[] = {
75  { "sigma", "set denoise strength",
76  OFFSET(sigma), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 30, .flags = FLAGS },
77  { "amount", "set amount of denoising",
78  OFFSET(amount), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0.01, 1, .flags = FLAGS },
79  { "block", "set block log2(size)",
80  OFFSET(block_bits), AV_OPT_TYPE_INT, {.i64=4}, 3, 6, .flags = FLAGS },
81  { "overlap", "set block overlap",
82  OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0.2, 0.8, .flags = FLAGS },
83  { "prev", "set number of previous frames for temporal denoising",
84  OFFSET(nb_prev), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = FLAGS },
85  { "next", "set number of next frames for temporal denoising",
86  OFFSET(nb_next), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = FLAGS },
87  { "planes", "set planes to filter",
88  OFFSET(planesf), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, .flags = FLAGS },
89  { NULL }
90 };
91 
92 AVFILTER_DEFINE_CLASS(fftdnoiz);
93 
95 {
96  FFTdnoizContext *s = ctx->priv;
97  int i;
98 
99  for (i = 0; i < 4; i++) {
100  PlaneContext *p = &s->planes[i];
101 
102  p->fft = av_fft_init(s->block_bits, 0);
103  p->ifft = av_fft_init(s->block_bits, 1);
104  if (!p->fft || !p->ifft)
105  return AVERROR(ENOMEM);
106  }
107 
108  return 0;
109 }
110 
112 {
113  static const enum AVPixelFormat pix_fmts[] = {
133  };
134  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
135  if (!fmts_list)
136  return AVERROR(ENOMEM);
137  return ff_set_common_formats(ctx, fmts_list);
138 }
139 
140 typedef struct ThreadData {
141  float *src, *dst;
142 } ThreadData;
143 
144 static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
145 {
146  int j;
147 
148  for (j = 0; j < rw; j++) {
149  dst[j].re = src[j];
150  dst[j].im = 0;
151  }
152 }
153 
154 static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
155 {
156  int j;
157 
158  for (j = 0; j < rw; j++)
159  dst[j] = av_clip_uint8(src[j].re * scale);
160 }
161 
162 static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
163 {
164  uint16_t *src = (uint16_t *)srcp;
165  int j;
166 
167  for (j = 0; j < rw; j++) {
168  dst[j].re = src[j];
169  dst[j].im = 0;
170  }
171 }
172 
173 static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
174 {
175  uint16_t *dst = (uint16_t *)dstp;
176  int j;
177 
178  for (j = 0; j < rw; j++)
179  dst[j] = av_clip_uintp2_c(src[j].re * scale, depth);
180 }
181 
182 static int config_input(AVFilterLink *inlink)
183 {
184  AVFilterContext *ctx = inlink->dst;
185  const AVPixFmtDescriptor *desc;
186  FFTdnoizContext *s = ctx->priv;
187  int i;
188 
189  desc = av_pix_fmt_desc_get(inlink->format);
190  s->depth = desc->comp[0].depth;
191 
192  if (s->depth <= 8) {
193  s->import_row = import_row8;
194  s->export_row = export_row8;
195  } else {
198  s->sigma *= 1 << (s->depth - 8) * (1 + s->nb_prev + s->nb_next);
199  }
200 
201  s->planes[1].planewidth = s->planes[2].planewidth = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
202  s->planes[0].planewidth = s->planes[3].planewidth = inlink->w;
203  s->planes[1].planeheight = s->planes[2].planeheight = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
204  s->planes[0].planeheight = s->planes[3].planeheight = inlink->h;
205 
207 
208  for (i = 0; i < s->nb_planes; i++) {
209  PlaneContext *p = &s->planes[i];
210  int size;
211 
212  p->b = 1 << s->block_bits;
213  p->n = 1.f / (p->b * p->b);
214  p->o = p->b * s->overlap;
215  size = p->b - p->o;
216  p->nox = (p->planewidth + (size - 1)) / size;
217  p->noy = (p->planeheight + (size - 1)) / size;
218 
219  av_log(ctx, AV_LOG_DEBUG, "nox:%d noy:%d size:%d\n", p->nox, p->noy, size);
220 
221  p->buffer_linesize = p->b * p->nox * sizeof(FFTComplex);
222  p->buffer[CURRENT] = av_calloc(p->b * p->noy, p->buffer_linesize);
223  if (!p->buffer[CURRENT])
224  return AVERROR(ENOMEM);
225  if (s->nb_prev > 0) {
226  p->buffer[PREV] = av_calloc(p->b * p->noy, p->buffer_linesize);
227  if (!p->buffer[PREV])
228  return AVERROR(ENOMEM);
229  }
230  if (s->nb_next > 0) {
231  p->buffer[NEXT] = av_calloc(p->b * p->noy, p->buffer_linesize);
232  if (!p->buffer[NEXT])
233  return AVERROR(ENOMEM);
234  }
235  p->data_linesize = 2 * p->b * sizeof(float);
236  p->hdata = av_calloc(p->b, p->data_linesize);
237  p->vdata = av_calloc(p->b, p->data_linesize);
238  if (!p->hdata || !p->vdata)
239  return AVERROR(ENOMEM);
240  }
241 
242  return 0;
243 }
244 
246  uint8_t *srcp, int src_linesize,
247  float *buffer, int buffer_linesize, int plane)
248 {
249  PlaneContext *p = &s->planes[plane];
250  const int width = p->planewidth;
251  const int height = p->planeheight;
252  const int block = p->b;
253  const int overlap = p->o;
254  const int size = block - overlap;
255  const int nox = p->nox;
256  const int noy = p->noy;
257  const int bpp = (s->depth + 7) / 8;
258  const int data_linesize = p->data_linesize / sizeof(FFTComplex);
259  FFTComplex *hdata = p->hdata;
260  FFTComplex *vdata = p->vdata;
261  int x, y, i, j;
262 
263  buffer_linesize /= sizeof(float);
264  for (y = 0; y < noy; y++) {
265  for (x = 0; x < nox; x++) {
266  const int rh = FFMIN(block, height - y * size);
267  const int rw = FFMIN(block, width - x * size);
268  uint8_t *src = srcp + src_linesize * y * size + x * size * bpp;
269  float *bdst = buffer + buffer_linesize * y * block + x * block * 2;
270  FFTComplex *ssrc, *dst = hdata;
271 
272  for (i = 0; i < rh; i++) {
273  s->import_row(dst, src, rw);
274  for (j = rw; j < block; j++) {
275  dst[j].re = dst[block - j - 1].re;
276  dst[j].im = 0;
277  }
278  av_fft_permute(p->fft, dst);
279  av_fft_calc(p->fft, dst);
280 
281  src += src_linesize;
282  dst += data_linesize;
283  }
284 
285  dst = hdata;
286  for (; i < block; i++) {
287  for (j = 0; j < block; j++) {
288  dst[j].re = dst[(block - i - 1) * data_linesize + j].re;
289  dst[j].im = dst[(block - i - 1) * data_linesize + j].im;
290  }
291  }
292 
293  ssrc = hdata;
294  dst = vdata;
295  for (i = 0; i < block; i++) {
296  for (j = 0; j < block; j++)
297  dst[j] = ssrc[j * data_linesize + i];
298  av_fft_permute(p->fft, dst);
299  av_fft_calc(p->fft, dst);
300  memcpy(bdst, dst, block * sizeof(FFTComplex));
301 
302  dst += data_linesize;
303  bdst += buffer_linesize;
304  }
305  }
306  }
307 }
308 
310  uint8_t *dstp, int dst_linesize,
311  float *buffer, int buffer_linesize, int plane)
312 {
313  PlaneContext *p = &s->planes[plane];
314  const int depth = s->depth;
315  const int bpp = (depth + 7) / 8;
316  const int width = p->planewidth;
317  const int height = p->planeheight;
318  const int block = p->b;
319  const int overlap = p->o;
320  const int hoverlap = overlap / 2;
321  const int size = block - overlap;
322  const int nox = p->nox;
323  const int noy = p->noy;
324  const int data_linesize = p->data_linesize / sizeof(FFTComplex);
325  const float scale = 1.f / (block * block);
326  FFTComplex *hdata = p->hdata;
327  FFTComplex *vdata = p->vdata;
328  int x, y, i, j;
329 
330  buffer_linesize /= sizeof(float);
331  for (y = 0; y < noy; y++) {
332  for (x = 0; x < nox; x++) {
333  const int woff = x == 0 ? 0 : hoverlap;
334  const int hoff = y == 0 ? 0 : hoverlap;
335  const int rw = x == 0 ? block : FFMIN(size, width - x * size - woff);
336  const int rh = y == 0 ? block : FFMIN(size, height - y * size - hoff);
337  float *bsrc = buffer + buffer_linesize * y * block + x * block * 2;
338  uint8_t *dst = dstp + dst_linesize * (y * size + hoff) + (x * size + woff) * bpp;
339  FFTComplex *hdst, *ddst = vdata;
340 
341  hdst = hdata;
342  for (i = 0; i < block; i++) {
343  memcpy(ddst, bsrc, block * sizeof(FFTComplex));
344  av_fft_permute(p->ifft, ddst);
345  av_fft_calc(p->ifft, ddst);
346  for (j = 0; j < block; j++) {
347  hdst[j * data_linesize + i] = ddst[j];
348  }
349 
350  ddst += data_linesize;
351  bsrc += buffer_linesize;
352  }
353 
354  hdst = hdata + hoff * data_linesize;
355  for (i = 0; i < rh; i++) {
356  av_fft_permute(p->ifft, hdst);
357  av_fft_calc(p->ifft, hdst);
358  s->export_row(hdst + woff, dst, rw, scale, depth);
359 
360  hdst += data_linesize;
361  dst += dst_linesize;
362  }
363  }
364  }
365 }
366 
367 static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
368 {
369  PlaneContext *p = &s->planes[plane];
370  const int block = p->b;
371  const int nox = p->nox;
372  const int noy = p->noy;
373  const int buffer_linesize = p->buffer_linesize / sizeof(float);
374  const float sigma = s->sigma * s->sigma * block * block;
375  const float limit = 1.f - s->amount;
376  float *cbuffer = p->buffer[CURRENT];
377  const float cfactor = sqrtf(3.f) * 0.5f;
378  const float scale = 1.f / 3.f;
379  int y, x, i, j;
380 
381  for (y = 0; y < noy; y++) {
382  for (x = 0; x < nox; x++) {
383  float *cbuff = cbuffer + buffer_linesize * y * block + x * block * 2;
384  float *pbuff = pbuffer + buffer_linesize * y * block + x * block * 2;
385  float *nbuff = nbuffer + buffer_linesize * y * block + x * block * 2;
386 
387  for (i = 0; i < block; i++) {
388  for (j = 0; j < block; j++) {
389  float sumr, sumi, difr, difi, mpr, mpi, mnr, mni;
390  float factor, power, sumpnr, sumpni;
391 
392  sumpnr = pbuff[2 * j ] + nbuff[2 * j ];
393  sumpni = pbuff[2 * j + 1] + nbuff[2 * j + 1];
394  sumr = cbuff[2 * j ] + sumpnr;
395  sumi = cbuff[2 * j + 1] + sumpni;
396  difr = cfactor * (nbuff[2 * j ] - pbuff[2 * j ]);
397  difi = cfactor * (pbuff[2 * j + 1] - nbuff[2 * j + 1]);
398  mpr = cbuff[2 * j ] - 0.5f * sumpnr + difi;
399  mnr = mpr - difi - difi;
400  mpi = cbuff[2 * j + 1] - 0.5f * sumpni + difr;
401  mni = mpi - difr - difr;
402  power = sumr * sumr + sumi * sumi + 1e-15f;
403  factor = FFMAX((power - sigma) / power, limit);
404  sumr *= factor;
405  sumi *= factor;
406  power = mpr * mpr + mpi * mpi + 1e-15f;
407  factor = FFMAX((power - sigma) / power, limit);
408  mpr *= factor;
409  mpi *= factor;
410  power = mnr * mnr + mni * mni + 1e-15f;
411  factor = FFMAX((power - sigma) / power, limit);
412  mnr *= factor;
413  mni *= factor;
414  cbuff[2 * j ] = (sumr + mpr + mnr) * scale;
415  cbuff[2 * j + 1] = (sumi + mpi + mni) * scale;
416 
417  }
418 
419  cbuff += buffer_linesize;
420  pbuff += buffer_linesize;
421  nbuff += buffer_linesize;
422  }
423  }
424  }
425 }
426 
427 static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
428 {
429  PlaneContext *p = &s->planes[plane];
430  const int block = p->b;
431  const int nox = p->nox;
432  const int noy = p->noy;
433  const int buffer_linesize = p->buffer_linesize / sizeof(float);
434  const float sigma = s->sigma * s->sigma * block * block;
435  const float limit = 1.f - s->amount;
436  float *cbuffer = p->buffer[CURRENT];
437  int y, x, i, j;
438 
439  for (y = 0; y < noy; y++) {
440  for (x = 0; x < nox; x++) {
441  float *cbuff = cbuffer + buffer_linesize * y * block + x * block * 2;
442  float *pbuff = pbuffer + buffer_linesize * y * block + x * block * 2;
443 
444  for (i = 0; i < block; i++) {
445  for (j = 0; j < block; j++) {
446  float factor, power, re, im, pre, pim;
447  float sumr, sumi, difr, difi;
448 
449  re = cbuff[j * 2 ];
450  pre = pbuff[j * 2 ];
451  im = cbuff[j * 2 + 1];
452  pim = pbuff[j * 2 + 1];
453 
454  sumr = re + pre;
455  sumi = im + pim;
456  difr = re - pre;
457  difi = im - pim;
458 
459  power = sumr * sumr + sumi * sumi + 1e-15f;
460  factor = FFMAX(limit, (power - sigma) / power);
461  sumr *= factor;
462  sumi *= factor;
463  power = difr * difr + difi * difi + 1e-15f;
464  factor = FFMAX(limit, (power - sigma) / power);
465  difr *= factor;
466  difi *= factor;
467 
468  cbuff[j * 2 ] = (sumr + difr) * 0.5f;
469  cbuff[j * 2 + 1] = (sumi + difi) * 0.5f;
470  }
471 
472  cbuff += buffer_linesize;
473  pbuff += buffer_linesize;
474  }
475  }
476  }
477 }
478 
480 {
481  PlaneContext *p = &s->planes[plane];
482  const int block = p->b;
483  const int nox = p->nox;
484  const int noy = p->noy;
485  const int buffer_linesize = p->buffer_linesize / 4;
486  const float sigma = s->sigma * s->sigma * block * block;
487  const float limit = 1.f - s->amount;
488  float *buffer = p->buffer[CURRENT];
489  int y, x, i, j;
490 
491  for (y = 0; y < noy; y++) {
492  for (x = 0; x < nox; x++) {
493  float *buff = buffer + buffer_linesize * y * block + x * block * 2;
494 
495  for (i = 0; i < block; i++) {
496  for (j = 0; j < block; j++) {
497  float factor, power, re, im;
498 
499  re = buff[j * 2 ];
500  im = buff[j * 2 + 1];
501  power = re * re + im * im + 1e-15f;
502  factor = FFMAX(limit, (power - sigma) / power);
503  buff[j * 2 ] *= factor;
504  buff[j * 2 + 1] *= factor;
505  }
506 
507  buff += buffer_linesize;
508  }
509  }
510  }
511 }
512 
513 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
514 {
515  AVFilterContext *ctx = inlink->dst;
516  FFTdnoizContext *s = ctx->priv;
517  AVFilterLink *outlink = ctx->outputs[0];
518  int direct, plane;
519  AVFrame *out;
520 
521  if (s->nb_next > 0 && s->nb_prev > 0) {
522  av_frame_free(&s->prev);
523  s->prev = s->cur;
524  s->cur = s->next;
525  s->next = in;
526 
527  if (!s->prev && s->cur) {
528  s->prev = av_frame_clone(s->cur);
529  if (!s->prev)
530  return AVERROR(ENOMEM);
531  }
532  if (!s->cur)
533  return 0;
534  } else if (s->nb_next > 0) {
535  av_frame_free(&s->cur);
536  s->cur = s->next;
537  s->next = in;
538 
539  if (!s->cur)
540  return 0;
541  } else if (s->nb_prev > 0) {
542  av_frame_free(&s->prev);
543  s->prev = s->cur;
544  s->cur = in;
545 
546  if (!s->prev)
547  s->prev = av_frame_clone(s->cur);
548  if (!s->prev)
549  return AVERROR(ENOMEM);
550  } else {
551  s->cur = in;
552  }
553 
554  if (av_frame_is_writable(in) && s->nb_next == 0 && s->nb_prev == 0) {
555  direct = 1;
556  out = in;
557  } else {
558  direct = 0;
559  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
560  if (!out)
561  return AVERROR(ENOMEM);
562  av_frame_copy_props(out, s->cur);
563  }
564 
565  for (plane = 0; plane < s->nb_planes; plane++) {
566  PlaneContext *p = &s->planes[plane];
567 
568  if (!((1 << plane) & s->planesf) || ctx->is_disabled) {
569  if (!direct)
570  av_image_copy_plane(out->data[plane], out->linesize[plane],
571  s->cur->data[plane], s->cur->linesize[plane],
572  p->planewidth, p->planeheight);
573  continue;
574  }
575 
576  if (s->next) {
577  import_plane(s, s->next->data[plane], s->next->linesize[plane],
578  p->buffer[NEXT], p->buffer_linesize, plane);
579  }
580 
581  if (s->prev) {
582  import_plane(s, s->prev->data[plane], s->prev->linesize[plane],
583  p->buffer[PREV], p->buffer_linesize, plane);
584  }
585 
586  import_plane(s, s->cur->data[plane], s->cur->linesize[plane],
587  p->buffer[CURRENT], p->buffer_linesize, plane);
588 
589  if (s->next && s->prev) {
590  filter_plane3d2(s, plane, p->buffer[PREV], p->buffer[NEXT]);
591  } else if (s->next) {
592  filter_plane3d1(s, plane, p->buffer[NEXT]);
593  } else if (s->prev) {
594  filter_plane3d1(s, plane, p->buffer[PREV]);
595  } else {
596  filter_plane2d(s, plane);
597  }
598 
599  export_plane(s, out->data[plane], out->linesize[plane],
600  p->buffer[CURRENT], p->buffer_linesize, plane);
601  }
602 
603  if (s->nb_next == 0 && s->nb_prev == 0) {
604  if (direct) {
605  s->cur = NULL;
606  } else {
607  av_frame_free(&s->cur);
608  }
609  }
610  return ff_filter_frame(outlink, out);
611 }
612 
613 static int request_frame(AVFilterLink *outlink)
614 {
615  AVFilterContext *ctx = outlink->src;
616  FFTdnoizContext *s = ctx->priv;
617  int ret = 0;
618 
619  ret = ff_request_frame(ctx->inputs[0]);
620 
621  if (ret == AVERROR_EOF && (s->nb_next > 0)) {
622  AVFrame *buf;
623 
624  if (s->next && s->nb_next > 0)
625  buf = av_frame_clone(s->next);
626  else if (s->cur)
627  buf = av_frame_clone(s->cur);
628  else
629  buf = av_frame_clone(s->prev);
630  if (!buf)
631  return AVERROR(ENOMEM);
632 
633  ret = filter_frame(ctx->inputs[0], buf);
634  if (ret < 0)
635  return ret;
636  ret = AVERROR_EOF;
637  }
638 
639  return ret;
640 }
641 
643 {
644  FFTdnoizContext *s = ctx->priv;
645  int i;
646 
647  for (i = 0; i < 4; i++) {
648  PlaneContext *p = &s->planes[i];
649 
650  av_freep(&p->hdata);
651  av_freep(&p->vdata);
652  av_freep(&p->buffer[PREV]);
653  av_freep(&p->buffer[CURRENT]);
654  av_freep(&p->buffer[NEXT]);
655  av_fft_end(p->fft);
656  av_fft_end(p->ifft);
657  }
658 
659  av_frame_free(&s->prev);
660  av_frame_free(&s->cur);
661  av_frame_free(&s->next);
662 }
663 
664 static const AVFilterPad fftdnoiz_inputs[] = {
665  {
666  .name = "default",
667  .type = AVMEDIA_TYPE_VIDEO,
668  .filter_frame = filter_frame,
669  .config_props = config_input,
670  },
671  { NULL }
672 };
673 
674 static const AVFilterPad fftdnoiz_outputs[] = {
675  {
676  .name = "default",
677  .type = AVMEDIA_TYPE_VIDEO,
678  .request_frame = request_frame,
679  },
680  { NULL }
681 };
682 
684  .name = "fftdnoiz",
685  .description = NULL_IF_CONFIG_SMALL("Denoise frames using 3D FFT."),
686  .priv_size = sizeof(FFTdnoizContext),
687  .init = init,
688  .uninit = uninit,
690  .inputs = fftdnoiz_inputs,
691  .outputs = fftdnoiz_outputs,
692  .priv_class = &fftdnoiz_class,
694 };
int plane
Definition: avisynth_c.h:422
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:381
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
AVOption.
Definition: opt.h:246
static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
Definition: vf_fftdnoiz.c:144
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:389
av_cold void av_fft_end(FFTContext *s)
Definition: avfft.c:48
float re
Definition: fft.c:82
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2486
const char * desc
Definition: nvenc.c:65
static int request_frame(AVFilterLink *outlink)
Definition: vf_fftdnoiz.c:613
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:395
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:359
FFTSample re
Definition: avfft.h:38
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:383
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:38
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
#define src
Definition: vp8dsp.c:254
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVFrame * next
Definition: vf_fftdnoiz.c:62
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:360
static int16_t block[64]
Definition: dct.c:115
BYTE int const BYTE * srcp
Definition: avisynth_c.h:813
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:361
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
static void export_plane(FFTdnoizContext *s, uint8_t *dstp, int dst_linesize, float *buffer, int buffer_linesize, int plane)
Definition: vf_fftdnoiz.c:309
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
AVFilter ff_vf_fftdnoiz
Definition: vf_fftdnoiz.c:683
#define f(width, name)
Definition: cbs_vp9.c:255
static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
Definition: vf_fftdnoiz.c:162
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:394
#define height
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:392
ptrdiff_t size
Definition: opengl_enc.c:101
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:384
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
static void import_plane(FFTdnoizContext *s, uint8_t *srcp, int src_linesize, float *buffer, int buffer_linesize, int plane)
Definition: vf_fftdnoiz.c:245
float * buffer[BSIZE]
Definition: vf_fftdnoiz.c:43
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:568
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
BYTE * dstp
Definition: avisynth_c.h:813
#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:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
FFTComplex * hdata
Definition: vf_fftdnoiz.c:44
static av_cold int init(AVFilterContext *ctx)
Definition: vf_fftdnoiz.c:94
PlaneContext planes[4]
Definition: vf_fftdnoiz.c:66
simple assert() macros that are a bit more flexible than ISO C assert().
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:28
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:382
#define FFMAX(a, b)
Definition: common.h:94
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
FFTComplex * vdata
Definition: vf_fftdnoiz.c:44
static const AVOption fftdnoiz_options[]
Definition: vf_fftdnoiz.c:74
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:377
FFTContext * ifft
Definition: vf_fftdnoiz.c:48
Definition: fft.h:88
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:398
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:363
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define width
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
Definition: vf_fftdnoiz.c:367
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:378
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:397
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:390
BufferTypes
Definition: vf_fftdnoiz.c:29
AVFrame * dst
Definition: vf_blend.c:55
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:387
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
static int config_input(AVFilterLink *inlink)
Definition: vf_fftdnoiz.c:182
Used for passing data between threads.
Definition: af_adeclick.c:484
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
Definition: vf_fftdnoiz.c:173
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
FFT functions.
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:362
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
void * buf
Definition: avisynth_c.h:690
#define FLAGS
Definition: vf_fftdnoiz.c:73
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:379
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
int buffer_linesize
Definition: vf_fftdnoiz.c:46
float im
Definition: fft.c:82
#define OFFSET(x)
Definition: vf_fftdnoiz.c:72
static const int factor[16]
Definition: vf_pp7.c:75
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:385
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:376
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_fftdnoiz.c:513
#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:133
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static const AVFilterPad fftdnoiz_inputs[]
Definition: vf_fftdnoiz.c:664
void(* import_row)(FFTComplex *dst, uint8_t *src, int rw)
Definition: vf_fftdnoiz.c:68
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:388
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:396
#define flags(name, subs,...)
Definition: cbs_av1.c:596
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:386
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
FFTSample im
Definition: avfft.h:38
common internal and external API header
static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
Definition: vf_fftdnoiz.c:427
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_fftdnoiz.c:642
void(* export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
Definition: vf_fftdnoiz.c:69
int data_linesize
Definition: vf_fftdnoiz.c:45
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
AVFrame * prev
Definition: vf_fftdnoiz.c:62
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
const uint8_t * src
Definition: vf_bm3d.c:56
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:258
static int query_formats(AVFilterContext *ctx)
Definition: vf_fftdnoiz.c:111
static const AVFilterPad fftdnoiz_outputs[]
Definition: vf_fftdnoiz.c:674
An instance of a filter.
Definition: avfilter.h:338
static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
Definition: vf_fftdnoiz.c:154
FILE * out
Definition: movenc.c:54
AVFILTER_DEFINE_CLASS(fftdnoiz)
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
static const uint8_t block_bits[]
Definition: imm4.c:107
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:407
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:338
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
Definition: avfft.c:43
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVFrame * cur
Definition: vf_fftdnoiz.c:62
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:391
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
static void filter_plane2d(FFTdnoizContext *s, int plane)
Definition: vf_fftdnoiz.c:479
GLuint buffer
Definition: opengl_enc.c:102
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
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:229
FFTContext * fft
Definition: vf_fftdnoiz.c:48