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++)
218 p->
n = 1.f / (p->
b * p->
b);
251 uint8_t *srcp,
int src_linesize,
258 const int overlap = p->
o;
259 const int size = block - overlap;
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++) {
271 const int rh =
FFMIN(block, height - y * size);
272 const int rw =
FFMIN(block, width - x * size);
273 uint8_t *
src = srcp + src_linesize * y * size + x * size * bpp;
274 float *bdst = buffer + buffer_linesize * y * block + x * block * 2;
277 for (i = 0; i < rh; i++) {
279 for (j = rw; j <
block; j++) {
280 dst[j].
re = dst[block - j - 1].
re;
291 for (; i <
block; i++) {
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;
300 for (i = 0; i <
block; i++) {
301 for (j = 0; j <
block; j++)
302 dst[j] = ssrc[j * data_linesize + i];
305 memcpy(bdst, dst, block *
sizeof(
FFTComplex));
315 uint8_t *dstp,
int dst_linesize,
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;
326 const int size = block - overlap;
330 const float scale = 1.f / (block *
block);
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;
340 const int rw = x == 0 ? block :
FFMIN(size, width - x * size - woff);
341 const int rh = y == 0 ? block :
FFMIN(size, height - y * size - hoff);
342 float *
bsrc = buffer + buffer_linesize * y * block + x * block * 2;
343 uint8_t *dst = dstp + dst_linesize * (y * size + hoff) + (x * size + woff) * bpp;
347 for (i = 0; i <
block; i++) {
348 memcpy(ddst, bsrc, block *
sizeof(
FFTComplex));
351 for (j = 0; j <
block; j++) {
352 hdst[j * data_linesize +
i] = ddst[j];
360 for (i = 0; i < rh; i++) {
363 s->
export_row(hdst + woff, dst, rw, scale, depth);
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;
392 for (i = 0; i <
block; i++) {
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;
408 factor =
FFMAX((power - sigma) / power, limit);
411 power = mpr * mpr + mpi * mpi + 1e-15
f;
412 factor =
FFMAX((power - sigma) / power, limit);
415 power = mnr * mnr + mni * mni + 1e-15
f;
416 factor =
FFMAX((power - sigma) / power, limit);
419 cbuff[2 * j ] = (sumr + mpr + mnr) * scale;
420 cbuff[2 * j + 1] = (sumi + mpi + mni) * scale;
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;
449 for (i = 0; i <
block; i++) {
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;
465 factor =
FFMAX(limit, (power - sigma) / power);
468 power = difr * difr + difi * difi + 1e-15
f;
469 factor =
FFMAX(limit, (power - sigma) / power);
473 cbuff[j * 2 ] = (sumr + difr) * 0.5f;
474 cbuff[j * 2 + 1] = (sumi + difi) * 0.5f;
492 const float limit = 1.f - s->
amount;
496 for (y = 0; y <
noy; y++) {
497 for (x = 0; x <
nox; x++) {
498 float *buff = buffer + buffer_linesize * y * block + x * block * 2;
500 for (i = 0; i <
block; i++) {
501 for (j = 0; j <
block; j++) {
505 im = buff[j * 2 + 1];
506 power = re * re + im * im + 1e-15
f;
507 factor =
FFMAX(limit, (power - sigma) / power);
509 buff[j * 2 + 1] *=
factor;
570 for (plane = 0; plane < s->
nb_planes; plane++) {
596 }
else if (s->
next) {
598 }
else if (s->
prev) {
652 for (i = 0; i < 4; i++) {
695 .
inputs = fftdnoiz_inputs,
697 .priv_class = &fftdnoiz_class,
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUVA422P9
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_YUVA420P10
#define AV_PIX_FMT_YUV444P14
av_cold void av_fft_end(FFTContext *s)
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA422P10
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.
static const struct @322 planes[]
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
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.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
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.
The exact code depends on how similar the blocks are and how related they are to the block
static void import_row16(FFTComplex *dst, uint8_t *srcp, int rw)
#define AV_PIX_FMT_YUVA420P9
void(* export_row)(FFTComplex *src, uint8_t *dst, int rw, float scale, int depth)
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
#define AV_PIX_FMT_YUVA420P16
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.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
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.
#define AV_PIX_FMT_YUVA444P16
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
#define AV_PIX_FMT_GBRAP12
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
#define AV_PIX_FMT_GBRAP16
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...
#define AV_PIX_FMT_YUVA444P12
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static void filter_plane3d2(FFTdnoizContext *s, int plane, float *pbuffer, float *nbuffer)
AVFilterContext * src
source filter
#define AV_PIX_FMT_YUVA444P10
#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)
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define AV_PIX_FMT_GRAY14
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
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 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[]
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.
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
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)
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_YUVA444P9
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
void(* import_row)(FFTComplex *dst, uint8_t *src, int rw)
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.
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
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_PIX_FMT_YUVA422P12
#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.