FFmpeg
Macros | Functions | Variables
vf_hqdn3d.c File Reference
#include <float.h>
#include "config.h"
#include "libavutil/attributes.h"
#include "libavutil/common.h"
#include "libavutil/pixdesc.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
#include "vf_hqdn3d.h"

Go to the source code of this file.

Macros

#define LUT_BITS   (depth==16 ? 8 : 4)
 
#define LOAD(x)
 
#define STORE(x, val)
 
#define denoise(...)
 
#define PARAM1_DEFAULT   4.0
 
#define PARAM2_DEFAULT   3.0
 
#define PARAM3_DEFAULT   6.0
 
#define OFFSET(x)   offsetof(HQDN3DContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
 

Functions

static av_always_inline uint32_t lowpass (int prev, int cur, int16_t *coef, int depth)
 
static av_always_inline void denoise_temporal (uint8_t *src, uint8_t *dst, uint16_t *frame_ant, int w, int h, int sstride, int dstride, int16_t *temporal, int depth)
 
static av_always_inline void denoise_spatial (HQDN3DContext *s, uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, int w, int h, int sstride, int dstride, int16_t *spatial, int16_t *temporal, int depth)
 
static av_always_inline int denoise_depth (HQDN3DContext *s, uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t **frame_ant_ptr, int w, int h, int sstride, int dstride, int16_t *spatial, int16_t *temporal, int depth)
 
static int16_t * precalc_coefs (double dist25, int depth)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
 AVFILTER_DEFINE_CLASS (hqdn3d)
 

Variables

static const AVOption hqdn3d_options []
 
static const AVFilterPad avfilter_vf_hqdn3d_inputs []
 
static const AVFilterPad avfilter_vf_hqdn3d_outputs []
 
AVFilter ff_vf_hqdn3d
 

Detailed Description

high quality 3d video denoiser, ported from MPlayer libmpcodecs/vf_hqdn3d.c.

Definition in file vf_hqdn3d.c.

Macro Definition Documentation

◆ LUT_BITS

#define LUT_BITS   (depth==16 ? 8 : 4)

Definition at line 44 of file vf_hqdn3d.c.

◆ LOAD

#define LOAD (   x)
Value:
(((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
+ (((1 << (16 - depth)) - 1) >> 1))

Definition at line 45 of file vf_hqdn3d.c.

◆ STORE

#define STORE (   x,
  val 
)
Value:
(depth == 8 ? dst[x] = (val) >> (16 - depth) : \
AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))

Definition at line 47 of file vf_hqdn3d.c.

◆ denoise

#define denoise (   ...)
Value:
do { \
int ret = AVERROR_BUG; \
switch (s->depth) { \
case 8: ret = denoise_depth(__VA_ARGS__, 8); break; \
case 9: ret = denoise_depth(__VA_ARGS__, 9); break; \
case 10: ret = denoise_depth(__VA_ARGS__, 10); break; \
case 16: ret = denoise_depth(__VA_ARGS__, 16); break; \
} \
if (ret < 0) { \
av_frame_free(&out); \
if (!direct) \
av_frame_free(&in); \
return ret; \
} \
} while (0)

Definition at line 156 of file vf_hqdn3d.c.

◆ PARAM1_DEFAULT

#define PARAM1_DEFAULT   4.0

Definition at line 194 of file vf_hqdn3d.c.

◆ PARAM2_DEFAULT

#define PARAM2_DEFAULT   3.0

Definition at line 195 of file vf_hqdn3d.c.

◆ PARAM3_DEFAULT

#define PARAM3_DEFAULT   6.0

Definition at line 196 of file vf_hqdn3d.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(HQDN3DContext, x)

Definition at line 332 of file vf_hqdn3d.c.

◆ FLAGS

Definition at line 333 of file vf_hqdn3d.c.

Function Documentation

◆ lowpass()

static av_always_inline uint32_t lowpass ( int  prev,
int  cur,
int16_t *  coef,
int  depth 
)
static

Definition at line 51 of file vf_hqdn3d.c.

Referenced by denoise_spatial(), and denoise_temporal().

◆ denoise_temporal()

static av_always_inline void denoise_temporal ( uint8_t src,
uint8_t dst,
uint16_t *  frame_ant,
int  w,
int  h,
int  sstride,
int  dstride,
int16_t *  temporal,
int  depth 
)
static

Definition at line 58 of file vf_hqdn3d.c.

Referenced by denoise_depth().

◆ denoise_spatial()

static av_always_inline void denoise_spatial ( HQDN3DContext s,
uint8_t src,
uint8_t dst,
uint16_t *  line_ant,
uint16_t *  frame_ant,
int  w,
int  h,
int  sstride,
int  dstride,
int16_t *  spatial,
int16_t *  temporal,
int  depth 
)
static

Definition at line 80 of file vf_hqdn3d.c.

Referenced by denoise_depth().

◆ denoise_depth()

static av_always_inline int denoise_depth ( HQDN3DContext s,
uint8_t src,
uint8_t dst,
uint16_t *  line_ant,
uint16_t **  frame_ant_ptr,
int  w,
int  h,
int  sstride,
int  dstride,
int16_t *  spatial,
int16_t *  temporal,
int  depth 
)
static

Definition at line 124 of file vf_hqdn3d.c.

◆ precalc_coefs()

static int16_t* precalc_coefs ( double  dist25,
int  depth 
)
static

Definition at line 173 of file vf_hqdn3d.c.

Referenced by config_input().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 198 of file vf_hqdn3d.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 218 of file vf_hqdn3d.c.

Referenced by config_input().

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 232 of file vf_hqdn3d.c.

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 262 of file vf_hqdn3d.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 290 of file vf_hqdn3d.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( hqdn3d  )

Variable Documentation

◆ hqdn3d_options

const AVOption hqdn3d_options[]
static
Initial value:
= {
{ "luma_spatial", "spatial luma strength", OFFSET(strength[LUMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
{ "chroma_spatial", "spatial chroma strength", OFFSET(strength[CHROMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
{ "luma_tmp", "temporal luma strength", OFFSET(strength[LUMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
{ "chroma_tmp", "temporal chroma strength", OFFSET(strength[CHROMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
{ NULL }
}

Definition at line 334 of file vf_hqdn3d.c.

◆ avfilter_vf_hqdn3d_inputs

const AVFilterPad avfilter_vf_hqdn3d_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
{ NULL }
}

Definition at line 344 of file vf_hqdn3d.c.

◆ avfilter_vf_hqdn3d_outputs

const AVFilterPad avfilter_vf_hqdn3d_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}

Definition at line 355 of file vf_hqdn3d.c.

◆ ff_vf_hqdn3d

AVFilter ff_vf_hqdn3d
Initial value:
= {
.name = "hqdn3d",
.description = NULL_IF_CONFIG_SMALL("Apply a High Quality 3D Denoiser."),
.priv_size = sizeof(HQDN3DContext),
.priv_class = &hqdn3d_class,
.init = init,
}

Definition at line 363 of file vf_hqdn3d.c.

init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:198
out
FILE * out
Definition: movenc.c:54
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_hqdn3d.c:262
FLAGS
#define FLAGS
Definition: vf_hqdn3d.c:333
OFFSET
#define OFFSET(x)
Definition: vf_hqdn3d.c:332
src
#define src
Definition: vp8dsp.c:254
CHROMA_TMP
#define CHROMA_TMP
Definition: vf_hqdn3d.h:45
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:232
s
#define s(width, name)
Definition: cbs_vp9.c:257
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:218
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
NULL
#define NULL
Definition: coverity.c:32
avfilter_vf_hqdn3d_inputs
static const AVFilterPad avfilter_vf_hqdn3d_inputs[]
Definition: vf_hqdn3d.c:344
inputs
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
Definition: filter_design.txt:243
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
LUMA_SPATIAL
#define LUMA_SPATIAL
Definition: vf_hqdn3d.h:42
val
const char const char void * val
Definition: avisynth_c.h:863
in
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
Definition: audio_convert.c:326
LUMA_TMP
#define LUMA_TMP
Definition: vf_hqdn3d.h:43
CHROMA_SPATIAL
#define CHROMA_SPATIAL
Definition: vf_hqdn3d.h:44
ret
ret
Definition: filter_design.txt:187
avfilter_vf_hqdn3d_outputs
static const AVFilterPad avfilter_vf_hqdn3d_outputs[]
Definition: vf_hqdn3d.c:355
AV_RN16A
#define AV_RN16A(p)
Definition: intreadwrite.h:522
HQDN3DContext
Definition: vf_hqdn3d.h:31
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_hqdn3d.c:290
denoise_depth
static av_always_inline int denoise_depth(HQDN3DContext *s, uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t **frame_ant_ptr, int w, int h, int sstride, int dstride, int16_t *spatial, int16_t *temporal, int depth)
Definition: vf_hqdn3d.c:124
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:133
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50