FFmpeg
vf_deflicker.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/imgutils.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/pixdesc.h"
24 #include "libavutil/qsort.h"
25 #include "avfilter.h"
26 
27 #define FF_BUFQUEUE_SIZE 129
28 #include "bufferqueue.h"
29 
30 #include "internal.h"
31 #include "video.h"
32 
33 #define SIZE FF_BUFQUEUE_SIZE
34 
44 };
45 
46 typedef struct DeflickerContext {
47  const AVClass *class;
48 
49  int size;
50  int mode;
51  int bypass;
52 
53  int eof;
54  int depth;
55  int nb_planes;
56  int planewidth[4];
57  int planeheight[4];
58 
59  uint64_t *histogram;
60  float luminance[SIZE];
61  float sorted[SIZE];
62 
63  struct FFBufQueue q;
64  int available;
65 
66  void (*get_factor)(AVFilterContext *ctx, float *f);
68  int (*deflicker)(AVFilterContext *ctx, const uint8_t *src, ptrdiff_t src_linesize,
69  uint8_t *dst, ptrdiff_t dst_linesize, int w, int h, float f);
71 
72 #define OFFSET(x) offsetof(DeflickerContext, x)
73 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
74 
75 static const AVOption deflicker_options[] = {
76  { "size", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=5}, 2, SIZE, FLAGS },
77  { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=5}, 2, SIZE, FLAGS },
78  { "mode", "set how to smooth luminance", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SMOOTH_MODE-1, FLAGS, "mode" },
79  { "m", "set how to smooth luminance", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SMOOTH_MODE-1, FLAGS, "mode" },
80  { "am", "arithmetic mean", 0, AV_OPT_TYPE_CONST, {.i64=ARITHMETIC_MEAN}, 0, 0, FLAGS, "mode" },
81  { "gm", "geometric mean", 0, AV_OPT_TYPE_CONST, {.i64=GEOMETRIC_MEAN}, 0, 0, FLAGS, "mode" },
82  { "hm", "harmonic mean", 0, AV_OPT_TYPE_CONST, {.i64=HARMONIC_MEAN}, 0, 0, FLAGS, "mode" },
83  { "qm", "quadratic mean", 0, AV_OPT_TYPE_CONST, {.i64=QUADRATIC_MEAN}, 0, 0, FLAGS, "mode" },
84  { "cm", "cubic mean", 0, AV_OPT_TYPE_CONST, {.i64=CUBIC_MEAN}, 0, 0, FLAGS, "mode" },
85  { "pm", "power mean", 0, AV_OPT_TYPE_CONST, {.i64=POWER_MEAN}, 0, 0, FLAGS, "mode" },
86  { "median", "median", 0, AV_OPT_TYPE_CONST, {.i64=MEDIAN}, 0, 0, FLAGS, "mode" },
87  { "bypass", "leave frames unchanged", OFFSET(bypass), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
88  { NULL }
89 };
90 
91 AVFILTER_DEFINE_CLASS(deflicker);
92 
93 static const enum AVPixelFormat pixel_fmts[] = {
114 };
115 
117  const uint8_t *src, ptrdiff_t src_linesize,
118  uint8_t *dst, ptrdiff_t dst_linesize,
119  int w, int h, float f)
120 {
121  int x, y;
122 
123  for (y = 0; y < h; y++) {
124  for (x = 0; x < w; x++) {
125  dst[x] = av_clip_uint8(src[x] * f);
126  }
127 
128  dst += dst_linesize;
129  src += src_linesize;
130  }
131 
132  return 0;
133 }
134 
136  const uint8_t *ssrc, ptrdiff_t src_linesize,
137  uint8_t *ddst, ptrdiff_t dst_linesize,
138  int w, int h, float f)
139 {
140  DeflickerContext *s = ctx->priv;
141  const uint16_t *src = (const uint16_t *)ssrc;
142  uint16_t *dst = (uint16_t *)ddst;
143  const int max = (1 << s->depth) - 1;
144  int x, y;
145 
146  for (y = 0; y < h; y++) {
147  for (x = 0; x < w; x++) {
148  dst[x] = av_clip(src[x] * f, 0, max);
149  }
150 
151  dst += dst_linesize / 2;
152  src += src_linesize / 2;
153  }
154 
155  return 0;
156 }
157 
159 {
160  DeflickerContext *s = ctx->priv;
161  const uint8_t *src = in->data[0];
162  int64_t sum = 0;
163  int y, x;
164 
165  memset(s->histogram, 0, (1 << s->depth) * sizeof(*s->histogram));
166 
167  for (y = 0; y < s->planeheight[0]; y++) {
168  for (x = 0; x < s->planewidth[0]; x++) {
169  s->histogram[src[x]]++;
170  }
171  src += in->linesize[0];
172  }
173 
174  for (y = 0; y < 1 << s->depth; y++) {
175  sum += s->histogram[y] * y;
176  }
177 
178  return 1.0f * sum / (s->planeheight[0] * s->planewidth[0]);
179 }
180 
182 {
183  DeflickerContext *s = ctx->priv;
184  const uint16_t *src = (const uint16_t *)in->data[0];
185  int64_t sum = 0;
186  int y, x;
187 
188  memset(s->histogram, 0, (1 << s->depth) * sizeof(*s->histogram));
189 
190  for (y = 0; y < s->planeheight[0]; y++) {
191  for (x = 0; x < s->planewidth[0]; x++) {
192  s->histogram[src[x]]++;
193  }
194  src += in->linesize[0] / 2;
195  }
196 
197  for (y = 0; y < 1 << s->depth; y++) {
198  sum += s->histogram[y] * y;
199  }
200 
201  return 1.0f * sum / (s->planeheight[0] * s->planewidth[0]);
202 }
203 
204 static void get_am_factor(AVFilterContext *ctx, float *f)
205 {
206  DeflickerContext *s = ctx->priv;
207  int y;
208 
209  *f = 0.0f;
210 
211  for (y = 0; y < s->size; y++) {
212  *f += s->luminance[y];
213  }
214 
215  *f /= s->size;
216  *f /= s->luminance[0];
217 }
218 
219 static void get_gm_factor(AVFilterContext *ctx, float *f)
220 {
221  DeflickerContext *s = ctx->priv;
222  int y;
223 
224  *f = 1;
225 
226  for (y = 0; y < s->size; y++) {
227  *f *= s->luminance[y];
228  }
229 
230  *f = pow(*f, 1.0f / s->size);
231  *f /= s->luminance[0];
232 }
233 
234 static void get_hm_factor(AVFilterContext *ctx, float *f)
235 {
236  DeflickerContext *s = ctx->priv;
237  int y;
238 
239  *f = 0.0f;
240 
241  for (y = 0; y < s->size; y++) {
242  *f += 1.0f / s->luminance[y];
243  }
244 
245  *f = s->size / *f;
246  *f /= s->luminance[0];
247 }
248 
249 static void get_qm_factor(AVFilterContext *ctx, float *f)
250 {
251  DeflickerContext *s = ctx->priv;
252  int y;
253 
254  *f = 0.0f;
255 
256  for (y = 0; y < s->size; y++) {
257  *f += s->luminance[y] * s->luminance[y];
258  }
259 
260  *f /= s->size;
261  *f = sqrtf(*f);
262  *f /= s->luminance[0];
263 }
264 
265 static void get_cm_factor(AVFilterContext *ctx, float *f)
266 {
267  DeflickerContext *s = ctx->priv;
268  int y;
269 
270  *f = 0.0f;
271 
272  for (y = 0; y < s->size; y++) {
273  *f += s->luminance[y] * s->luminance[y] * s->luminance[y];
274  }
275 
276  *f /= s->size;
277  *f = cbrtf(*f);
278  *f /= s->luminance[0];
279 }
280 
281 static void get_pm_factor(AVFilterContext *ctx, float *f)
282 {
283  DeflickerContext *s = ctx->priv;
284  int y;
285 
286  *f = 0.0f;
287 
288  for (y = 0; y < s->size; y++) {
289  *f += powf(s->luminance[y], s->size);
290  }
291 
292  *f /= s->size;
293  *f = powf(*f, 1.0f / s->size);
294  *f /= s->luminance[0];
295 }
296 
297 static int comparef(const void *a, const void *b)
298 {
299  const float *aa = a, *bb = b;
300  return round(aa - bb);
301 }
302 
303 static void get_median_factor(AVFilterContext *ctx, float *f)
304 {
305  DeflickerContext *s = ctx->priv;
306 
307  memcpy(s->sorted, s->luminance, sizeof(s->sorted));
308  AV_QSORT(s->sorted, s->size, float, comparef);
309 
310  *f = s->sorted[s->size >> 1] / s->luminance[0];
311 }
312 
314 {
316  AVFilterContext *ctx = inlink->dst;
317  DeflickerContext *s = ctx->priv;
318 
319  s->nb_planes = desc->nb_components;
320 
321  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
322  s->planeheight[0] = s->planeheight[3] = inlink->h;
323  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
324  s->planewidth[0] = s->planewidth[3] = inlink->w;
325 
326  s->depth = desc->comp[0].depth;
327  if (s->depth == 8) {
328  s->deflicker = deflicker8;
329  s->calc_avgy = calc_avgy8;
330  } else {
331  s->deflicker = deflicker16;
332  s->calc_avgy = calc_avgy16;
333  }
334 
335  s->histogram = av_calloc(1 << s->depth, sizeof(*s->histogram));
336  if (!s->histogram)
337  return AVERROR(ENOMEM);
338 
339  switch (s->mode) {
340  case MEDIAN: s->get_factor = get_median_factor; break;
341  case ARITHMETIC_MEAN: s->get_factor = get_am_factor; break;
342  case GEOMETRIC_MEAN: s->get_factor = get_gm_factor; break;
343  case HARMONIC_MEAN: s->get_factor = get_hm_factor; break;
344  case QUADRATIC_MEAN: s->get_factor = get_qm_factor; break;
345  case CUBIC_MEAN: s->get_factor = get_cm_factor; break;
346  case POWER_MEAN: s->get_factor = get_pm_factor; break;
347  }
348 
349  return 0;
350 }
351 
353 {
354  AVFilterContext *ctx = inlink->dst;
355  AVFilterLink *outlink = ctx->outputs[0];
356  DeflickerContext *s = ctx->priv;
357  AVDictionary **metadata;
358  AVFrame *out, *in;
359  float f;
360  int y;
361 
362  if (s->q.available < s->size && !s->eof) {
363  s->luminance[s->available] = s->calc_avgy(ctx, buf);
364  ff_bufqueue_add(ctx, &s->q, buf);
365  s->available++;
366  return 0;
367  }
368 
369  in = ff_bufqueue_peek(&s->q, 0);
370 
371  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
372  if (!out) {
373  av_frame_free(&buf);
374  return AVERROR(ENOMEM);
375  }
376 
377  s->get_factor(ctx, &f);
378  if (!s->bypass)
379  s->deflicker(ctx, in->data[0], in->linesize[0], out->data[0], out->linesize[0],
380  outlink->w, outlink->h, f);
381  for (y = 1 - s->bypass; y < s->nb_planes; y++) {
382  av_image_copy_plane(out->data[y], out->linesize[y],
383  in->data[y], in->linesize[y],
384  s->planewidth[y] * (1 + (s->depth > 8)), s->planeheight[y]);
385  }
386 
388  metadata = &out->metadata;
389  if (metadata) {
390  uint8_t value[128];
391 
392  snprintf(value, sizeof(value), "%f", s->luminance[0]);
393  av_dict_set(metadata, "lavfi.deflicker.luminance", value, 0);
394 
395  snprintf(value, sizeof(value), "%f", s->luminance[0] * f);
396  av_dict_set(metadata, "lavfi.deflicker.new_luminance", value, 0);
397 
398  snprintf(value, sizeof(value), "%f", f - 1.0f);
399  av_dict_set(metadata, "lavfi.deflicker.relative_change", value, 0);
400  }
401 
402  in = ff_bufqueue_get(&s->q);
403  av_frame_free(&in);
404  memmove(&s->luminance[0], &s->luminance[1], sizeof(*s->luminance) * (s->size - 1));
405  s->luminance[s->available - 1] = s->calc_avgy(ctx, buf);
406  ff_bufqueue_add(ctx, &s->q, buf);
407 
408  return ff_filter_frame(outlink, out);
409 }
410 
411 static int request_frame(AVFilterLink *outlink)
412 {
413  AVFilterContext *ctx = outlink->src;
414  DeflickerContext *s = ctx->priv;
415  int ret;
416 
417  ret = ff_request_frame(ctx->inputs[0]);
418  if (ret == AVERROR_EOF && s->available > 0) {
419  AVFrame *buf = ff_bufqueue_peek(&s->q, s->available - 1);
420  if (!buf)
421  return AVERROR(ENOMEM);
422  buf = av_frame_clone(buf);
423  if (!buf)
424  return AVERROR(ENOMEM);
425 
426  s->eof = 1;
427  ret = filter_frame(ctx->inputs[0], buf);
428  s->available--;
429  }
430 
431  return ret;
432 }
433 
435 {
436  DeflickerContext *s = ctx->priv;
437 
439  av_freep(&s->histogram);
440 }
441 
442 static const AVFilterPad inputs[] = {
443  {
444  .name = "default",
445  .type = AVMEDIA_TYPE_VIDEO,
446  .filter_frame = filter_frame,
447  .config_props = config_input,
448  },
449 };
450 
451 static const AVFilterPad outputs[] = {
452  {
453  .name = "default",
454  .type = AVMEDIA_TYPE_VIDEO,
455  .request_frame = request_frame,
456  },
457 };
458 
460  .name = "deflicker",
461  .description = NULL_IF_CONFIG_SMALL("Remove temporal frame luminance variations."),
462  .priv_size = sizeof(DeflickerContext),
463  .priv_class = &deflicker_class,
464  .uninit = uninit,
468 };
GEOMETRIC_MEAN
@ GEOMETRIC_MEAN
Definition: vf_deflicker.c:37
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:108
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:512
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
av_clip
#define av_clip
Definition: common.h:96
get_gm_factor
static void get_gm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:219
DeflickerContext::luminance
float luminance[SIZE]
Definition: vf_deflicker.c:60
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
DeflickerContext::available
int available
Definition: vf_deflicker.c:64
get_am_factor
static void get_am_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:204
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:978
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:172
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
comparef
static int comparef(const void *a, const void *b)
Definition: vf_deflicker.c:297
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:504
DeflickerContext::eof
int eof
Definition: vf_deflicker.c:53
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:511
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:506
AVOption
AVOption.
Definition: opt.h:251
b
#define b
Definition: input.c:41
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:468
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:431
deflicker_options
static const AVOption deflicker_options[]
Definition: vf_deflicker.c:75
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
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVDictionary
Definition: dict.c:34
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:507
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:448
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
ff_bufqueue_get
static AVFrame * ff_bufqueue_get(struct FFBufQueue *queue)
Get the first buffer from the queue and remove it.
Definition: bufferqueue.h:98
av_image_copy_plane
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.
Definition: imgutils.c:374
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:503
OFFSET
#define OFFSET(x)
Definition: vf_deflicker.c:72
FLAGS
#define FLAGS
Definition: vf_deflicker.c:73
get_pm_factor
static void get_pm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:281
DeflickerContext::calc_avgy
float(* calc_avgy)(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:67
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:513
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:466
DeflickerContext::get_factor
void(* get_factor)(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:66
NB_SMOOTH_MODE
@ NB_SMOOTH_MODE
Definition: vf_deflicker.c:43
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:452
ARITHMETIC_MEAN
@ ARITHMETIC_MEAN
Definition: vf_deflicker.c:36
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:471
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:276
deflicker16
static int deflicker16(AVFilterContext *ctx, const uint8_t *ssrc, ptrdiff_t src_linesize, uint8_t *ddst, ptrdiff_t dst_linesize, int w, int h, float f)
Definition: vf_deflicker.c:135
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:480
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
float
float
Definition: af_crystalizer.c:121
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:481
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
calc_avgy8
static float calc_avgy8(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:158
CUBIC_MEAN
@ CUBIC_MEAN
Definition: vf_deflicker.c:40
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:510
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
ctx
AVFormatContext * ctx
Definition: movenc.c:48
DeflickerContext::bypass
int bypass
Definition: vf_deflicker.c:51
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:451
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:609
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
DeflickerContext::planeheight
int planeheight[4]
Definition: vf_deflicker.c:57
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:449
DeflickerContext
Definition: vf_deflicker.c:46
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
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:736
ff_vf_deflicker
const AVFilter ff_vf_deflicker
Definition: vf_deflicker.c:459
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
DeflickerContext::mode
int mode
Definition: vf_deflicker.c:50
ff_bufqueue_discard_all
static void ff_bufqueue_discard_all(struct FFBufQueue *queue)
Unref and remove all buffers from the queue.
Definition: bufferqueue.h:111
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:470
MEDIAN
@ MEDIAN
Definition: vf_deflicker.c:42
DeflickerContext::histogram
uint64_t * histogram
Definition: vf_deflicker.c:59
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
DeflickerContext::size
int size
Definition: vf_deflicker.c:49
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:469
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
outputs
static const AVFilterPad outputs[]
Definition: vf_deflicker.c:451
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: vf_deflicker.c:411
SIZE
#define SIZE
Definition: vf_deflicker.c:33
bufferqueue.h
qsort.h
f
f
Definition: af_crystalizer.c:121
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
powf
#define powf(x, y)
Definition: libm.h:50
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:473
size
int size
Definition: twinvq_data.h:10344
inputs
static const AVFilterPad inputs[]
Definition: vf_deflicker.c:442
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:475
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_deflicker.c:434
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
deflicker8
static int deflicker8(AVFilterContext *ctx, const uint8_t *src, ptrdiff_t src_linesize, uint8_t *dst, ptrdiff_t dst_linesize, int w, int h, float f)
Definition: vf_deflicker.c:116
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:508
ff_bufqueue_add
static void ff_bufqueue_add(void *log, struct FFBufQueue *queue, AVFrame *buf)
Add a buffer to the queue.
Definition: bufferqueue.h:71
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: vf_deflicker.c:352
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(deflicker)
DeflickerContext::sorted
float sorted[SIZE]
Definition: vf_deflicker.c:61
internal.h
get_median_factor
static void get_median_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:303
QUADRATIC_MEAN
@ QUADRATIC_MEAN
Definition: vf_deflicker.c:39
POWER_MEAN
@ POWER_MEAN
Definition: vf_deflicker.c:41
ff_bufqueue_peek
static AVFrame * ff_bufqueue_peek(struct FFBufQueue *queue, unsigned index)
Get a buffer from the queue without altering it.
Definition: bufferqueue.h:87
AV_QSORT
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
Definition: qsort.h:33
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
FFBufQueue
Structure holding the queue.
Definition: bufferqueue.h:49
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
cbrtf
static av_always_inline float cbrtf(float x)
Definition: libm.h:61
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
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:53
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:467
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_deflicker.c:93
AVFilter
Filter definition.
Definition: avfilter.h:166
DeflickerContext::deflicker
int(* deflicker)(AVFilterContext *ctx, const uint8_t *src, ptrdiff_t src_linesize, uint8_t *dst, ptrdiff_t dst_linesize, int w, int h, float f)
Definition: vf_deflicker.c:68
ret
ret
Definition: filter_design.txt:187
DeflickerContext::planewidth
int planewidth[4]
Definition: vf_deflicker.c:56
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:505
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
smooth_mode
smooth_mode
Definition: vf_deflicker.c:35
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:509
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
get_qm_factor
static void get_qm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:249
av_clip_uint8
#define av_clip_uint8
Definition: common.h:102
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:397
DeflickerContext::depth
int depth
Definition: vf_deflicker.c:54
desc
const char * desc
Definition: libsvtav1.c:83
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:69
get_cm_factor
static void get_cm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:265
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
DeflickerContext::nb_planes
int nb_planes
Definition: vf_deflicker.c:55
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
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_deflicker.c:313
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
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
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:478
HARMONIC_MEAN
@ HARMONIC_MEAN
Definition: vf_deflicker.c:38
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:450
DeflickerContext::q
struct FFBufQueue q
Definition: vf_deflicker.c:63
int
int
Definition: ffmpeg_filter.c:368
calc_avgy16
static float calc_avgy16(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:181
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:166
get_hm_factor
static void get_hm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:234
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:476