87#define OFFSET(x) offsetof(FFTdnoizContext, x)
88#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
89#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
91 {
"sigma",
"set denoise strength",
93 {
"amount",
"set amount of denoising",
95 {
"block",
"set block size",
97 {
"overlap",
"set block overlap",
99 {
"method",
"set method of denoising",
101 {
"wiener",
"wiener method",
103 {
"hard",
"hard thresholding",
105 {
"prev",
"set number of previous frames for temporal denoising",
107 {
"next",
"set number of next frames for temporal denoising",
109 {
"planes",
"set planes to filter",
151 for (
int j = 0; j < rw; j++) {
152 const int i =
abs(j + off);
160 for (
int j = 0; j < rw; j++)
167 uint16_t *
src = (uint16_t *)srcp;
169 for (
int j = 0; j < rw; j++) {
170 const int i =
abs(j + off);
178 uint16_t *
dst = (uint16_t *)dstp;
180 for (
int j = 0; j < rw; j++)
194 s->depth =
desc->comp[0].depth;
205 s->planes[0].planewidth =
s->planes[3].planewidth = inlink->
w;
206 s->planes[1].planeheight =
s->planes[2].planeheight =
AV_CEIL_RSHIFT(inlink->
h,
desc->log2_chroma_h);
207 s->planes[0].planeheight =
s->planes[3].planeheight = inlink->
h;
212 for (
int i = 0;
i <
s->nb_threads;
i++) {
213 float scale = 1.f, iscale = 1.f;
217 0,
s->block_size, &
scale, 0)) < 0 ||
219 1,
s->block_size, &iscale, 0)) < 0 ||
221 0, 1 +
s->nb_prev +
s->nb_next, &
scale, 0)) < 0 ||
223 1, 1 +
s->nb_prev +
s->nb_next, &iscale, 0)) < 0)
227 for (
i = 0;
i <
s->nb_planes;
i++) {
231 p->b =
s->block_size;
232 p->n = 1.f / (p->b * p->b);
233 p->o =
lrintf(p->b *
s->overlap);
235 p->nox = (p->planewidth + (
size - 1)) /
size;
236 p->noy = (p->planeheight + (
size - 1)) /
size;
241 p->data_linesize = 2 * p->b *
sizeof(
float);
242 for (
int j = 0; j <
s->nb_threads; j++) {
243 p->hdata[j] =
av_calloc(p->b, p->data_linesize);
244 p->hdata_out[j] =
av_calloc(p->b, p->data_linesize);
245 p->vdata[j] =
av_calloc(p->b, p->data_linesize);
246 p->vdata_out[j] =
av_calloc(p->b, p->data_linesize);
250 if (
s->nb_prev > 0) {
252 if (!p->buffer[j][
PREV])
255 if (
s->nb_next > 0) {
257 if (!p->buffer[j][
NEXT])
260 if (!p->hdata[j] || !p->vdata[j] ||
261 !p->hdata_out[j] || !p->vdata_out[j])
268 for (
int y = 0; y <
s->block_size; y++) {
269 for (
int x = 0; x <
s->block_size; x++)
270 s->win[y][x] = lut[y] * lut[x];
277 uint8_t *srcp,
int src_linesize,
278 float *
buffer,
int buffer_linesize,
int plane,
279 int jobnr,
int y,
int x)
282 const int width = p->planewidth;
283 const int height = p->planeheight;
284 const int block = p->b;
285 const int overlap = p->o;
286 const int hoverlap = overlap / 2;
288 const int bpp = (
s->depth + 7) / 8;
289 const int data_linesize = p->data_linesize /
sizeof(
AVComplexFloat);
290 const float scale = 1.f / ((1.f +
s->nb_prev +
s->nb_next) *
s->block_size *
s->block_size);
294 const int woff = -hoverlap;
295 const int hoff = -hoverlap;
301 buffer_linesize /=
sizeof(
float);
303 for (
int i = 0;
i < rh;
i++) {
304 uint8_t *
src = srcp + src_linesize *
abs(y *
size +
i + hoff) + x *
size * bpp;
307 for (
int j = rw; j <
block; j++) {
308 dst[j].re =
dst[rw - 1].re;
314 dst += data_linesize;
315 dst_out += data_linesize;
320 for (
int j = 0; j <
block; j++) {
321 dst[j].re = ddst[j].
re;
322 dst[j].im = ddst[j].
im;
325 dst += data_linesize;
331 for (
int j = 0; j <
block; j++)
332 dst[j] = ssrc[j * data_linesize +
i];
335 dst += data_linesize;
336 bdst += buffer_linesize;
341 uint8_t *dstp,
int dst_linesize,
342 float *
buffer,
int buffer_linesize,
int plane,
343 int jobnr,
int y,
int x)
346 const int depth =
s->depth;
347 const int bpp = (depth + 7) / 8;
348 const int width = p->planewidth;
349 const int height = p->planeheight;
350 const int block = p->b;
351 const int overlap = p->o;
352 const int hoverlap = overlap / 2;
354 const int data_linesize = p->data_linesize /
sizeof(
AVComplexFloat);
364 buffer_linesize /=
sizeof(
float);
368 for (
int j = 0; j <
block; j++)
369 hdst[j * data_linesize +
i] = vdst[j];
371 vdst += data_linesize;
372 bsrc += buffer_linesize;
375 hdst = hdata + hoverlap * data_linesize;
377 uint8_t *
dst = dstp + dst_linesize * (y *
size +
i) + x *
size * bpp;
380 s->export_row(hdst_out + hoverlap,
dst, rw, depth,
s->win[
i + hoverlap] + hoverlap);
382 hdst += data_linesize;
383 hdst_out += data_linesize;
391 const int block = p->b;
392 const int buffer_linesize = p->buffer_linesize /
sizeof(
float);
393 const float depthx = (1 << (
s->depth - 8)) * (1 << (
s->depth - 8));
394 const float sigma =
s->sigma * depthx / (3.f *
s->block_size *
s->block_size);
395 const float limit = 1.f -
s->amount;
396 float *cbuffer = p->buffer[jobnr][
CURRENT];
397 const int method =
s->method;
398 float *cbuff = cbuffer;
399 float *pbuff = pbuffer;
400 float *nbuff = nbuffer;
403 for (
int j = 0; j <
block; j++) {
407 buffer[0].re = pbuff[2 * j ];
408 buffer[0].im = pbuff[2 * j + 1];
410 buffer[1].re = cbuff[2 * j ];
411 buffer[1].im = cbuff[2 * j + 1];
413 buffer[2].re = nbuff[2 * j ];
414 buffer[2].im = nbuff[2 * j + 1];
418 for (
int z = 0; z < 3; z++) {
419 const float re = outbuffer[z].
re;
420 const float im = outbuffer[z].
im;
421 const float power = re * re + im * im;
439 cbuff[2 * j + 0] =
buffer[1].re;
440 cbuff[2 * j + 1] =
buffer[1].im;
443 cbuff += buffer_linesize;
444 pbuff += buffer_linesize;
445 nbuff += buffer_linesize;
453 const int block = p->b;
454 const int buffer_linesize = p->buffer_linesize /
sizeof(
float);
455 const float depthx = (1 << (
s->depth - 8)) * (1 << (
s->depth - 8));
456 const float sigma =
s->sigma * depthx / (2.f *
s->block_size *
s->block_size);
457 const float limit = 1.f -
s->amount;
458 float *cbuffer = p->buffer[jobnr][
CURRENT];
459 const int method =
s->method;
460 float *cbuff = cbuffer;
461 float *pbuff = pbuffer;
464 for (
int j = 0; j <
block; j++) {
468 buffer[0].re = pbuff[2 * j ];
469 buffer[0].im = pbuff[2 * j + 1];
471 buffer[1].re = cbuff[2 * j ];
472 buffer[1].im = cbuff[2 * j + 1];
476 for (
int z = 0; z < 2; z++) {
477 const float re = outbuffer[z].
re;
478 const float im = outbuffer[z].
im;
479 const float power = re * re + im * im;
497 cbuff[2 * j + 0] =
buffer[1].re;
498 cbuff[2 * j + 1] =
buffer[1].im;
501 cbuff += buffer_linesize;
502 pbuff += buffer_linesize;
510 const int block = p->b;
511 const int method =
s->method;
512 const int buffer_linesize = p->buffer_linesize /
sizeof(
float);
513 const float depthx = (1 << (
s->depth - 8)) * (1 << (
s->depth - 8));
514 const float sigma =
s->sigma * depthx / (
s->block_size *
s->block_size);
515 const float limit = 1.f -
s->amount;
516 float *buff = p->buffer[jobnr][
CURRENT];
519 for (
int j = 0; j <
block; j++) {
523 im = buff[j * 2 + 1];
524 power = re * re + im * im;
535 buff[j * 2 + 1] *=
factor;
538 buff += buffer_linesize;
543 int jobnr,
int nb_jobs)
548 for (
int plane = 0; plane <
s->nb_planes; plane++) {
550 const int nox = p->nox;
551 const int noy = p->noy;
555 if (!((1 << plane) &
s->planesf) ||
ctx->is_disabled)
559 for (
int x = 0; x < nox; x++) {
562 p->buffer[jobnr][
NEXT], p->buffer_linesize, plane,
568 p->buffer[jobnr][
PREV], p->buffer_linesize, plane,
573 p->buffer[jobnr][
CURRENT], p->buffer_linesize, plane,
576 if (
s->next &&
s->prev) {
578 }
else if (
s->next) {
580 }
else if (
s->prev) {
587 p->buffer[jobnr][
CURRENT], p->buffer_linesize, plane,
604 if (
s->nb_next > 0 &&
s->nb_prev > 0) {
610 if (!
s->prev &&
s->cur) {
617 }
else if (
s->nb_next > 0) {
624 }
else if (
s->nb_prev > 0) {
649 FFMIN(
s->planes[0].noy,
s->nb_threads));
651 for (plane = 0; plane <
s->nb_planes; plane++) {
654 if (!((1 << plane) &
s->planesf) ||
ctx->is_disabled) {
657 s->cur->data[plane],
s->cur->linesize[plane],
658 p->planewidth * (1 + (
s->depth > 8)), p->planeheight);
663 if (
s->nb_next == 0 &&
s->nb_prev == 0) {
684 if (
s->next &&
s->nb_next > 0)
707 for (
i = 0;
i < 4;
i++) {
710 for (
int j = 0; j <
s->nb_threads; j++) {
721 for (
i = 0;
i <
s->nb_threads;
i++) {
751 .p.name =
"fftdnoiz",
753 .p.priv_class = &fftdnoiz_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_input(AVFilterLink *inlink)
static int request_frame(AVFilterLink *outlink)
static float win(SuperEqualizerContext *s, float n, int N)
const FFFilter ff_vf_fftdnoiz
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
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.
float fmaxf(float, float)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
static SDL_Window * window
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVERROR_EOF
End of file.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
static const int factor[16]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
static float power(float r, float g, float b, float max)
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVTXContext * fft[MAX_THREADS]
AVTXContext * ifft[MAX_THREADS]
void(* export_row)(AVComplexFloat *src, uint8_t *dst, int rw, int depth, float *win)
AVTXContext * fft_r[MAX_THREADS]
float win[MAX_BLOCK][MAX_BLOCK]
AVTXContext * ifft_r[MAX_THREADS]
void(* import_row)(AVComplexFloat *dst, uint8_t *src, int rw, float scale, float *win, int off)
AVComplexFloat * hdata[MAX_THREADS]
AVComplexFloat * vdata_out[MAX_THREADS]
AVComplexFloat * hdata_out[MAX_THREADS]
float * buffer[MAX_THREADS][BSIZE]
AVComplexFloat * vdata[MAX_THREADS]
Used for passing data between threads.
static AVFormatContext * ctx
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static const AVOption fftdnoiz_options[]
static void filter_block3d1(FFTdnoizContext *s, int plane, float *pbuffer, int jobnr)
static void import_row8(AVComplexFloat *dst, uint8_t *src, int rw, float scale, float *win, int off)
static void export_block(FFTdnoizContext *s, uint8_t *dstp, int dst_linesize, float *buffer, int buffer_linesize, int plane, int jobnr, int y, int x)
static int config_input(AVFilterLink *inlink)
static void export_row8(AVComplexFloat *src, uint8_t *dst, int rw, int depth, float *win)
static int request_frame(AVFilterLink *outlink)
static const AVFilterPad fftdnoiz_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void filter_block3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer, int jobnr)
static void import_block(FFTdnoizContext *s, uint8_t *srcp, int src_linesize, float *buffer, int buffer_linesize, int plane, int jobnr, int y, int x)
static av_cold void uninit(AVFilterContext *ctx)
static void export_row16(AVComplexFloat *src, uint8_t *dstp, int rw, int depth, float *win)
static const AVFilterPad fftdnoiz_inputs[]
static void import_row16(AVComplexFloat *dst, uint8_t *srcp, int rw, float scale, float *win, int off)
static void filter_block2d(FFTdnoizContext *s, int plane, int jobnr)
static double limit(double x)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
static void generate_window_func(float *lut, int N, int win_func, float *overlap)