FFmpeg
vf_estdif.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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/common.h"
22 #include "libavutil/imgutils.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/pixdesc.h"
25 #include "avfilter.h"
26 #include "formats.h"
27 #include "internal.h"
28 #include "video.h"
29 
30 typedef struct ESTDIFContext {
31  const AVClass *class;
32 
33  int mode; ///< 0 is frame, 1 is field
34  int parity; ///< frame field parity
35  int deint; ///< which frames to deinterlace
36  int rslope; ///< best edge slope search radius
37  int redge; ///< best edge match search radius
38  int ecost; ///< edge cost for edge matching
39  int mcost; ///< middle cost for edge matching
40  int dcost; ///< distance cost for edge matching
41  int interp; ///< type of interpolation
42  int linesize[4]; ///< bytes of pixel data per line for each plane
43  int planewidth[4]; ///< width of each plane
44  int planeheight[4]; ///< height of each plane
45  int field; ///< which field are we on, 0 or 1
46  int eof;
47  int depth;
48  int max;
49  int nb_planes;
52 
53  void (*interpolate)(struct ESTDIFContext *s, uint8_t *dst,
54  const uint8_t *prev_line, const uint8_t *next_line,
55  const uint8_t *prev2_line, const uint8_t *next2_line,
56  const uint8_t *prev3_line, const uint8_t *next3_line,
57  int x, int width, int rslope, int redge,
58  int depth, int *K);
59 
60  unsigned (*mid_8[3])(const uint8_t *const prev,
61  const uint8_t *const next,
62  const uint8_t *const prev2,
63  const uint8_t *const next2,
64  const uint8_t *const prev3,
65  const uint8_t *const next3,
66  int end, int x, int k, int depth);
67 
68  unsigned (*mid_16[3])(const uint16_t *const prev,
69  const uint16_t *const next,
70  const uint16_t *const prev2,
71  const uint16_t *const next2,
72  const uint16_t *const prev3,
73  const uint16_t *const next3,
74  int end, int x, int k, int depth);
76 
77 #define MAX_R 15
78 #define S (MAX_R * 2 + 1)
79 
80 #define OFFSET(x) offsetof(ESTDIFContext, x)
81 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
82 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
83 
84 static const AVOption estdif_options[] = {
85  { "mode", "specify the mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
86  CONST("frame", "send one frame for each frame", 0, "mode"),
87  CONST("field", "send one frame for each field", 1, "mode"),
88  { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS, "parity" },
89  CONST("tff", "assume top field first", 0, "parity"),
90  CONST("bff", "assume bottom field first", 1, "parity"),
91  CONST("auto", "auto detect parity", -1, "parity"),
92  { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "deint" },
93  CONST("all", "deinterlace all frames", 0, "deint"),
94  CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
95  { "rslope", "specify the search radius for edge slope tracing", OFFSET(rslope), AV_OPT_TYPE_INT, {.i64=1}, 1, MAX_R, FLAGS },
96  { "redge", "specify the search radius for best edge matching", OFFSET(redge), AV_OPT_TYPE_INT, {.i64=2}, 0, MAX_R, FLAGS },
97  { "ecost", "specify the edge cost for edge matching", OFFSET(ecost), AV_OPT_TYPE_INT, {.i64=2}, 0, 50, FLAGS },
98  { "mcost", "specify the middle cost for edge matching", OFFSET(mcost), AV_OPT_TYPE_INT, {.i64=1}, 0, 50, FLAGS },
99  { "dcost", "specify the distance cost for edge matching", OFFSET(dcost), AV_OPT_TYPE_INT, {.i64=1}, 0, 50, FLAGS },
100  { "interp", "specify the type of interpolation", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, FLAGS, "interp" },
101  CONST("2p", "two-point interpolation", 0, "interp"),
102  CONST("4p", "four-point interpolation", 1, "interp"),
103  CONST("6p", "six-point interpolation", 2, "interp"),
104  { NULL }
105 };
106 
107 AVFILTER_DEFINE_CLASS(estdif);
108 
109 static const enum AVPixelFormat pix_fmts[] = {
133 };
134 
135 static int config_output(AVFilterLink *outlink)
136 {
137  AVFilterContext *ctx = outlink->src;
138  AVFilterLink *inlink = ctx->inputs[0];
139  ESTDIFContext *s = ctx->priv;
140 
141  outlink->time_base = av_mul_q(inlink->time_base, (AVRational){1, 2});
142  if (s->mode)
143  outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){2, 1});
144 
145  return 0;
146 }
147 
148 typedef struct ThreadData {
149  AVFrame *out, *in;
150 } ThreadData;
151 
152 #define MIDL(type, ss) \
153 static unsigned midl_##ss(const type *const prev, \
154  const type *const next, \
155  int end, int x, int k) \
156 { \
157  return (prev[av_clip(x + k, 0, end)] + \
158  next[av_clip(x - k, 0, end)] + 1) >> 1; \
159 }
160 
161 MIDL(uint8_t, 8)
162 MIDL(uint16_t, 16)
163 
164 #define MID2(type, ss) \
165 static unsigned mid2_##ss(const type *const prev, \
166  const type *const next, \
167  const type *const prev2, \
168  const type *const next2, \
169  const type *const prev3, \
170  const type *const next3, \
171  int end, int x, int k, int depth) \
172 { \
173  return (prev[av_clip(x + k, 0, end)] + \
174  next[av_clip(x - k, 0, end)] + 1) >> 1; \
175 }
176 
177 MID2(uint8_t, 8)
178 MID2(uint16_t, 16)
179 
180 #define MID4(type, ss) \
181 static unsigned mid4_##ss(const type *const prev, \
182  const type *const next, \
183  const type *const prev2, \
184  const type *const next2, \
185  const type *const prev3, \
186  const type *const next3, \
187  int end, int x, int k, int depth) \
188 { \
189  return av_clip_uintp2_c(( \
190  9 * (prev[av_clip(x + k, 0, end)] + \
191  next[av_clip(x - k, 0, end)]) - \
192  1 * (prev2[av_clip(x + k*3, 0, end)] + \
193  next2[av_clip(x - k*3, 0, end)]) + 8) >> 4, \
194  depth); \
195 }
196 
197 MID4(uint8_t, 8)
198 MID4(uint16_t, 16)
199 
200 #define MID6(type, ss) \
201 static unsigned mid6_##ss(const type *const prev, \
202  const type *const next, \
203  const type *const prev2, \
204  const type *const next2, \
205  const type *const prev3, \
206  const type *const next3, \
207  int end, int x, int k, int depth) \
208 { \
209  return av_clip_uintp2_c(( \
210  20 * (prev[av_clip(x + k, 0, end)] + \
211  next[av_clip(x - k, 0, end)]) - \
212  5 * (prev2[av_clip(x + k*3, 0, end)] + \
213  next2[av_clip(x - k*3, 0, end)]) + \
214  1 * (prev3[av_clip(x + k*5, 0, end)] + \
215  next3[av_clip(x - k*5, 0, end)]) + 16) >> 5, \
216  depth); \
217 }
218 
219 MID6(uint8_t, 8)
220 MID6(uint16_t, 16)
221 
222 #define DIFF(type, ss) \
223 static unsigned diff_##ss(const type *const prev, \
224  const type *const next, \
225  int x, int y) \
226 { \
227  return FFABS(prev[x] - next[y]); \
228 }
229 
230 DIFF(uint8_t, 8)
231 DIFF(uint16_t, 16)
232 
233 #define COST(type, ss) \
234 static unsigned cost_##ss(const type *const prev, \
235  const type *const next, \
236  int end, int x, int k) \
237 { \
238  const int m = midl_##ss(prev, next, end, x, k); \
239  const int p = prev[x]; \
240  const int n = next[x]; \
241  \
242  return FFABS(p - m) + FFABS(n - m); \
243 }
244 
245 COST(uint8_t, 8)
246 COST(uint16_t, 16)
247 
248 #define INTERPOLATE(type, atype, amax, ss) \
249 static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \
250  const uint8_t *const pprev_line, \
251  const uint8_t *const nnext_line, \
252  const uint8_t *const pprev2_line, \
253  const uint8_t *const nnext2_line, \
254  const uint8_t *const pprev3_line, \
255  const uint8_t *const nnext3_line, \
256  int x, int width, int rslope, \
257  int redge, int depth, \
258  int *K) \
259 { \
260  type *dst = (type *)ddst; \
261  const type *const prev_line = (const type *const)pprev_line; \
262  const type *const prev2_line = (const type *const)pprev2_line; \
263  const type *const prev3_line = (const type *const)pprev3_line; \
264  const type *const next_line = (const type *const)nnext_line; \
265  const type *const next2_line = (const type *const)nnext2_line; \
266  const type *const next3_line = (const type *const)nnext3_line; \
267  const int interp = s->interp; \
268  const int ecost = s->ecost; \
269  const int dcost = s->dcost; \
270  const int mcost = s->mcost; \
271  atype sd[S], sD[S], di = 0; \
272  const int end = width - 1; \
273  atype dmin = amax; \
274  int id = 0, iD = 0; \
275  int k = *K; \
276  \
277  for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) { \
278  atype sum = 0; \
279  \
280  for (int j = -redge; j <= redge; j++) { \
281  const int xx = av_clip(x + i + j, 0, end); \
282  const int yy = av_clip(x - i + j, 0, end); \
283  sum += diff_##ss(prev_line, next_line, xx, yy); \
284  sum += diff_##ss(prev2_line, prev_line, xx, yy); \
285  sum += diff_##ss(next_line, next2_line, xx, yy); \
286  } \
287  \
288  sD[i + rslope] = ecost * sum; \
289  sD[i + rslope] += mcost * cost_##ss(prev_line, next_line, end, x, i);\
290  sD[i + rslope] += dcost * abs(i); \
291  \
292  if (dmin > sD[i + rslope]) { \
293  dmin = sD[i + rslope]; \
294  di = 1; \
295  iD = i; \
296  } \
297  } \
298  \
299  for (int i = -rslope; i <= rslope; i++) { \
300  atype sum = 0; \
301  \
302  for (int j = -redge; j <= redge; j++) { \
303  const int xx = av_clip(x + k + i + j, 0, end); \
304  const int yy = av_clip(x - k - i + j, 0, end); \
305  sum += diff_##ss(prev_line, next_line, xx, yy); \
306  sum += diff_##ss(prev2_line, prev_line, xx, yy); \
307  sum += diff_##ss(next_line, next2_line, xx, yy); \
308  } \
309  \
310  sd[i + rslope] = ecost * sum; \
311  sd[i + rslope] += mcost * cost_##ss(prev_line, next_line, end, x, k+i);\
312  sd[i + rslope] += dcost * abs(k + i); \
313  \
314  if (dmin > sd[i + rslope]) { \
315  dmin = sd[i + rslope]; \
316  di = 0; \
317  id = i; \
318  } \
319  } \
320  \
321  k = di ? iD : k + id; \
322  \
323  dst[x] = s->mid_##ss[interp](prev_line, next_line, \
324  prev2_line, next2_line, \
325  prev3_line, next3_line, \
326  end, x, k, depth); \
327  \
328  *K = k; \
329 }
330 
331 INTERPOLATE(uint8_t, unsigned, UINT_MAX, 8)
332 INTERPOLATE(uint16_t, uint64_t, UINT64_MAX, 16)
333 
335  int jobnr, int nb_jobs)
336 {
337  ESTDIFContext *s = ctx->priv;
338  ThreadData *td = arg;
339  AVFrame *out = td->out;
340  AVFrame *in = td->in;
341  const int rslope = s->rslope;
342  const int redge = s->redge;
343  const int depth = s->depth;
344  const int interlaced = !!(in->flags & AV_FRAME_FLAG_INTERLACED);
345  const int tff = (s->field == (s->parity == -1 ? interlaced ? !!(in->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) : 1 :
346  s->parity ^ 1));
347 
348  for (int plane = 0; plane < s->nb_planes; plane++) {
349  const uint8_t *src_data = in->data[plane];
350  uint8_t *dst_data = out->data[plane];
351  const int linesize = s->linesize[plane];
352  const int width = s->planewidth[plane];
353  const int height = s->planeheight[plane];
354  const int src_linesize = in->linesize[plane];
355  const int dst_linesize = out->linesize[plane];
356  const int start = (height * jobnr) / nb_jobs;
357  const int end = (height * (jobnr+1)) / nb_jobs;
358  const uint8_t *prev_line, *prev2_line, *next_line, *next2_line, *in_line;
359  const uint8_t *prev3_line, *next3_line;
360  uint8_t *out_line;
361  int y_out;
362 
363  y_out = start + (tff ^ (start & 1));
364 
365  in_line = src_data + (y_out * src_linesize);
366  out_line = dst_data + (y_out * dst_linesize);
367 
368  while (y_out < end) {
369  memcpy(out_line, in_line, linesize);
370  y_out += 2;
371  in_line += src_linesize * 2;
372  out_line += dst_linesize * 2;
373  }
374 
375  y_out = start + ((!tff) ^ (start & 1));
376  out_line = dst_data + (y_out * dst_linesize);
377 
378  for (int y = y_out; y < end; y += 2) {
379  int y_prev3_in = y - 5;
380  int y_next3_in = y + 5;
381  int y_prev2_in = y - 3;
382  int y_next2_in = y + 3;
383  int y_prev_in = y - 1;
384  int y_next_in = y + 1;
385  int k;
386 
387  while (y_prev3_in < 0)
388  y_prev3_in += 2;
389 
390  while (y_next3_in >= height)
391  y_next3_in -= 2;
392 
393  while (y_prev2_in < 0)
394  y_prev2_in += 2;
395 
396  while (y_next2_in >= height)
397  y_next2_in -= 2;
398 
399  while (y_prev_in < 0)
400  y_prev_in += 2;
401 
402  while (y_next_in >= height)
403  y_next_in -= 2;
404 
405  prev3_line = src_data + (y_prev3_in * src_linesize);
406  next3_line = src_data + (y_next3_in * src_linesize);
407 
408  prev2_line = src_data + (y_prev2_in * src_linesize);
409  next2_line = src_data + (y_next2_in * src_linesize);
410 
411  prev_line = src_data + (y_prev_in * src_linesize);
412  next_line = src_data + (y_next_in * src_linesize);
413 
414  k = 0;
415 
416  for (int x = 0; x < width; x++) {
417  s->interpolate(s, out_line,
418  prev_line, next_line,
419  prev2_line, next2_line,
420  prev3_line, next3_line,
421  x, width, rslope, redge, depth, &k);
422  }
423 
424  out_line += 2 * dst_linesize;
425  }
426  }
427 
428  return 0;
429 }
430 
431 static int filter(AVFilterContext *ctx, AVFrame *in, int64_t pts, int64_t duration)
432 {
433  ESTDIFContext *s = ctx->priv;
434  AVFilterLink *outlink = ctx->outputs[0];
435  AVFrame *out;
436  ThreadData td;
437 
438  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
439  if (!out)
440  return AVERROR(ENOMEM);
442 #if FF_API_INTERLACED_FRAME
444  out->interlaced_frame = 0;
446 #endif
447  out->flags &= ~AV_FRAME_FLAG_INTERLACED;
448  out->pts = pts;
449  out->duration = duration;
450 
451  td.out = out; td.in = in;
453  FFMIN(s->planeheight[1] / 2, s->nb_threads));
454 
455  if (s->mode)
456  s->field = !s->field;
457 
458  return ff_filter_frame(outlink, out);
459 }
460 
462 {
463  AVFilterContext *ctx = inlink->dst;
464  ESTDIFContext *s = ctx->priv;
466  int ret;
467 
468  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
469  return ret;
470 
471  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
472  s->planeheight[0] = s->planeheight[3] = inlink->h;
473  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
474  s->planewidth[0] = s->planewidth[3] = inlink->w;
475 
476  if (inlink->h < 3) {
477  av_log(ctx, AV_LOG_ERROR, "Video of less than 3 lines is not supported\n");
478  return AVERROR(EINVAL);
479  }
480 
481  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
482  s->nb_threads = ff_filter_get_nb_threads(ctx);
483  s->depth = desc->comp[0].depth;
484  s->interpolate = s->depth <= 8 ? interpolate_8 : interpolate_16;
485  s->mid_8[0] = mid2_8;
486  s->mid_8[1] = mid4_8;
487  s->mid_8[2] = mid6_8;
488  s->mid_16[0] = mid2_16;
489  s->mid_16[1] = mid4_16;
490  s->mid_16[2] = mid6_16;
491  s->max = (1 << (s->depth)) - 1;
492 
493  return 0;
494 }
496 {
497  AVFilterContext *ctx = inlink->dst;
498  ESTDIFContext *s = ctx->priv;
499  int ret;
500 
501  if (!s->prev) {
502  s->prev = in;
503  return 0;
504  }
505 
506  if ((s->deint && !(s->prev->flags & AV_FRAME_FLAG_INTERLACED)) || ctx->is_disabled) {
507  s->prev->pts *= 2;
508  s->prev->duration *= 2;
509  ret = ff_filter_frame(ctx->outputs[0], s->prev);
510  s->prev = in;
511  return ret;
512  }
513 
514  ret = filter(ctx, s->prev, s->prev->pts * 2,
515  s->prev->duration * (s->mode ? 1 : 2));
516  if (ret < 0 || s->mode == 0) {
517  av_frame_free(&s->prev);
518  s->prev = in;
519  return ret;
520  }
521 
522  ret = filter(ctx, s->prev, s->prev->pts + in->pts, in->duration);
523  av_frame_free(&s->prev);
524  s->prev = in;
525  return ret;
526 }
527 
529 {
530  AVFilterContext *ctx = link->src;
531  ESTDIFContext *s = ctx->priv;
532  int ret;
533 
534  if (s->eof)
535  return AVERROR_EOF;
536 
537  ret = ff_request_frame(ctx->inputs[0]);
538 
539  if (ret == AVERROR_EOF && s->prev) {
540  AVFrame *next = av_frame_clone(s->prev);
541 
542  if (!next)
543  return AVERROR(ENOMEM);
544 
545  next->pts = s->prev->pts + av_rescale_q(1, av_inv_q(ctx->outputs[0]->frame_rate),
546  ctx->outputs[0]->time_base);
547  s->eof = 1;
548  ret = filter_frame(ctx->inputs[0], next);
549  } else if (ret < 0) {
550  return ret;
551  }
552 
553  return ret;
554 }
555 
557 {
558  ESTDIFContext *s = ctx->priv;
559 
560  av_frame_free(&s->prev);
561 }
562 
563 static const AVFilterPad estdif_inputs[] = {
564  {
565  .name = "default",
566  .type = AVMEDIA_TYPE_VIDEO,
567  .filter_frame = filter_frame,
568  .config_props = config_input,
569  },
570 };
571 
572 static const AVFilterPad estdif_outputs[] = {
573  {
574  .name = "default",
575  .type = AVMEDIA_TYPE_VIDEO,
576  .config_props = config_output,
577  .request_frame = request_frame,
578  },
579 };
580 
582  .name = "estdif",
583  .description = NULL_IF_CONFIG_SMALL("Apply Edge Slope Tracing deinterlace."),
584  .priv_size = sizeof(ESTDIFContext),
585  .priv_class = &estdif_class,
586  .uninit = uninit,
591  .process_command = ff_filter_process_command,
592 };
ESTDIFContext::nb_planes
int nb_planes
Definition: vf_estdif.c:49
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:101
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:508
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:487
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:81
ESTDIFContext::mcost
int mcost
middle cost for edge matching
Definition: vf_estdif.c:39
td
#define td
Definition: regdef.h:70
ESTDIFContext::interpolate
void(* interpolate)(struct ESTDIFContext *s, uint8_t *dst, const uint8_t *prev_line, const uint8_t *next_line, const uint8_t *prev2_line, const uint8_t *next2_line, const uint8_t *prev3_line, const uint8_t *next3_line, int x, int width, int rslope, int redge, int depth, int *K)
Definition: vf_estdif.c:53
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
MID6
#define MID6(type, ss)
Definition: vf_estdif.c:200
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:971
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:797
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2936
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
deinterlace_slice
static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_estdif.c:334
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:174
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
estdif_inputs
static const AVFilterPad estdif_inputs[]
Definition: vf_estdif.c:563
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:500
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
ESTDIFContext::parity
int parity
frame field parity
Definition: vf_estdif.c:34
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:442
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:507
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:502
AVOption
AVOption.
Definition: opt.h:251
ESTDIFContext::mid_16
unsigned(* mid_16[3])(const uint16_t *const prev, const uint16_t *const next, const uint16_t *const prev2, const uint16_t *const next2, const uint16_t *const prev3, const uint16_t *const next3, int end, int x, int k, int depth)
Definition: vf_estdif.c:68
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_estdif.c:495
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:465
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:415
MIDL
#define MIDL(type, ss)
Definition: vf_estdif.c:152
DIFF
#define DIFF(type, ss)
Definition: vf_estdif.c:222
ESTDIFContext::deint
int deint
which frames to deinterlace
Definition: vf_estdif.c:35
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
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:639
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:473
video.h
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:154
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:503
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:445
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:631
formats.h
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2976
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:499
MID4
#define MID4(type, ss)
Definition: vf_estdif.c:180
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:483
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_estdif.c:109
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
interp
interp
Definition: vf_curves.c:61
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:481
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_estdif.c:135
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:509
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:463
pts
static int64_t pts
Definition: transcode_aac.c:643
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:449
ESTDIFContext::ecost
int ecost
edge cost for edge matching
Definition: vf_estdif.c:38
ESTDIFContext::max
int max
Definition: vf_estdif.c:48
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:468
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
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:477
duration
int64_t duration
Definition: movenc.c:64
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
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:485
width
#define width
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
s
#define s(width, name)
Definition: cbs_vp9.c:256
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:486
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:478
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
ESTDIFContext::field
int field
which field are we on, 0 or 1
Definition: vf_estdif.c:45
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:506
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:462
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:476
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:448
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_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
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:194
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_estdif.c:461
link
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 link
Definition: filter_design.txt:23
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
ESTDIFContext::mode
int mode
0 is frame, 1 is field
Definition: vf_estdif.c:33
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:446
ESTDIFContext::interp
int interp
type of interpolation
Definition: vf_estdif.c:41
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:484
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
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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
ESTDIFContext::eof
int eof
Definition: vf_estdif.c:46
MID2
#define MID2(type, ss)
Definition: vf_estdif.c:164
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:467
COST
#define COST(type, ss)
Definition: vf_estdif.c:233
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_estdif.c:556
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:466
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
estdif_outputs
static const AVFilterPad estdif_outputs[]
Definition: vf_estdif.c:572
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:480
ESTDIFContext::dcost
int dcost
distance cost for edge matching
Definition: vf_estdif.c:40
ESTDIFContext::linesize
int linesize[4]
bytes of pixel data per line for each plane
Definition: vf_estdif.c:42
FLAGS
#define FLAGS
Definition: vf_estdif.c:81
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:114
ESTDIFContext::mid_8
unsigned(* mid_8[3])(const uint8_t *const prev, const uint8_t *const next, const uint8_t *const prev2, const uint8_t *const next2, const uint8_t *const prev3, const uint8_t *const next3, int end, int x, int k, int depth)
Definition: vf_estdif.c:60
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:470
parity
mcdeint parity
Definition: vf_mcdeint.c:282
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:472
ESTDIFContext
Definition: vf_estdif.c:30
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:844
ESTDIFContext::depth
int depth
Definition: vf_estdif.c:47
height
#define height
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
INTERPOLATE
#define INTERPOLATE(type, atype, amax, ss)
Definition: vf_estdif.c:248
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:504
OFFSET
#define OFFSET(x)
Definition: vf_estdif.c:80
internal.h
interlaced
uint8_t interlaced
Definition: mxfenc.c:2148
ff_vf_estdif
const AVFilter ff_vf_estdif
Definition: vf_estdif.c:581
filter
static int filter(AVFilterContext *ctx, AVFrame *in, int64_t pts, int64_t duration)
Definition: vf_estdif.c:431
ESTDIFContext::planeheight
int planeheight[4]
height of each plane
Definition: vf_estdif.c:44
MAX_R
#define MAX_R
Definition: vf_estdif.c:77
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:482
common.h
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:779
ThreadData
Used for passing data between threads.
Definition: dsddec.c:69
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
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
CONST
#define CONST(name, help, val, unit)
Definition: vf_estdif.c:82
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:626
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:464
AVFilter
Filter definition.
Definition: avfilter.h:166
estdif_options
static const AVOption estdif_options[]
Definition: vf_estdif.c:84
ret
ret
Definition: filter_design.txt:187
ESTDIFContext::nb_threads
int nb_threads
Definition: vf_estdif.c:50
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:501
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:469
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:474
request_frame
static int request_frame(AVFilterLink *link)
Definition: vf_estdif.c:528
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:505
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
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
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
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
ESTDIFContext::prev
AVFrame * prev
Definition: vf_estdif.c:51
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
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
K
#define K
Definition: palette.c:25
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:155
imgutils.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(estdif)
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:375
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:27
ESTDIFContext::redge
int redge
best edge match search radius
Definition: vf_estdif.c:37
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:471
ESTDIFContext::planewidth
int planewidth[4]
width of each plane
Definition: vf_estdif.c:43
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:475
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:447
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:146
ESTDIFContext::rslope
int rslope
best edge slope search radius
Definition: vf_estdif.c:36
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
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:473