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 "formats.h"
31 #include "internal.h"
32 #include "video.h"
33 
34 #define SIZE FF_BUFQUEUE_SIZE
35 
45 };
46 
47 typedef struct DeflickerContext {
48  const AVClass *class;
49 
50  int size;
51  int mode;
52  int bypass;
53 
54  int eof;
55  int depth;
56  int nb_planes;
57  int planewidth[4];
58  int planeheight[4];
59 
60  uint64_t *histogram;
61  float luminance[SIZE];
62  float sorted[SIZE];
63 
64  struct FFBufQueue q;
65  int available;
66 
67  void (*get_factor)(AVFilterContext *ctx, float *f);
69  int (*deflicker)(AVFilterContext *ctx, const uint8_t *src, ptrdiff_t src_linesize,
70  uint8_t *dst, ptrdiff_t dst_linesize, int w, int h, float f);
72 
73 #define OFFSET(x) offsetof(DeflickerContext, x)
74 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
75 
76 static const AVOption deflicker_options[] = {
77  { "size", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=5}, 2, SIZE, FLAGS },
78  { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=5}, 2, SIZE, FLAGS },
79  { "mode", "set how to smooth luminance", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SMOOTH_MODE-1, FLAGS, "mode" },
80  { "m", "set how to smooth luminance", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SMOOTH_MODE-1, FLAGS, "mode" },
81  { "am", "arithmetic mean", 0, AV_OPT_TYPE_CONST, {.i64=ARITHMETIC_MEAN}, 0, 0, FLAGS, "mode" },
82  { "gm", "geometric mean", 0, AV_OPT_TYPE_CONST, {.i64=GEOMETRIC_MEAN}, 0, 0, FLAGS, "mode" },
83  { "hm", "harmonic mean", 0, AV_OPT_TYPE_CONST, {.i64=HARMONIC_MEAN}, 0, 0, FLAGS, "mode" },
84  { "qm", "quadratic mean", 0, AV_OPT_TYPE_CONST, {.i64=QUADRATIC_MEAN}, 0, 0, FLAGS, "mode" },
85  { "cm", "cubic mean", 0, AV_OPT_TYPE_CONST, {.i64=CUBIC_MEAN}, 0, 0, FLAGS, "mode" },
86  { "pm", "power mean", 0, AV_OPT_TYPE_CONST, {.i64=POWER_MEAN}, 0, 0, FLAGS, "mode" },
87  { "median", "median", 0, AV_OPT_TYPE_CONST, {.i64=MEDIAN}, 0, 0, FLAGS, "mode" },
88  { "bypass", "leave frames unchanged", OFFSET(bypass), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
89  { NULL }
90 };
91 
92 AVFILTER_DEFINE_CLASS(deflicker);
93 
94 static const enum AVPixelFormat pixel_fmts[] = {
115 };
116 
118  const uint8_t *src, ptrdiff_t src_linesize,
119  uint8_t *dst, ptrdiff_t dst_linesize,
120  int w, int h, float f)
121 {
122  int x, y;
123 
124  for (y = 0; y < h; y++) {
125  for (x = 0; x < w; x++) {
126  dst[x] = av_clip_uint8(src[x] * f);
127  }
128 
129  dst += dst_linesize;
130  src += src_linesize;
131  }
132 
133  return 0;
134 }
135 
137  const uint8_t *ssrc, ptrdiff_t src_linesize,
138  uint8_t *ddst, ptrdiff_t dst_linesize,
139  int w, int h, float f)
140 {
141  DeflickerContext *s = ctx->priv;
142  const uint16_t *src = (const uint16_t *)ssrc;
143  uint16_t *dst = (uint16_t *)ddst;
144  const int max = (1 << s->depth) - 1;
145  int x, y;
146 
147  for (y = 0; y < h; y++) {
148  for (x = 0; x < w; x++) {
149  dst[x] = av_clip(src[x] * f, 0, max);
150  }
151 
152  dst += dst_linesize / 2;
153  src += src_linesize / 2;
154  }
155 
156  return 0;
157 }
158 
160 {
161  DeflickerContext *s = ctx->priv;
162  const uint8_t *src = in->data[0];
163  int64_t sum = 0;
164  int y, x;
165 
166  memset(s->histogram, 0, (1 << s->depth) * sizeof(*s->histogram));
167 
168  for (y = 0; y < s->planeheight[0]; y++) {
169  for (x = 0; x < s->planewidth[0]; x++) {
170  s->histogram[src[x]]++;
171  }
172  src += in->linesize[0];
173  }
174 
175  for (y = 0; y < 1 << s->depth; y++) {
176  sum += s->histogram[y] * y;
177  }
178 
179  return 1.0f * sum / (s->planeheight[0] * s->planewidth[0]);
180 }
181 
183 {
184  DeflickerContext *s = ctx->priv;
185  const uint16_t *src = (const uint16_t *)in->data[0];
186  int64_t sum = 0;
187  int y, x;
188 
189  memset(s->histogram, 0, (1 << s->depth) * sizeof(*s->histogram));
190 
191  for (y = 0; y < s->planeheight[0]; y++) {
192  for (x = 0; x < s->planewidth[0]; x++) {
193  s->histogram[src[x]]++;
194  }
195  src += in->linesize[0] / 2;
196  }
197 
198  for (y = 0; y < 1 << s->depth; y++) {
199  sum += s->histogram[y] * y;
200  }
201 
202  return 1.0f * sum / (s->planeheight[0] * s->planewidth[0]);
203 }
204 
205 static void get_am_factor(AVFilterContext *ctx, float *f)
206 {
207  DeflickerContext *s = ctx->priv;
208  int y;
209 
210  *f = 0.0f;
211 
212  for (y = 0; y < s->size; y++) {
213  *f += s->luminance[y];
214  }
215 
216  *f /= s->size;
217  *f /= s->luminance[0];
218 }
219 
220 static void get_gm_factor(AVFilterContext *ctx, float *f)
221 {
222  DeflickerContext *s = ctx->priv;
223  int y;
224 
225  *f = 1;
226 
227  for (y = 0; y < s->size; y++) {
228  *f *= s->luminance[y];
229  }
230 
231  *f = pow(*f, 1.0f / s->size);
232  *f /= s->luminance[0];
233 }
234 
235 static void get_hm_factor(AVFilterContext *ctx, float *f)
236 {
237  DeflickerContext *s = ctx->priv;
238  int y;
239 
240  *f = 0.0f;
241 
242  for (y = 0; y < s->size; y++) {
243  *f += 1.0f / s->luminance[y];
244  }
245 
246  *f = s->size / *f;
247  *f /= s->luminance[0];
248 }
249 
250 static void get_qm_factor(AVFilterContext *ctx, float *f)
251 {
252  DeflickerContext *s = ctx->priv;
253  int y;
254 
255  *f = 0.0f;
256 
257  for (y = 0; y < s->size; y++) {
258  *f += s->luminance[y] * s->luminance[y];
259  }
260 
261  *f /= s->size;
262  *f = sqrtf(*f);
263  *f /= s->luminance[0];
264 }
265 
266 static void get_cm_factor(AVFilterContext *ctx, float *f)
267 {
268  DeflickerContext *s = ctx->priv;
269  int y;
270 
271  *f = 0.0f;
272 
273  for (y = 0; y < s->size; y++) {
274  *f += s->luminance[y] * s->luminance[y] * s->luminance[y];
275  }
276 
277  *f /= s->size;
278  *f = cbrtf(*f);
279  *f /= s->luminance[0];
280 }
281 
282 static void get_pm_factor(AVFilterContext *ctx, float *f)
283 {
284  DeflickerContext *s = ctx->priv;
285  int y;
286 
287  *f = 0.0f;
288 
289  for (y = 0; y < s->size; y++) {
290  *f += powf(s->luminance[y], s->size);
291  }
292 
293  *f /= s->size;
294  *f = powf(*f, 1.0f / s->size);
295  *f /= s->luminance[0];
296 }
297 
298 static int comparef(const void *a, const void *b)
299 {
300  const float *aa = a, *bb = b;
301  return round(aa - bb);
302 }
303 
304 static void get_median_factor(AVFilterContext *ctx, float *f)
305 {
306  DeflickerContext *s = ctx->priv;
307 
308  memcpy(s->sorted, s->luminance, sizeof(s->sorted));
309  AV_QSORT(s->sorted, s->size, float, comparef);
310 
311  *f = s->sorted[s->size >> 1] / s->luminance[0];
312 }
313 
315 {
317  AVFilterContext *ctx = inlink->dst;
318  DeflickerContext *s = ctx->priv;
319 
320  s->nb_planes = desc->nb_components;
321 
322  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
323  s->planeheight[0] = s->planeheight[3] = inlink->h;
324  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
325  s->planewidth[0] = s->planewidth[3] = inlink->w;
326 
327  s->depth = desc->comp[0].depth;
328  if (s->depth == 8) {
329  s->deflicker = deflicker8;
330  s->calc_avgy = calc_avgy8;
331  } else {
332  s->deflicker = deflicker16;
333  s->calc_avgy = calc_avgy16;
334  }
335 
336  s->histogram = av_calloc(1 << s->depth, sizeof(*s->histogram));
337  if (!s->histogram)
338  return AVERROR(ENOMEM);
339 
340  switch (s->mode) {
341  case MEDIAN: s->get_factor = get_median_factor; break;
342  case ARITHMETIC_MEAN: s->get_factor = get_am_factor; break;
343  case GEOMETRIC_MEAN: s->get_factor = get_gm_factor; break;
344  case HARMONIC_MEAN: s->get_factor = get_hm_factor; break;
345  case QUADRATIC_MEAN: s->get_factor = get_qm_factor; break;
346  case CUBIC_MEAN: s->get_factor = get_cm_factor; break;
347  case POWER_MEAN: s->get_factor = get_pm_factor; break;
348  }
349 
350  return 0;
351 }
352 
354 {
355  AVFilterContext *ctx = inlink->dst;
356  AVFilterLink *outlink = ctx->outputs[0];
357  DeflickerContext *s = ctx->priv;
358  AVDictionary **metadata;
359  AVFrame *out, *in;
360  float f;
361  int y;
362 
363  if (s->q.available < s->size && !s->eof) {
364  s->luminance[s->available] = s->calc_avgy(ctx, buf);
365  ff_bufqueue_add(ctx, &s->q, buf);
366  s->available++;
367  return 0;
368  }
369 
370  in = ff_bufqueue_peek(&s->q, 0);
371 
372  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
373  if (!out) {
374  av_frame_free(&buf);
375  return AVERROR(ENOMEM);
376  }
377 
378  s->get_factor(ctx, &f);
379  if (!s->bypass)
380  s->deflicker(ctx, in->data[0], in->linesize[0], out->data[0], out->linesize[0],
381  outlink->w, outlink->h, f);
382  for (y = 1 - s->bypass; y < s->nb_planes; y++) {
383  av_image_copy_plane(out->data[y], out->linesize[y],
384  in->data[y], in->linesize[y],
385  s->planewidth[y] * (1 + (s->depth > 8)), s->planeheight[y]);
386  }
387 
389  metadata = &out->metadata;
390  if (metadata) {
391  uint8_t value[128];
392 
393  snprintf(value, sizeof(value), "%f", s->luminance[0]);
394  av_dict_set(metadata, "lavfi.deflicker.luminance", value, 0);
395 
396  snprintf(value, sizeof(value), "%f", s->luminance[0] * f);
397  av_dict_set(metadata, "lavfi.deflicker.new_luminance", value, 0);
398 
399  snprintf(value, sizeof(value), "%f", f - 1.0f);
400  av_dict_set(metadata, "lavfi.deflicker.relative_change", value, 0);
401  }
402 
403  in = ff_bufqueue_get(&s->q);
404  av_frame_free(&in);
405  memmove(&s->luminance[0], &s->luminance[1], sizeof(*s->luminance) * (s->size - 1));
406  s->luminance[s->available - 1] = s->calc_avgy(ctx, buf);
407  ff_bufqueue_add(ctx, &s->q, buf);
408 
409  return ff_filter_frame(outlink, out);
410 }
411 
412 static int request_frame(AVFilterLink *outlink)
413 {
414  AVFilterContext *ctx = outlink->src;
415  DeflickerContext *s = ctx->priv;
416  int ret;
417 
418  ret = ff_request_frame(ctx->inputs[0]);
419  if (ret == AVERROR_EOF && s->available > 0) {
420  AVFrame *buf = ff_bufqueue_peek(&s->q, s->available - 1);
421  if (!buf)
422  return AVERROR(ENOMEM);
423  buf = av_frame_clone(buf);
424  if (!buf)
425  return AVERROR(ENOMEM);
426 
427  s->eof = 1;
428  ret = filter_frame(ctx->inputs[0], buf);
429  s->available--;
430  }
431 
432  return ret;
433 }
434 
436 {
437  DeflickerContext *s = ctx->priv;
438 
440  av_freep(&s->histogram);
441 }
442 
443 static const AVFilterPad inputs[] = {
444  {
445  .name = "default",
446  .type = AVMEDIA_TYPE_VIDEO,
447  .filter_frame = filter_frame,
448  .config_props = config_input,
449  },
450 };
451 
452 static const AVFilterPad outputs[] = {
453  {
454  .name = "default",
455  .type = AVMEDIA_TYPE_VIDEO,
456  .request_frame = request_frame,
457  },
458 };
459 
461  .name = "deflicker",
462  .description = NULL_IF_CONFIG_SMALL("Remove temporal frame luminance variations."),
463  .priv_size = sizeof(DeflickerContext),
464  .priv_class = &deflicker_class,
465  .uninit = uninit,
469 };
GEOMETRIC_MEAN
@ GEOMETRIC_MEAN
Definition: vf_deflicker.c:38
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:98
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:447
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:220
DeflickerContext::luminance
float luminance[SIZE]
Definition: vf_deflicker.c:61
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:65
get_am_factor
static void get_am_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:205
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:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2660
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:171
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:298
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:439
DeflickerContext::eof
int eof
Definition: vf_deflicker.c:54
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:446
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:441
AVOption
AVOption.
Definition: opt.h:247
b
#define b
Definition: input.c:40
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:404
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:420
deflicker_options
static const AVOption deflicker_options[]
Definition: vf_deflicker.c:76
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:30
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:442
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:384
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:338
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
formats.h
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:438
OFFSET
#define OFFSET(x)
Definition: vf_deflicker.c:73
FLAGS
#define FLAGS
Definition: vf_deflicker.c:74
get_pm_factor
static void get_pm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:282
DeflickerContext::calc_avgy
float(* calc_avgy)(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:68
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:448
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:402
DeflickerContext::get_factor
void(* get_factor)(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:67
NB_SMOOTH_MODE
@ NB_SMOOTH_MODE
Definition: vf_deflicker.c:44
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:388
ARITHMETIC_MEAN
@ ARITHMETIC_MEAN
Definition: vf_deflicker.c:37
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:407
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:248
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:136
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:416
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:257
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:417
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:159
CUBIC_MEAN
@ CUBIC_MEAN
Definition: vf_deflicker.c:41
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:445
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:401
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:415
ctx
AVFormatContext * ctx
Definition: movenc.c:48
DeflickerContext::bypass
int bypass
Definition: vf_deflicker.c:52
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:387
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:422
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
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
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:58
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:385
DeflickerContext
Definition: vf_deflicker.c:47
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:537
ff_vf_deflicker
const AVFilter ff_vf_deflicker
Definition: vf_deflicker.c:460
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:51
src
#define src
Definition: vp8dsp.c:255
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:406
MEDIAN
@ MEDIAN
Definition: vf_deflicker.c:43
DeflickerContext::histogram
uint64_t * histogram
Definition: vf_deflicker.c:60
DeflickerContext::size
int size
Definition: vf_deflicker.c:50
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:405
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
outputs
static const AVFilterPad outputs[]
Definition: vf_deflicker.c:452
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: vf_deflicker.c:412
SIZE
#define SIZE
Definition: vf_deflicker.c:34
bufferqueue.h
qsort.h
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:117
powf
#define powf(x, y)
Definition: libm.h:50
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:409
size
int size
Definition: twinvq_data.h:10344
inputs
static const AVFilterPad inputs[]
Definition: vf_deflicker.c:443
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:411
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_deflicker.c:435
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:117
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:443
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:353
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(deflicker)
DeflickerContext::sorted
float sorted[SIZE]
Definition: vf_deflicker.c:62
internal.h
get_median_factor
static void get_median_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:304
QUADRATIC_MEAN
@ QUADRATIC_MEAN
Definition: vf_deflicker.c:40
POWER_MEAN
@ POWER_MEAN
Definition: vf_deflicker.c:42
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:56
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:403
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_deflicker.c:94
AVFilter
Filter definition.
Definition: avfilter.h:165
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:69
ret
ret
Definition: filter_design.txt:187
DeflickerContext::planewidth
int planewidth[4]
Definition: vf_deflicker.c:57
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:440
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:408
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:413
smooth_mode
smooth_mode
Definition: vf_deflicker.c:36
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:444
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
get_qm_factor
static void get_qm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:250
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:402
DeflickerContext::depth
int depth
Definition: vf_deflicker.c:55
desc
const char * desc
Definition: libsvtav1.c:79
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:266
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:70
DeflickerContext::nb_planes
int nb_planes
Definition: vf_deflicker.c:56
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:314
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:362
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:410
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:414
HARMONIC_MEAN
@ HARMONIC_MEAN
Definition: vf_deflicker.c:39
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:386
DeflickerContext::q
struct FFBufQueue q
Definition: vf_deflicker.c:64
int
int
Definition: ffmpeg_filter.c:153
calc_avgy16
static float calc_avgy16(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:182
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
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:235
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:412