Go to the documentation of this file.
   31 #define MAX_THREADS 32 
   85 #define OFFSET(x) offsetof(FFTdnoizContext, x) 
   86 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 
   87 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM 
   89     { 
"sigma",   
"set denoise strength",
 
   91     { 
"amount",  
"set amount of denoising",
 
   93     { 
"block",   
"set block size",
 
   95     { 
"overlap", 
"set block overlap",
 
   97     { 
"method",  
"set method of denoising",
 
   99     { 
"wiener", 
"wiener method",
 
  101     { 
"hard",   
"hard thresholding",
 
  103     { 
"prev",    
"set number of previous frames for temporal denoising",
 
  105     { 
"next",    
"set number of next frames for temporal denoising",
 
  107     { 
"planes",  
"set planes to filter",
 
  149     for (
int j = 0; j < rw; j++) {
 
  150         const int i = 
abs(j + off);
 
  158     for (
int j = 0; j < rw; j++)
 
  165     uint16_t *
src = (uint16_t *)srcp;
 
  167     for (
int j = 0; j < rw; j++) {
 
  168         const int i = 
abs(j + off);
 
  176     uint16_t *dst = (uint16_t *)dstp;
 
  178     for (
int j = 0; j < rw; j++)
 
  192     s->depth = 
desc->comp[0].depth;
 
  203     s->planes[0].planewidth = 
s->planes[3].planewidth = 
inlink->w;
 
  205     s->planes[0].planeheight = 
s->planes[3].planeheight = 
inlink->h;
 
  210     for (
int i = 0; 
i < 
s->nb_threads; 
i++) {
 
  211         float scale = 1.f, iscale = 1.f;
 
  215                               0, 
s->block_size,               &
scale,  0)) < 0 ||
 
  217                               1, 
s->block_size,               &iscale, 0)) < 0 ||
 
  219                               0, 1 + 
s->nb_prev + 
s->nb_next, &
scale,  0)) < 0 ||
 
  221                               1, 1 + 
s->nb_prev + 
s->nb_next, &iscale, 0)) < 0)
 
  225     for (
i = 0; 
i < 
s->nb_planes; 
i++) {
 
  229         p->
b = 
s->block_size;
 
  230         p->
n = 1.f / (p->
b * p->
b);
 
  240         for (
int j = 0; j < 
s->nb_threads; j++) {
 
  248             if (
s->nb_prev > 0) {
 
  253             if (
s->nb_next > 0) {
 
  266     for (
int y = 0; y < 
s->block_size; y++) {
 
  267         for (
int x = 0; x < 
s->block_size; x++)
 
  268             s->win[y][x] = lut[y] * lut[x];
 
  275                          uint8_t *srcp, 
int src_linesize,
 
  276                          float *
buffer, 
int buffer_linesize, 
int plane,
 
  277                          int jobnr, 
int y, 
int x)
 
  283     const int overlap = p->
o;
 
  284     const int hoverlap = overlap / 2;
 
  286     const int bpp = (
s->depth + 7) / 8;
 
  288     const float scale = 1.f / ((1.f + 
s->nb_prev + 
s->nb_next) * 
s->block_size * 
s->block_size);
 
  292     const int woff = -hoverlap;
 
  293     const int hoff = -hoverlap;
 
  299     buffer_linesize /= 
sizeof(
float);
 
  301     for (
int i = 0; 
i < rh; 
i++) {
 
  302         uint8_t *
src = srcp + src_linesize * 
abs(y * 
size + 
i + hoff) + x * 
size * bpp;
 
  304         s->import_row(dst, 
src, rw, 
scale, 
s->win[
i], woff);
 
  305         for (
int j = rw; j < 
block; j++) {
 
  306             dst[j].
re = dst[rw - 1].
re;
 
  312         dst += data_linesize;
 
  313         dst_out += data_linesize;
 
  318         for (
int j = 0; j < 
block; j++) {
 
  319             dst[j].
re = ddst[j].
re;
 
  320             dst[j].
im = ddst[j].
im;
 
  323         dst += data_linesize;
 
  329         for (
int j = 0; j < 
block; j++)
 
  330             dst[j] = ssrc[j * data_linesize + 
i];
 
  333         dst += data_linesize;
 
  334         bdst += buffer_linesize;
 
  339                          uint8_t *dstp, 
int dst_linesize,
 
  340                          float *
buffer, 
int buffer_linesize, 
int plane,
 
  341                          int jobnr, 
int y, 
int x)
 
  344     const int depth = 
s->depth;
 
  345     const int bpp = (depth + 7) / 8;
 
  349     const int overlap = p->
o;
 
  350     const int hoverlap = overlap / 2;
 
  362     buffer_linesize /= 
sizeof(
float);
 
  366         for (
int j = 0; j < 
block; j++)
 
  367             hdst[j * data_linesize + 
i] = vdst[j];
 
  369         vdst += data_linesize;
 
  370         bsrc += buffer_linesize;
 
  373     hdst = hdata + hoverlap * data_linesize;
 
  375         uint8_t *dst = dstp + dst_linesize * (y * 
size + 
i) + x * 
size * bpp;
 
  378         s->export_row(hdst_out + hoverlap, dst, rw, depth, 
s->win[
i + hoverlap] + hoverlap);
 
  380         hdst += data_linesize;
 
  381         hdst_out += data_linesize;
 
  391     const float depthx = (1 << (
s->depth - 8)) * (1 << (
s->depth - 8));
 
  392     const float sigma = 
s->sigma * depthx / (3.f * 
s->block_size * 
s->block_size);
 
  393     const float limit = 1.f - 
s->amount;
 
  395     const int method = 
s->method;
 
  396     float *cbuff = cbuffer;
 
  397     float *pbuff = pbuffer;
 
  398     float *nbuff = nbuffer;
 
  401         for (
int j = 0; j < 
block; j++) {
 
  405             buffer[0].re = pbuff[2 * j    ];
 
  406             buffer[0].im = pbuff[2 * j + 1];
 
  408             buffer[1].re = cbuff[2 * j    ];
 
  409             buffer[1].im = cbuff[2 * j + 1];
 
  411             buffer[2].re = nbuff[2 * j    ];
 
  412             buffer[2].im = nbuff[2 * j + 1];
 
  416             for (
int z = 0; z < 3; z++) {
 
  417                 const float re = outbuffer[z].
re;
 
  418                 const float im = outbuffer[z].
im;
 
  419                 const float power = re * re + im * im;
 
  437             cbuff[2 * j + 0] = 
buffer[1].re;
 
  438             cbuff[2 * j + 1] = 
buffer[1].im;
 
  441         cbuff += buffer_linesize;
 
  442         pbuff += buffer_linesize;
 
  443         nbuff += buffer_linesize;
 
  453     const float depthx = (1 << (
s->depth - 8)) * (1 << (
s->depth - 8));
 
  454     const float sigma = 
s->sigma * depthx / (2.f * 
s->block_size * 
s->block_size);
 
  455     const float limit = 1.f - 
s->amount;
 
  457     const int method = 
s->method;
 
  458     float *cbuff = cbuffer;
 
  459     float *pbuff = pbuffer;
 
  462         for (
int j = 0; j < 
block; j++) {
 
  466             buffer[0].re = pbuff[2 * j    ];
 
  467             buffer[0].im = pbuff[2 * j + 1];
 
  469             buffer[1].re = cbuff[2 * j    ];
 
  470             buffer[1].im = cbuff[2 * j + 1];
 
  474             for (
int z = 0; z < 2; z++) {
 
  475                 const float re = outbuffer[z].
re;
 
  476                 const float im = outbuffer[z].
im;
 
  477                 const float power = re * re + im * im;
 
  495             cbuff[2 * j + 0] = 
buffer[1].re;
 
  496             cbuff[2 * j + 1] = 
buffer[1].im;
 
  499         cbuff += buffer_linesize;
 
  500         pbuff += buffer_linesize;
 
  509     const int method = 
s->method;
 
  511     const float depthx = (1 << (
s->depth - 8)) * (1 << (
s->depth - 8));
 
  512     const float sigma = 
s->sigma * depthx / (
s->block_size * 
s->block_size);
 
  513     const float limit = 1.f - 
s->amount;
 
  517         for (
int j = 0; j < 
block; j++) {
 
  521             im = buff[j * 2 + 1];
 
  522             power = re * re + im * im;
 
  533             buff[j * 2 + 1] *= 
factor;
 
  536         buff += buffer_linesize;
 
  541                    int jobnr, 
int nb_jobs)
 
  546     for (
int plane = 0; plane < 
s->nb_planes; plane++) {
 
  548         const int nox = p->
nox;
 
  549         const int noy = p->
noy;
 
  551         const int slice_end = (noy * (jobnr+1)) / nb_jobs;
 
  553         if (!((1 << plane) & 
s->planesf) || 
ctx->is_disabled)
 
  557             for (
int x = 0; x < nox; x++) {
 
  574                 if (
s->next && 
s->prev) {
 
  576                 } 
else if (
s->next) {
 
  578                 } 
else  if (
s->prev) {
 
  602     if (
s->nb_next > 0 && 
s->nb_prev > 0) {
 
  608         if (!
s->prev && 
s->cur) {
 
  615     } 
else if (
s->nb_next > 0) {
 
  622     } 
else if (
s->nb_prev > 0) {
 
  647                       FFMIN(
s->planes[0].noy, 
s->nb_threads));
 
  649     for (plane = 0; plane < 
s->nb_planes; plane++) {
 
  652         if (!((1 << plane) & 
s->planesf) || 
ctx->is_disabled) {
 
  655                                     s->cur->data[plane], 
s->cur->linesize[plane],
 
  661     if (
s->nb_next == 0 && 
s->nb_prev == 0) {
 
  682         if (
s->next && 
s->nb_next > 0)
 
  705     for (
i = 0; 
i < 4; 
i++) {
 
  708         for (
int j = 0; j < 
s->nb_threads; j++) {
 
  719     for (
i = 0; 
i < 
s->nb_threads; 
i++) {
 
  756     .priv_class    = &fftdnoiz_class,
 
  
static void filter_block2d(FFTdnoizContext *s, int plane, int jobnr)
 
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
 
#define AV_PIX_FMT_YUVA422P16
 
static int denoise(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
#define AV_PIX_FMT_GBRAP16
 
void(* import_row)(AVComplexFloat *dst, uint8_t *src, int rw, float scale, float *win, int off)
 
AVPixelFormat
Pixel format.
 
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
 
static int request_frame(AVFilterLink *outlink)
 
void(* export_row)(AVComplexFloat *src, uint8_t *dst, int rw, int depth, float *win)
 
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
 
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
 
#define AVERROR_EOF
End of file.
 
float * buffer[MAX_THREADS][BSIZE]
 
#define FILTER_PIXFMTS_ARRAY(array)
 
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
 
static void import_row16(AVComplexFloat *dst, uint8_t *srcp, int rw, float scale, float *win, int off)
 
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
 
#define AV_PIX_FMT_YUVA422P9
 
This structure describes decoded (raw) audio or video data.
 
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.
 
#define AV_PIX_FMT_YUVA420P16
 
#define AV_PIX_FMT_YUVA420P10
 
static const AVFilterPad fftdnoiz_outputs[]
 
AVTXContext * ifft[MAX_THREADS]
 
#define AV_PIX_FMT_YUV420P10
 
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
 
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
 
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
 
const char * name
Filter name.
 
A link between two filters.
 
#define AV_PIX_FMT_YUVA422P10
 
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...
 
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 float win(SuperEqualizerContext *s, float n, int N)
 
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
 
#define AV_PIX_FMT_YUVA420P9
 
static SDL_Window * window
 
#define AV_PIX_FMT_GBRP14
 
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
 
#define AV_PIX_FMT_GBRP10
 
#define AV_PIX_FMT_YUVA444P16
 
#define AV_PIX_FMT_YUV422P9
 
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)
 
#define AV_PIX_FMT_GRAY16
 
A filter pad used for either input or output.
 
#define AV_PIX_FMT_YUV444P10
 
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
 
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
 
AVComplexFloat * vdata[MAX_THREADS]
 
#define AV_PIX_FMT_YUV422P16
 
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
 
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
 
#define AV_PIX_FMT_GBRAP10
 
#define AV_PIX_FMT_GBRAP12
 
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
 
#define AV_PIX_FMT_YUV444P16
 
#define AV_CEIL_RSHIFT(a, b)
 
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
 
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
 
#define AV_PIX_FMT_YUVA444P12
 
#define AV_PIX_FMT_YUV420P9
 
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
 
float win[MAX_BLOCK][MAX_BLOCK]
 
#define AV_PIX_FMT_YUV420P16
 
#define AV_PIX_FMT_GRAY14
 
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
 
static enum AVPixelFormat pix_fmts[]
 
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
 
#define FILTER_INPUTS(array)
 
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
 
#define AV_PIX_FMT_GRAY10
 
AVComplexFloat * hdata[MAX_THREADS]
 
#define AV_PIX_FMT_GBRP16
 
Describe the class of an AVClass context structure.
 
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
 
AVTXContext * fft_r[MAX_THREADS]
 
@ 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_YUV440P10
 
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
 
#define AV_PIX_FMT_YUV422P10
 
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
 
static int config_input(AVFilterLink *inlink)
 
static void filter_block3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer, int jobnr)
 
static void scale(int *out, const int *in, const int w, const int h, const int shift)
 
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
 
float fmaxf(float, float)
 
#define AV_PIX_FMT_YUV422P12
 
#define AV_PIX_FMT_YUV444P12
 
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
 
AVFilterContext * src
source 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.
 
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
 
#define AV_PIX_FMT_YUVA444P10
 
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
 
static void filter_block3d1(FFTdnoizContext *s, int plane, float *pbuffer, int jobnr)
 
AVComplexFloat * vdata_out[MAX_THREADS]
 
#define i(width, name, range_min, range_max)
 
int w
agreed upon image width
 
#define AV_PIX_FMT_GBRP12
 
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
 
Used for passing data between threads.
 
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
 
const char * name
Pad name.
 
void * av_calloc(size_t nmemb, size_t size)
 
#define AV_PIX_FMT_YUV444P9
 
static double limit(double x)
 
static av_cold void uninit(AVFilterContext *ctx)
 
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)
 
AVTXContext * ifft_r[MAX_THREADS]
 
#define AV_PIX_FMT_YUVA444P9
 
static const AVFilterPad fftdnoiz_inputs[]
 
#define AV_PIX_FMT_YUV420P12
 
#define AV_PIX_FMT_YUV422P14
 
AVComplexFloat * hdata_out[MAX_THREADS]
 
static float power(float r, float g, float b, float max)
 
const AVFilter ff_vf_fftdnoiz
 
int h
agreed upon image height
 
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
 
#define AV_PIX_FMT_YUVA422P12
 
static void export_row16(AVComplexFloat *src, uint8_t *dstp, int rw, int depth, float *win)
 
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
 
static const int factor[16]
 
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
 
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
 
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
 
static void import_row8(AVComplexFloat *dst, uint8_t *src, int rw, float scale, float *win, int off)
 
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
 
AVTXContext * fft[MAX_THREADS]
 
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
#define FILTER_OUTPUTS(array)
 
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
 
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
 
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
 
The exact code depends on how similar the blocks are and how related they are to the block
 
static void export_row8(AVComplexFloat *src, uint8_t *dst, int rw, int depth, float *win)
 
#define AV_PIX_FMT_YUV440P12
 
#define AV_PIX_FMT_YUV444P14
 
AVFILTER_DEFINE_CLASS(fftdnoiz)
 
static const AVOption fftdnoiz_options[]
 
#define AV_PIX_FMT_GRAY12
 
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
 
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
 
#define AV_PIX_FMT_YUV420P14