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++) {
148 for (j = 0; j < rw; j++) {
158 for (j = 0; j < rw; j++)
159 dst[j] = av_clip_uint8(src[j].
re * scale);
164 uint16_t *
src = (uint16_t *)srcp;
167 for (j = 0; j < rw; j++) {
175 uint16_t *dst = (uint16_t *)dstp;
178 for (j = 0; j < rw; j++)
213 p->
n = 1.f / (p->
b * 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;
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;
272 for (i = 0; i < rh; i++) {
274 for (j = rw; j <
block; j++) {
275 dst[j].
re = dst[block - j - 1].
re;
282 dst += data_linesize;
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;
295 for (i = 0; i <
block; i++) {
296 for (j = 0; j <
block; j++)
297 dst[j] = ssrc[j * data_linesize + i];
300 memcpy(bdst, dst, block *
sizeof(
FFTComplex));
302 dst += data_linesize;
303 bdst += buffer_linesize;
314 const int depth = s->
depth;
315 const int bpp = (depth + 7) / 8;
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;
325 const float scale = 1.f / (block *
block);
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;
342 for (i = 0; i <
block; i++) {
343 memcpy(ddst, bsrc, block *
sizeof(
FFTComplex));
346 for (j = 0; j <
block; j++) {
347 hdst[j * data_linesize + i] = ddst[j];
350 ddst += data_linesize;
351 bsrc += buffer_linesize;
354 hdst = hdata + hoff * data_linesize;
355 for (i = 0; i < rh; i++) {
358 s->
export_row(hdst + woff, dst, rw, scale, depth);
360 hdst += data_linesize;
371 const int nox = p->
nox;
372 const int noy = p->
noy;
375 const float limit = 1.f - s->
amount;
377 const float cfactor = sqrtf(3.
f) * 0.5f;
378 const float scale = 1.f / 3.f;
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;
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;
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-15
f;
403 factor =
FFMAX((power - sigma) / power, limit);
406 power = mpr * mpr + mpi * mpi + 1e-15
f;
407 factor =
FFMAX((power - sigma) / power, limit);
410 power = mnr * mnr + mni * mni + 1e-15
f;
411 factor =
FFMAX((power - sigma) / power, limit);
414 cbuff[2 * j ] = (sumr + mpr + mnr) * scale;
415 cbuff[2 * j + 1] = (sumi + mpi + mni) * scale;
419 cbuff += buffer_linesize;
420 pbuff += buffer_linesize;
421 nbuff += buffer_linesize;
431 const int nox = p->
nox;
432 const int noy = p->
noy;
435 const float limit = 1.f - s->
amount;
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;
444 for (i = 0; i <
block; i++) {
445 for (j = 0; j <
block; j++) {
447 float sumr, sumi, difr, difi;
451 im = cbuff[j * 2 + 1];
452 pim = pbuff[j * 2 + 1];
459 power = sumr * sumr + sumi * sumi + 1e-15
f;
460 factor =
FFMAX(limit, (power - sigma) / power);
463 power = difr * difr + difi * difi + 1e-15
f;
464 factor =
FFMAX(limit, (power - sigma) / power);
468 cbuff[j * 2 ] = (sumr + difr) * 0.5f;
469 cbuff[j * 2 + 1] = (sumi + difi) * 0.5f;
472 cbuff += buffer_linesize;
473 pbuff += buffer_linesize;
483 const int nox = p->
nox;
484 const int noy = p->
noy;
487 const float limit = 1.f - s->
amount;
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;
495 for (i = 0; i <
block; i++) {
496 for (j = 0; j <
block; j++) {
500 im = buff[j * 2 + 1];
501 power = re * re + im * im + 1e-15
f;
502 factor =
FFMAX(limit, (power - sigma) / power);
504 buff[j * 2 + 1] *=
factor;
507 buff += buffer_linesize;
565 for (plane = 0; plane < s->
nb_planes; plane++) {
591 }
else if (s->
next) {
593 }
else if (s->
prev) {
647 for (i = 0; i < 4; i++) {
690 .
inputs = fftdnoiz_inputs,
692 .priv_class = &fftdnoiz_class,
#define AV_PIX_FMT_YUV440P10
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static void import_row8(FFTComplex *dst, uint8_t *src, int rw)
#define AV_PIX_FMT_YUV444P14
av_cold void av_fft_end(FFTContext *s)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
int h
agreed upon image height
static int request_frame(AVFilterLink *outlink)
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV420P12
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int is_disabled
the enabled state from the last expression evaluation
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
#define AV_PIX_FMT_GRAY10
BYTE int const BYTE * srcp
const char * name
Pad name.
#define AV_PIX_FMT_GRAY12
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static void export_plane(FFTdnoizContext *s, uint8_t *dstp, int dst_linesize, float *buffer, int buffer_linesize, int plane)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AVERROR_EOF
End of file.
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV422P12
A filter pad used for either input or output.
static void import_plane(FFTdnoizContext *s, uint8_t *srcp, int src_linesize, float *buffer, int buffer_linesize, int plane)
A link between two filters.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_cold int init(AVFilterContext *ctx)
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.
#define AV_PIX_FMT_YUV444P10
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
static const AVOption fftdnoiz_options[]
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GRAY16
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
AVFilterContext * src
source filter
static const AVFilterPad inputs[]
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
static const AVFilterPad outputs[]
int format
agreed upon media format
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P14
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
static int config_input(AVFilterLink *inlink)
Used for passing data between threads.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static void export_row16(FFTComplex *src, uint8_t *dstp, int rw, float scale, int depth)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define AV_PIX_FMT_GRAY14
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
#define AV_PIX_FMT_YUV420P10
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
static const int factor[16]
const char * name
Filter name.
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV420P9
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterLink ** outputs
array of pointers to output links
static const AVFilterPad fftdnoiz_inputs[]
void(* import_row)(FFTComplex *dst, uint8_t *src, int rw)
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GBRP12
#define flags(name, subs,...)
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
static void filter_plane3d1(FFTdnoizContext *s, int plane, float *pbuffer)
static av_cold void uninit(AVFilterContext *ctx)
void(* export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
AVFilterContext * dst
dest filter
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static int query_formats(AVFilterContext *ctx)
static const AVFilterPad fftdnoiz_outputs[]
static void export_row8(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
AVFILTER_DEFINE_CLASS(fftdnoiz)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static const uint8_t block_bits[]
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
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 depth
Number of bits in the component.
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_YUV422P16
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static void filter_plane2d(FFTdnoizContext *s, int plane)
#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.