FFmpeg
vf_hqdn3d.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Daniel Moreno <comac AT comac DOT darktech DOT org>
3  * Copyright (c) 2010 Baptiste Coudurier
4  * Copyright (c) 2012 Loren Merritt
5  *
6  * This file is part of FFmpeg, ported from MPlayer.
7  *
8  * FFmpeg is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 /**
24  * @file
25  * high quality 3d video denoiser, ported from MPlayer
26  * libmpcodecs/vf_hqdn3d.c.
27  */
28 
29 #include <float.h>
30 
31 #include "config.h"
32 #include "libavutil/attributes.h"
33 #include "libavutil/common.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/intreadwrite.h"
36 #include "libavutil/opt.h"
37 
38 #include "avfilter.h"
39 #include "formats.h"
40 #include "internal.h"
41 #include "video.h"
42 #include "vf_hqdn3d.h"
43 
44 #define LUT_BITS (depth==16 ? 8 : 4)
45 #define LOAD(x) (((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
46  + (((1 << (16 - depth)) - 1) >> 1))
47 #define STORE(x,val) (depth == 8 ? dst[x] = (val) >> (16 - depth) : \
48  AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))
49 
51 static uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
52 {
53  int d = (prev - cur) >> (8 - LUT_BITS);
54  return cur + coef[d];
55 }
56 
58 static void denoise_temporal(uint8_t *src, uint8_t *dst,
59  uint16_t *frame_ant,
60  int w, int h, int sstride, int dstride,
61  int16_t *temporal, int depth)
62 {
63  long x, y;
64  uint32_t tmp;
65 
66  temporal += 256 << LUT_BITS;
67 
68  for (y = 0; y < h; y++) {
69  for (x = 0; x < w; x++) {
70  frame_ant[x] = tmp = lowpass(frame_ant[x], LOAD(x), temporal, depth);
71  STORE(x, tmp);
72  }
73  src += sstride;
74  dst += dstride;
75  frame_ant += w;
76  }
77 }
78 
81  uint8_t *src, uint8_t *dst,
82  uint16_t *line_ant, uint16_t *frame_ant,
83  int w, int h, int sstride, int dstride,
84  int16_t *spatial, int16_t *temporal, int depth)
85 {
86  long x, y;
87  uint32_t pixel_ant;
88  uint32_t tmp;
89 
90  spatial += 256 << LUT_BITS;
91  temporal += 256 << LUT_BITS;
92 
93  /* First line has no top neighbor. Only left one for each tmp and
94  * last frame */
95  pixel_ant = LOAD(0);
96  for (x = 0; x < w; x++) {
97  line_ant[x] = tmp = pixel_ant = lowpass(pixel_ant, LOAD(x), spatial, depth);
98  frame_ant[x] = tmp = lowpass(frame_ant[x], tmp, temporal, depth);
99  STORE(x, tmp);
100  }
101 
102  for (y = 1; y < h; y++) {
103  src += sstride;
104  dst += dstride;
105  frame_ant += w;
106  if (s->denoise_row[depth]) {
107  s->denoise_row[depth](src, dst, line_ant, frame_ant, w, spatial, temporal);
108  continue;
109  }
110  pixel_ant = LOAD(0);
111  for (x = 0; x < w-1; x++) {
112  line_ant[x] = tmp = lowpass(line_ant[x], pixel_ant, spatial, depth);
113  pixel_ant = lowpass(pixel_ant, LOAD(x+1), spatial, depth);
114  frame_ant[x] = tmp = lowpass(frame_ant[x], tmp, temporal, depth);
115  STORE(x, tmp);
116  }
117  line_ant[x] = tmp = lowpass(line_ant[x], pixel_ant, spatial, depth);
118  frame_ant[x] = tmp = lowpass(frame_ant[x], tmp, temporal, depth);
119  STORE(x, tmp);
120  }
121 }
122 
125  uint8_t *src, uint8_t *dst,
126  uint16_t *line_ant, uint16_t **frame_ant_ptr,
127  int w, int h, int sstride, int dstride,
128  int16_t *spatial, int16_t *temporal, int depth)
129 {
130  // FIXME: For 16-bit depth, frame_ant could be a pointer to the previous
131  // filtered frame rather than a separate buffer.
132  long x, y;
133  uint16_t *frame_ant = *frame_ant_ptr;
134  if (!frame_ant) {
135  uint8_t *frame_src = src;
136  *frame_ant_ptr = frame_ant = av_malloc_array(w, h*sizeof(uint16_t));
137  if (!frame_ant)
138  return AVERROR(ENOMEM);
139  for (y = 0; y < h; y++, src += sstride, frame_ant += w)
140  for (x = 0; x < w; x++)
141  frame_ant[x] = LOAD(x);
142  src = frame_src;
143  frame_ant = *frame_ant_ptr;
144  }
145 
146  if (spatial[0])
147  denoise_spatial(s, src, dst, line_ant, frame_ant,
148  w, h, sstride, dstride, spatial, temporal, depth);
149  else
150  denoise_temporal(src, dst, frame_ant,
151  w, h, sstride, dstride, temporal, depth);
152  emms_c();
153  return 0;
154 }
155 
156 #define denoise(...) \
157  do { \
158  int ret = AVERROR_BUG; \
159  switch (s->depth) { \
160  case 8: ret = denoise_depth(__VA_ARGS__, 8); break; \
161  case 9: ret = denoise_depth(__VA_ARGS__, 9); break; \
162  case 10: ret = denoise_depth(__VA_ARGS__, 10); break; \
163  case 16: ret = denoise_depth(__VA_ARGS__, 16); break; \
164  } \
165  if (ret < 0) { \
166  av_frame_free(&out); \
167  if (!direct) \
168  av_frame_free(&in); \
169  return ret; \
170  } \
171  } while (0)
172 
173 static int16_t *precalc_coefs(double dist25, int depth)
174 {
175  int i;
176  double gamma, simil, C;
177  int16_t *ct = av_malloc((512<<LUT_BITS)*sizeof(int16_t));
178  if (!ct)
179  return NULL;
180 
181  gamma = log(0.25) / log(1.0 - FFMIN(dist25,252.0)/255.0 - 0.00001);
182 
183  for (i = -256<<LUT_BITS; i < 256<<LUT_BITS; i++) {
184  double f = ((i<<(9-LUT_BITS)) + (1<<(8-LUT_BITS)) - 1) / 512.0; // midpoint of the bin
185  simil = FFMAX(0, 1.0 - fabs(f) / 255.0);
186  C = pow(simil, gamma) * 256.0 * f;
187  ct[(256<<LUT_BITS)+i] = lrint(C);
188  }
189 
190  ct[0] = !!dist25;
191  return ct;
192 }
193 
194 #define PARAM1_DEFAULT 4.0
195 #define PARAM2_DEFAULT 3.0
196 #define PARAM3_DEFAULT 6.0
197 
199 {
200  HQDN3DContext *s = ctx->priv;
201 
202  if (!s->strength[LUMA_SPATIAL])
203  s->strength[LUMA_SPATIAL] = PARAM1_DEFAULT;
204  if (!s->strength[CHROMA_SPATIAL])
205  s->strength[CHROMA_SPATIAL] = PARAM2_DEFAULT * s->strength[LUMA_SPATIAL] / PARAM1_DEFAULT;
206  if (!s->strength[LUMA_TMP])
207  s->strength[LUMA_TMP] = PARAM3_DEFAULT * s->strength[LUMA_SPATIAL] / PARAM1_DEFAULT;
208  if (!s->strength[CHROMA_TMP])
209  s->strength[CHROMA_TMP] = s->strength[LUMA_TMP] * s->strength[CHROMA_SPATIAL] / s->strength[LUMA_SPATIAL];
210 
211  av_log(ctx, AV_LOG_VERBOSE, "ls:%f cs:%f lt:%f ct:%f\n",
212  s->strength[LUMA_SPATIAL], s->strength[CHROMA_SPATIAL],
213  s->strength[LUMA_TMP], s->strength[CHROMA_TMP]);
214 
215  return 0;
216 }
217 
219 {
220  HQDN3DContext *s = ctx->priv;
221 
222  av_freep(&s->coefs[0]);
223  av_freep(&s->coefs[1]);
224  av_freep(&s->coefs[2]);
225  av_freep(&s->coefs[3]);
226  av_freep(&s->line);
227  av_freep(&s->frame_prev[0]);
228  av_freep(&s->frame_prev[1]);
229  av_freep(&s->frame_prev[2]);
230 }
231 
233 {
234  static const enum AVPixelFormat pix_fmts[] = {
255  };
257  if (!fmts_list)
258  return AVERROR(ENOMEM);
259  return ff_set_common_formats(ctx, fmts_list);
260 }
261 
263 {
264  HQDN3DContext *s = inlink->dst->priv;
266  int i;
267 
268  uninit(inlink->dst);
269 
270  s->hsub = desc->log2_chroma_w;
271  s->vsub = desc->log2_chroma_h;
272  s->depth = desc->comp[0].depth;
273 
274  s->line = av_malloc_array(inlink->w, sizeof(*s->line));
275  if (!s->line)
276  return AVERROR(ENOMEM);
277 
278  for (i = 0; i < 4; i++) {
279  s->coefs[i] = precalc_coefs(s->strength[i], s->depth);
280  if (!s->coefs[i])
281  return AVERROR(ENOMEM);
282  }
283 
284  if (ARCH_X86)
286 
287  return 0;
288 }
289 
291 {
292  AVFilterContext *ctx = inlink->dst;
293  HQDN3DContext *s = ctx->priv;
294  AVFilterLink *outlink = ctx->outputs[0];
295 
296  AVFrame *out;
297  int c, direct = av_frame_is_writable(in) && !ctx->is_disabled;
298 
299  if (direct) {
300  out = in;
301  } else {
302  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
303  if (!out) {
304  av_frame_free(&in);
305  return AVERROR(ENOMEM);
306  }
307 
309  }
310 
311  for (c = 0; c < 3; c++) {
312  denoise(s, in->data[c], out->data[c],
313  s->line, &s->frame_prev[c],
314  AV_CEIL_RSHIFT(in->width, (!!c * s->hsub)),
315  AV_CEIL_RSHIFT(in->height, (!!c * s->vsub)),
316  in->linesize[c], out->linesize[c],
317  s->coefs[c ? CHROMA_SPATIAL : LUMA_SPATIAL],
318  s->coefs[c ? CHROMA_TMP : LUMA_TMP]);
319  }
320 
321  if (ctx->is_disabled) {
322  av_frame_free(&out);
323  return ff_filter_frame(outlink, in);
324  }
325 
326  if (!direct)
327  av_frame_free(&in);
328 
329  return ff_filter_frame(outlink, out);
330 }
331 
332 #define OFFSET(x) offsetof(HQDN3DContext, x)
333 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
334 static const AVOption hqdn3d_options[] = {
335  { "luma_spatial", "spatial luma strength", OFFSET(strength[LUMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
336  { "chroma_spatial", "spatial chroma strength", OFFSET(strength[CHROMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
337  { "luma_tmp", "temporal luma strength", OFFSET(strength[LUMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
338  { "chroma_tmp", "temporal chroma strength", OFFSET(strength[CHROMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
339  { NULL }
340 };
341 
342 AVFILTER_DEFINE_CLASS(hqdn3d);
343 
345  {
346  .name = "default",
347  .type = AVMEDIA_TYPE_VIDEO,
348  .config_props = config_input,
349  .filter_frame = filter_frame,
350  },
351  { NULL }
352 };
353 
354 
356  {
357  .name = "default",
358  .type = AVMEDIA_TYPE_VIDEO
359  },
360  { NULL }
361 };
362 
364  .name = "hqdn3d",
365  .description = NULL_IF_CONFIG_SMALL("Apply a High Quality 3D Denoiser."),
366  .priv_size = sizeof(HQDN3DContext),
367  .priv_class = &hqdn3d_class,
368  .init = init,
369  .uninit = uninit,
374 };
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:198
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
vf_hqdn3d.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVERROR
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
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
LOAD
#define LOAD(x)
Definition: vf_hqdn3d.c:45
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
inlink
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
Definition: filter_design.txt:212
LUT_BITS
#define LUT_BITS
Definition: vf_hqdn3d.c:44
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
PARAM2_DEFAULT
#define PARAM2_DEFAULT
Definition: vf_hqdn3d.c:195
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:246
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:387
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
float.h
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
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
video.h
lowpass
static av_always_inline uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
Definition: vf_hqdn3d.c:51
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_hqdn3d.c:262
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
STORE
#define STORE(x, val)
Definition: vf_hqdn3d.c:47
ff_hqdn3d_init_x86
void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d)
Definition: vf_hqdn3d_init.c:41
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:385
FLAGS
#define FLAGS
Definition: vf_hqdn3d.c:333
OFFSET
#define OFFSET(x)
Definition: vf_hqdn3d.c:332
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
precalc_coefs
static int16_t * precalc_coefs(double dist25, int depth)
Definition: vf_hqdn3d.c:173
PARAM3_DEFAULT
#define PARAM3_DEFAULT
Definition: vf_hqdn3d.c:196
CHROMA_TMP
#define CHROMA_TMP
Definition: vf_hqdn3d.h:45
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
lrint
#define lrint
Definition: tablegen.h:53
av_cold
#define av_cold
Definition: attributes.h:84
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:399
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
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
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:232
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:400
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
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
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:384
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:398
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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
f
#define f(width, name)
Definition: cbs_vp9.c:255
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
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
avfilter_vf_hqdn3d_inputs
static const AVFilterPad avfilter_vf_hqdn3d_inputs[]
Definition: vf_hqdn3d.c:344
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_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
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
ff_vf_hqdn3d
AVFilter ff_vf_hqdn3d
Definition: vf_hqdn3d.c:363
PARAM1_DEFAULT
#define PARAM1_DEFAULT
Definition: vf_hqdn3d.c:194
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
desc
const char * desc
Definition: nvenc.c:68
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
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(hqdn3d)
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
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)
Definition: vf_hqdn3d.c:58
hqdn3d_options
static const AVOption hqdn3d_options[]
Definition: vf_hqdn3d.c:334
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
attributes.h
internal.h
denoise
#define denoise(...)
Definition: vf_hqdn3d.c:156
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
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
av_always_inline
#define av_always_inline
Definition: attributes.h:43
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
uint8_t
uint8_t
Definition: audio_convert.c:194
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)
Definition: vf_hqdn3d.c:80
LUMA_TMP
#define LUMA_TMP
Definition: vf_hqdn3d.h:43
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:386
CHROMA_SPATIAL
#define CHROMA_SPATIAL
Definition: vf_hqdn3d.h:44
AVFilter
Filter definition.
Definition: avfilter.h:144
avfilter_vf_hqdn3d_outputs
static const AVFilterPad avfilter_vf_hqdn3d_outputs[]
Definition: vf_hqdn3d.c:355
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
config.h
avfilter.h
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
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
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
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_hqdn3d.c:290
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:133
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
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_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038