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;
208 s->planes[1].planeheight =
s->planes[2].planeheight =
AV_CEIL_RSHIFT(inlink->
h,
desc->log2_chroma_h);
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-15f;
411 power = mpr * mpr + mpi * mpi + 1e-15f;
415 power = mnr * mnr + mni * mni + 1e-15f;
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-15f;
468 power = difr * difr + difi * difi + 1e-15f;
473 cbuff[j * 2 ] = (sumr + difr) * 0.5f;
474 cbuff[j * 2 + 1] = (sumi + difi) * 0.5f;
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,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
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
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
#define flags(name, subs,...)
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.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
av_cold void av_fft_end(FFTContext *s)
#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.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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 const uint8_t block_bits[]
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
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
typedef void(RENAME(mix_any_func_type))
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.
const char * name
Pad name.
const char * name
Filter name.
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...
void(* import_row)(FFTComplex *dst, uint8_t *src, int rw)
void(* export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
Used for passing data between threads.
AVFILTER_DEFINE_CLASS(fftdnoiz)
static void export_plane(FFTdnoizContext *s, uint8_t *dstp, int dst_linesize, float *buffer, int buffer_linesize, int plane)
static const AVOption fftdnoiz_options[]
static int query_formats(AVFilterContext *ctx)
static void filter_plane2d(FFTdnoizContext *s, int plane)
static int config_input(AVFilterLink *inlink)
static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
static int request_frame(AVFilterLink *outlink)
static const AVFilterPad fftdnoiz_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
static void import_plane(FFTdnoizContext *s, uint8_t *srcp, int src_linesize, float *buffer, int buffer_linesize, int plane)
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
static const AVFilterPad fftdnoiz_inputs[]
static const int factor[16]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.