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

Go to the source code of this file.

Data Structures

struct  ThreadData
 Used for passing data between threads. More...
 

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 | AV_OPT_FLAG_RUNTIME_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 void precalc_coefs (double dist25, int depth, int16_t *ct)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static void calc_coefs (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static int do_denoise (AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 
 AVFILTER_DEFINE_CLASS (hqdn3d)
 

Variables

static enum AVPixelFormat pix_fmts []
 
static const AVOption hqdn3d_options []
 
static const AVFilterPad avfilter_vf_hqdn3d_inputs []
 
const 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 12: ret = denoise_depth(__VA_ARGS__, 12); break; \
case 14: ret = denoise_depth(__VA_ARGS__, 14); 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 192 of file vf_hqdn3d.c.

◆ PARAM2_DEFAULT

#define PARAM2_DEFAULT   3.0

Definition at line 193 of file vf_hqdn3d.c.

◆ PARAM3_DEFAULT

#define PARAM3_DEFAULT   6.0

Definition at line 194 of file vf_hqdn3d.c.

◆ OFFSET

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

Definition at line 364 of file vf_hqdn3d.c.

◆ FLAGS

Definition at line 365 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 void precalc_coefs ( double  dist25,
int  depth,
int16_t *  ct 
)
static

Definition at line 175 of file vf_hqdn3d.c.

Referenced by calc_coefs().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 196 of file vf_hqdn3d.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 216 of file vf_hqdn3d.c.

Referenced by config_input().

◆ calc_coefs()

static void calc_coefs ( AVFilterContext ctx)
static

Definition at line 246 of file vf_hqdn3d.c.

Referenced by config_input(), and process_command().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 254 of file vf_hqdn3d.c.

◆ do_denoise()

static int do_denoise ( AVFilterContext ctx,
void *  data,
int  job_nr,
int  n_jobs 
)
static

Definition at line 293 of file vf_hqdn3d.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 312 of file vf_hqdn3d.c.

◆ process_command()

static int process_command ( AVFilterContext ctx,
const char *  cmd,
const char *  args,
char *  res,
int  res_len,
int  flags 
)
static

Definition at line 350 of file vf_hqdn3d.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( hqdn3d  )

Variable Documentation

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ 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 366 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,
},
}

Definition at line 376 of file vf_hqdn3d.c.

◆ ff_vf_hqdn3d

const 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,
.process_command = process_command,
}

Definition at line 386 of file vf_hqdn3d.c.

init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:196
out
FILE * out
Definition: movenc.c:54
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:172
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:468
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_hqdn3d.c:254
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:466
val
static double val(void *priv, double ch)
Definition: aeval.c:78
FLAGS
#define FLAGS
Definition: vf_hqdn3d.c:365
OFFSET
#define OFFSET(x)
Definition: vf_hqdn3d.c:364
CHROMA_TMP
#define CHROMA_TMP
Definition: vf_hqdn3d.h:45
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:471
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:480
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:36
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:481
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:216
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:465
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:479
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
NULL
#define NULL
Definition: coverity.c:32
avfilter_vf_hqdn3d_inputs
static const AVFilterPad avfilter_vf_hqdn3d_inputs[]
Definition: vf_hqdn3d.c:376
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:470
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:469
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:106
LUMA_SPATIAL
#define LUMA_SPATIAL
Definition: vf_hqdn3d.h:42
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:473
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:475
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_hqdn3d.c:232
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
LUMA_TMP
#define LUMA_TMP
Definition: vf_hqdn3d.h:43
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:467
CHROMA_SPATIAL
#define CHROMA_SPATIAL
Definition: vf_hqdn3d.h:44
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:472
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:477
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_RN16A
#define AV_RN16A(p)
Definition: intreadwrite.h:520
HQDN3DContext
Definition: vf_hqdn3d.h:31
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_hqdn3d.c:312
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
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
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
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:155
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:474
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:478
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_hqdn3d.c:350
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:476