FFmpeg  4.3.6
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 
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 
93 
95 {
96  static const enum AVPixelFormat pixel_fmts[] = {
117  };
119  if (!formats)
120  return AVERROR(ENOMEM);
121  return ff_set_common_formats(ctx, formats);
122 }
123 
125  const uint8_t *src, ptrdiff_t src_linesize,
126  uint8_t *dst, ptrdiff_t dst_linesize,
127  int w, int h, float f)
128 {
129  int x, y;
130 
131  for (y = 0; y < h; y++) {
132  for (x = 0; x < w; x++) {
133  dst[x] = av_clip_uint8(src[x] * f);
134  }
135 
136  dst += dst_linesize;
137  src += src_linesize;
138  }
139 
140  return 0;
141 }
142 
144  const uint8_t *ssrc, ptrdiff_t src_linesize,
145  uint8_t *ddst, ptrdiff_t dst_linesize,
146  int w, int h, float f)
147 {
148  DeflickerContext *s = ctx->priv;
149  const uint16_t *src = (const uint16_t *)ssrc;
150  uint16_t *dst = (uint16_t *)ddst;
151  const int max = (1 << s->depth) - 1;
152  int x, y;
153 
154  for (y = 0; y < h; y++) {
155  for (x = 0; x < w; x++) {
156  dst[x] = av_clip(src[x] * f, 0, max);
157  }
158 
159  dst += dst_linesize / 2;
160  src += src_linesize / 2;
161  }
162 
163  return 0;
164 }
165 
167 {
168  DeflickerContext *s = ctx->priv;
169  const uint8_t *src = in->data[0];
170  int64_t sum = 0;
171  int y, x;
172 
173  memset(s->histogram, 0, (1 << s->depth) * sizeof(*s->histogram));
174 
175  for (y = 0; y < s->planeheight[0]; y++) {
176  for (x = 0; x < s->planewidth[0]; x++) {
177  s->histogram[src[x]]++;
178  }
179  src += in->linesize[0];
180  }
181 
182  for (y = 0; y < 1 << s->depth; y++) {
183  sum += s->histogram[y] * y;
184  }
185 
186  return 1.0f * sum / (s->planeheight[0] * s->planewidth[0]);
187 }
188 
190 {
191  DeflickerContext *s = ctx->priv;
192  const uint16_t *src = (const uint16_t *)in->data[0];
193  int64_t sum = 0;
194  int y, x;
195 
196  memset(s->histogram, 0, (1 << s->depth) * sizeof(*s->histogram));
197 
198  for (y = 0; y < s->planeheight[0]; y++) {
199  for (x = 0; x < s->planewidth[0]; x++) {
200  s->histogram[src[x]]++;
201  }
202  src += in->linesize[0] / 2;
203  }
204 
205  for (y = 0; y < 1 << s->depth; y++) {
206  sum += s->histogram[y] * y;
207  }
208 
209  return 1.0f * sum / (s->planeheight[0] * s->planewidth[0]);
210 }
211 
212 static void get_am_factor(AVFilterContext *ctx, float *f)
213 {
214  DeflickerContext *s = ctx->priv;
215  int y;
216 
217  *f = 0.0f;
218 
219  for (y = 0; y < s->size; y++) {
220  *f += s->luminance[y];
221  }
222 
223  *f /= s->size;
224  *f /= s->luminance[0];
225 }
226 
227 static void get_gm_factor(AVFilterContext *ctx, float *f)
228 {
229  DeflickerContext *s = ctx->priv;
230  int y;
231 
232  *f = 1;
233 
234  for (y = 0; y < s->size; y++) {
235  *f *= s->luminance[y];
236  }
237 
238  *f = pow(*f, 1.0f / s->size);
239  *f /= s->luminance[0];
240 }
241 
242 static void get_hm_factor(AVFilterContext *ctx, float *f)
243 {
244  DeflickerContext *s = ctx->priv;
245  int y;
246 
247  *f = 0.0f;
248 
249  for (y = 0; y < s->size; y++) {
250  *f += 1.0f / s->luminance[y];
251  }
252 
253  *f = s->size / *f;
254  *f /= s->luminance[0];
255 }
256 
257 static void get_qm_factor(AVFilterContext *ctx, float *f)
258 {
259  DeflickerContext *s = ctx->priv;
260  int y;
261 
262  *f = 0.0f;
263 
264  for (y = 0; y < s->size; y++) {
265  *f += s->luminance[y] * s->luminance[y];
266  }
267 
268  *f /= s->size;
269  *f = sqrtf(*f);
270  *f /= s->luminance[0];
271 }
272 
273 static void get_cm_factor(AVFilterContext *ctx, float *f)
274 {
275  DeflickerContext *s = ctx->priv;
276  int y;
277 
278  *f = 0.0f;
279 
280  for (y = 0; y < s->size; y++) {
281  *f += s->luminance[y] * s->luminance[y] * s->luminance[y];
282  }
283 
284  *f /= s->size;
285  *f = cbrtf(*f);
286  *f /= s->luminance[0];
287 }
288 
289 static void get_pm_factor(AVFilterContext *ctx, float *f)
290 {
291  DeflickerContext *s = ctx->priv;
292  int y;
293 
294  *f = 0.0f;
295 
296  for (y = 0; y < s->size; y++) {
297  *f += powf(s->luminance[y], s->size);
298  }
299 
300  *f /= s->size;
301  *f = powf(*f, 1.0f / s->size);
302  *f /= s->luminance[0];
303 }
304 
305 static int comparef(const void *a, const void *b)
306 {
307  const float *aa = a, *bb = b;
308  return round(aa - bb);
309 }
310 
311 static void get_median_factor(AVFilterContext *ctx, float *f)
312 {
313  DeflickerContext *s = ctx->priv;
314 
315  memcpy(s->sorted, s->luminance, sizeof(s->sorted));
316  AV_QSORT(s->sorted, s->size, float, comparef);
317 
318  *f = s->sorted[s->size >> 1] / s->luminance[0];
319 }
320 
321 static int config_input(AVFilterLink *inlink)
322 {
324  AVFilterContext *ctx = inlink->dst;
325  DeflickerContext *s = ctx->priv;
326 
327  s->nb_planes = desc->nb_components;
328 
329  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
330  s->planeheight[0] = s->planeheight[3] = inlink->h;
331  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
332  s->planewidth[0] = s->planewidth[3] = inlink->w;
333 
334  s->depth = desc->comp[0].depth;
335  if (s->depth == 8) {
336  s->deflicker = deflicker8;
337  s->calc_avgy = calc_avgy8;
338  } else {
339  s->deflicker = deflicker16;
340  s->calc_avgy = calc_avgy16;
341  }
342 
343  s->histogram = av_calloc(1 << s->depth, sizeof(*s->histogram));
344  if (!s->histogram)
345  return AVERROR(ENOMEM);
346 
347  switch (s->mode) {
348  case MEDIAN: s->get_factor = get_median_factor; break;
349  case ARITHMETIC_MEAN: s->get_factor = get_am_factor; break;
350  case GEOMETRIC_MEAN: s->get_factor = get_gm_factor; break;
351  case HARMONIC_MEAN: s->get_factor = get_hm_factor; break;
352  case QUADRATIC_MEAN: s->get_factor = get_qm_factor; break;
353  case CUBIC_MEAN: s->get_factor = get_cm_factor; break;
354  case POWER_MEAN: s->get_factor = get_pm_factor; break;
355  }
356 
357  return 0;
358 }
359 
360 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
361 {
362  AVFilterContext *ctx = inlink->dst;
363  AVFilterLink *outlink = ctx->outputs[0];
364  DeflickerContext *s = ctx->priv;
365  AVDictionary **metadata;
366  AVFrame *out, *in;
367  float f;
368  int y;
369 
370  if (s->q.available < s->size && !s->eof) {
371  s->luminance[s->available] = s->calc_avgy(ctx, buf);
372  ff_bufqueue_add(ctx, &s->q, buf);
373  s->available++;
374  return 0;
375  }
376 
377  in = ff_bufqueue_peek(&s->q, 0);
378 
379  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
380  if (!out) {
381  av_frame_free(&buf);
382  return AVERROR(ENOMEM);
383  }
384 
385  s->get_factor(ctx, &f);
386  if (!s->bypass)
387  s->deflicker(ctx, in->data[0], in->linesize[0], out->data[0], out->linesize[0],
388  outlink->w, outlink->h, f);
389  for (y = 1 - s->bypass; y < s->nb_planes; y++) {
390  av_image_copy_plane(out->data[y], out->linesize[y],
391  in->data[y], in->linesize[y],
392  s->planewidth[y] * (1 + (s->depth > 8)), s->planeheight[y]);
393  }
394 
395  av_frame_copy_props(out, in);
396  metadata = &out->metadata;
397  if (metadata) {
398  uint8_t value[128];
399 
400  snprintf(value, sizeof(value), "%f", s->luminance[0]);
401  av_dict_set(metadata, "lavfi.deflicker.luminance", value, 0);
402 
403  snprintf(value, sizeof(value), "%f", s->luminance[0] * f);
404  av_dict_set(metadata, "lavfi.deflicker.new_luminance", value, 0);
405 
406  snprintf(value, sizeof(value), "%f", f - 1.0f);
407  av_dict_set(metadata, "lavfi.deflicker.relative_change", value, 0);
408  }
409 
410  in = ff_bufqueue_get(&s->q);
411  av_frame_free(&in);
412  memmove(&s->luminance[0], &s->luminance[1], sizeof(*s->luminance) * (s->size - 1));
413  s->luminance[s->available - 1] = s->calc_avgy(ctx, buf);
414  ff_bufqueue_add(ctx, &s->q, buf);
415 
416  return ff_filter_frame(outlink, out);
417 }
418 
419 static int request_frame(AVFilterLink *outlink)
420 {
421  AVFilterContext *ctx = outlink->src;
422  DeflickerContext *s = ctx->priv;
423  int ret;
424 
425  ret = ff_request_frame(ctx->inputs[0]);
426  if (ret == AVERROR_EOF && s->available > 0) {
427  AVFrame *buf = ff_bufqueue_peek(&s->q, s->available - 1);
428  if (!buf)
429  return AVERROR(ENOMEM);
430  buf = av_frame_clone(buf);
431  if (!buf)
432  return AVERROR(ENOMEM);
433 
434  s->eof = 1;
435  ret = filter_frame(ctx->inputs[0], buf);
436  s->available--;
437  }
438 
439  return ret;
440 }
441 
443 {
444  DeflickerContext *s = ctx->priv;
445 
447  av_freep(&s->histogram);
448 }
449 
450 static const AVFilterPad inputs[] = {
451  {
452  .name = "default",
453  .type = AVMEDIA_TYPE_VIDEO,
454  .filter_frame = filter_frame,
455  .config_props = config_input,
456  },
457  { NULL }
458 };
459 
460 static const AVFilterPad outputs[] = {
461  {
462  .name = "default",
463  .type = AVMEDIA_TYPE_VIDEO,
464  .request_frame = request_frame,
465  },
466  { NULL }
467 };
468 
470  .name = "deflicker",
471  .description = NULL_IF_CONFIG_SMALL("Remove temporal frame luminance variations."),
472  .priv_size = sizeof(DeflickerContext),
473  .priv_class = &deflicker_class,
474  .uninit = uninit,
476  .inputs = inputs,
477  .outputs = outputs,
478 };
static AVFrame * ff_bufqueue_get(struct FFBufQueue *queue)
Get the first buffer from the queue and remove it.
Definition: bufferqueue.h:98
#define NULL
Definition: coverity.c:32
static int comparef(const void *a, const void *b)
Definition: vf_deflicker.c:305
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:440
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:432
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
static void get_hm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:242
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:434
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:407
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:435
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:79
static void get_am_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:212
const char * b
Definition: vf_curves.c:116
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:377
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:401
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
#define OFFSET(x)
Definition: vf_deflicker.c:73
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
#define FLAGS
Definition: vf_deflicker.c:74
static const AVOption deflicker_options[]
Definition: vf_deflicker.c:76
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:300
Structure holding the queue.
Definition: bufferqueue.h:49
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:378
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:379
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:88
AVOptions.
#define f(width, name)
Definition: cbs_vp9.c:255
float(* calc_avgy)(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:68
static void get_pm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:289
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:431
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVDictionary * metadata
metadata.
Definition: frame.h:586
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:410
#define max(a, b)
Definition: cuda_runtime.h:33
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:402
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:439
A filter pad used for either input or output.
Definition: internal.h:54
#define src
Definition: vp8dsp.c:254
#define SIZE
Definition: vf_deflicker.c:34
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
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:143
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:605
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:188
static int request_frame(AVFilterLink *outlink)
Definition: vf_deflicker.c:419
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:441
static float calc_avgy8(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:166
static av_always_inline av_const double round(double x)
Definition: libm.h:444
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:400
void(* get_factor)(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:67
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_deflicker.c:442
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define powf(x, y)
Definition: libm.h:50
static const AVFilterPad outputs[]
Definition: vf_deflicker.c:460
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:395
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:381
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:438
uint8_t w
Definition: llviddspenc.c:38
AVFormatContext * ctx
Definition: movenc.c:48
uint64_t * histogram
Definition: vf_deflicker.c:60
#define s(width, name)
Definition: cbs_vp9.c:257
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:436
static void ff_bufqueue_discard_all(struct FFBufQueue *queue)
Unref and remove all buffers from the queue.
Definition: bufferqueue.h:111
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:396
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:541
static int query_formats(AVFilterContext *ctx)
Definition: vf_deflicker.c:94
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:408
static void get_median_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:311
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:405
typedef void(RENAME(mix_any_func_type))
unsigned short available
number of available buffers
Definition: bufferqueue.h:52
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:331
static const AVFilterPad inputs[]
Definition: vf_deflicker.c:450
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:380
static av_always_inline float cbrtf(float x)
Definition: libm.h:61
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
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
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)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:397
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
double value
Definition: eval.c:98
Describe the class of an AVClass context structure.
Definition: log.h:67
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: vf_deflicker.c:360
Filter definition.
Definition: avfilter.h:144
AVFILTER_DEFINE_CLASS(deflicker)
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:394
#define snprintf
Definition: snprintf.h:34
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static int config_input(AVFilterLink *inlink)
Definition: vf_deflicker.c:321
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:404
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
smooth_mode
Definition: vf_deflicker.c:36
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
static float calc_avgy16(AVFilterContext *ctx, AVFrame *in)
Definition: vf_deflicker.c:189
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:124
float sorted[SIZE]
Definition: vf_deflicker.c:62
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:433
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
A list of supported formats for one end of a filter link.
Definition: formats.h:64
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
struct FFBufQueue q
Definition: vf_deflicker.c:64
An instance of a filter.
Definition: avfilter.h:338
static void get_qm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:257
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
static void ff_bufqueue_add(void *log, struct FFBufQueue *queue, AVFrame *buf)
Add a buffer to the queue.
Definition: bufferqueue.h:71
AVFilter ff_vf_deflicker
Definition: vf_deflicker.c:469
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:407
formats
Definition: signature.h:48
static void get_cm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:273
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:338
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
float luminance[SIZE]
Definition: vf_deflicker.c:61
static void get_gm_factor(AVFilterContext *ctx, float *f)
Definition: vf_deflicker.c:227
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:409
#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
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:437
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
static AVFrame * ff_bufqueue_peek(struct FFBufQueue *queue, unsigned index)
Get a buffer from the queue without altering it.
Definition: bufferqueue.h:87