Go to the documentation of this file.
72 #define OFFSET(x) offsetof(FFTdnoizContext, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
75 {
"sigma",
"set denoise strength",
77 {
"amount",
"set amount of denoising",
79 {
"block",
"set block log2(size)",
81 {
"overlap",
"set block overlap",
83 {
"prev",
"set number of previous frames for temporal denoising",
85 {
"next",
"set number of next frames for temporal denoising",
87 {
"planes",
"set planes to filter",
99 for (
i = 0;
i < 4;
i++) {
153 for (j = 0; j < rw; j++) {
163 for (j = 0; j < rw; j++)
169 uint16_t *
src = (uint16_t *)srcp;
172 for (j = 0; j < rw; j++) {
180 uint16_t *dst = (uint16_t *)dstp;
183 for (j = 0; j < rw; j++)
195 s->depth =
desc->comp[0].depth;
203 s->sigma *= 1 << (
s->depth - 8) * (1 +
s->nb_prev +
s->nb_next);
207 s->planes[0].planewidth =
s->planes[3].planewidth =
inlink->w;
209 s->planes[0].planeheight =
s->planes[3].planeheight =
inlink->h;
213 for (
i = 0;
i <
s->nb_planes;
i++) {
217 p->
b = 1 <<
s->block_bits;
218 p->
n = 1.f / (p->
b * p->
b);
219 p->
o = p->
b *
s->overlap;
230 if (
s->nb_prev > 0) {
235 if (
s->nb_next > 0) {
251 uint8_t *srcp,
int src_linesize,
252 float *
buffer,
int buffer_linesize,
int plane)
258 const int overlap = p->
o;
260 const int nox = p->
nox;
261 const int noy = p->
noy;
262 const int bpp = (
s->depth + 7) / 8;
268 buffer_linesize /=
sizeof(float);
269 for (y = 0; y < noy; y++) {
270 for (x = 0; x < nox; x++) {
277 for (
i = 0;
i < rh;
i++) {
278 s->import_row(dst,
src, rw);
279 for (j = rw; j <
block; j++) {
287 dst += data_linesize;
292 for (j = 0; j <
block; j++) {
293 dst[j].
re = dst[(
block -
i - 1) * data_linesize + j].
re;
294 dst[j].
im = dst[(
block -
i - 1) * data_linesize + j].
im;
301 for (j = 0; j <
block; j++)
302 dst[j] = ssrc[j * data_linesize +
i];
307 dst += data_linesize;
308 bdst += buffer_linesize;
315 uint8_t *dstp,
int dst_linesize,
316 float *
buffer,
int buffer_linesize,
int plane)
319 const int depth =
s->depth;
320 const int bpp = (depth + 7) / 8;
324 const int overlap = p->
o;
325 const int hoverlap = overlap / 2;
327 const int nox = p->
nox;
328 const int noy = p->
noy;
335 buffer_linesize /=
sizeof(float);
336 for (y = 0; y < noy; y++) {
337 for (x = 0; x < nox; x++) {
338 const int woff = x == 0 ? 0 : hoverlap;
339 const int hoff = y == 0 ? 0 : hoverlap;
343 uint8_t *dst = dstp + dst_linesize * (y *
size + hoff) + (x *
size + woff) * bpp;
351 for (j = 0; j <
block; j++) {
352 hdst[j * data_linesize +
i] = ddst[j];
355 ddst += data_linesize;
356 bsrc += buffer_linesize;
359 hdst = hdata + hoff * data_linesize;
360 for (
i = 0;
i < rh;
i++) {
363 s->export_row(hdst + woff, dst, rw, scale, depth);
365 hdst += data_linesize;
376 const int nox = p->
nox;
377 const int noy = p->
noy;
379 const float sigma =
s->sigma *
s->sigma *
block *
block;
380 const float limit = 1.f -
s->amount;
382 const float cfactor = sqrtf(3.
f) * 0.5f;
383 const float scale = 1.f / 3.f;
386 for (y = 0; y < noy; y++) {
387 for (x = 0; x < nox; x++) {
388 float *cbuff = cbuffer + buffer_linesize * y *
block + x *
block * 2;
389 float *pbuff = pbuffer + buffer_linesize * y *
block + x *
block * 2;
390 float *nbuff = nbuffer + buffer_linesize * y *
block + x *
block * 2;
393 for (j = 0; j <
block; j++) {
394 float sumr, sumi, difr, difi, mpr, mpi, mnr, mni;
395 float factor, power, sumpnr, sumpni;
397 sumpnr = pbuff[2 * j ] + nbuff[2 * j ];
398 sumpni = pbuff[2 * j + 1] + nbuff[2 * j + 1];
399 sumr = cbuff[2 * j ] + sumpnr;
400 sumi = cbuff[2 * j + 1] + sumpni;
401 difr = cfactor * (nbuff[2 * j ] - pbuff[2 * j ]);
402 difi = cfactor * (pbuff[2 * j + 1] - nbuff[2 * j + 1]);
403 mpr = cbuff[2 * j ] - 0.5f * sumpnr + difi;
404 mnr = mpr - difi - difi;
405 mpi = cbuff[2 * j + 1] - 0.5f * sumpni + difr;
406 mni = mpi - difr - difr;
407 power = sumr * sumr + sumi * sumi + 1e-15
f;
411 power = mpr * mpr + mpi * mpi + 1e-15
f;
415 power = mnr * mnr + mni * mni + 1e-15
f;
419 cbuff[2 * j ] = (sumr + mpr + mnr) * scale;
420 cbuff[2 * j + 1] = (sumi + mpi + mni) * scale;
424 cbuff += buffer_linesize;
425 pbuff += buffer_linesize;
426 nbuff += buffer_linesize;
436 const int nox = p->
nox;
437 const int noy = p->
noy;
439 const float sigma =
s->sigma *
s->sigma *
block *
block;
440 const float limit = 1.f -
s->amount;
444 for (y = 0; y < noy; y++) {
445 for (x = 0; x < nox; x++) {
446 float *cbuff = cbuffer + buffer_linesize * y *
block + x *
block * 2;
447 float *pbuff = pbuffer + buffer_linesize * y *
block + x *
block * 2;
450 for (j = 0; j <
block; j++) {
452 float sumr, sumi, difr, difi;
456 im = cbuff[j * 2 + 1];
457 pim = pbuff[j * 2 + 1];
464 power = sumr * sumr + sumi * sumi + 1e-15
f;
468 power = difr * difr + difi * difi + 1e-15
f;
473 cbuff[j * 2 ] = (sumr + difr) * 0.5
f;
474 cbuff[j * 2 + 1] = (sumi + difi) * 0.5
f;
477 cbuff += buffer_linesize;
478 pbuff += buffer_linesize;
488 const int nox = p->
nox;
489 const int noy = p->
noy;
491 const float sigma =
s->sigma *
s->sigma *
block *
block;
492 const float limit = 1.f -
s->amount;
496 for (y = 0; y < noy; y++) {
497 for (x = 0; x < nox; x++) {
501 for (j = 0; j <
block; j++) {
505 im = buff[j * 2 + 1];
509 buff[j * 2 + 1] *=
factor;
512 buff += buffer_linesize;
526 if (
s->nb_next > 0 &&
s->nb_prev > 0) {
532 if (!
s->prev &&
s->cur) {
539 }
else if (
s->nb_next > 0) {
546 }
else if (
s->nb_prev > 0) {
570 for (plane = 0; plane <
s->nb_planes; plane++) {
573 if (!((1 << plane) &
s->planesf) ||
ctx->is_disabled) {
576 s->cur->data[plane],
s->cur->linesize[plane],
594 if (
s->next &&
s->prev) {
596 }
else if (
s->next) {
598 }
else if (
s->prev) {
608 if (
s->nb_next == 0 &&
s->nb_prev == 0) {
629 if (
s->next &&
s->nb_next > 0)
652 for (
i = 0;
i < 4;
i++) {
697 .priv_class = &fftdnoiz_class,
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
av_cold void av_fft_end(FFTContext *s)
#define AV_PIX_FMT_GBRAP16
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
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)
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.
static const uint8_t block_bits[]
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_PIX_FMT_YUVA422P9
static void filter_plane2d(FFTdnoizContext *s, int plane)
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
static void export_plane(FFTdnoizContext *s, uint8_t *dstp, int dst_linesize, float *buffer, int buffer_linesize, int plane)
#define AV_PIX_FMT_YUVA420P10
static const AVFilterPad fftdnoiz_outputs[]
#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.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
@ 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
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUVA420P9
#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
#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 ...
#define AV_PIX_FMT_YUV422P16
@ 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 const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#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.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ 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
#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.
@ 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
#define AV_PIX_FMT_YUV422P10
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int config_input(AVFilterLink *inlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int init(AVFilterContext *ctx)
#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
void(* import_row)(FFTComplex *dst, uint8_t *src, int rw)
static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
static int query_formats(AVFilterContext *ctx)
static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define i(width, name, range_min, range_max)
static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
int w
agreed upon image width
static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
#define AV_PIX_FMT_GBRP12
Used for passing data between threads.
static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
@ 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.
#define AV_PIX_FMT_YUV444P9
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_YUVA444P9
static const AVFilterPad fftdnoiz_inputs[]
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static void import_plane(FFTdnoizContext *s, uint8_t *srcp, int src_linesize, float *buffer, int buffer_linesize, int plane)
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
@ 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
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
@ 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...
#define flags(name, subs,...)
@ 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
#define AV_PIX_FMT_YUV440P12
void(* export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
#define AV_PIX_FMT_YUV444P14
AVFILTER_DEFINE_CLASS(fftdnoiz)
static const AVOption fftdnoiz_options[]
#define AV_PIX_FMT_GRAY12
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14