FFmpeg
vf_w3fdif.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 British Broadcasting Corporation, All Rights Reserved
3  * Author of de-interlace algorithm: Jim Easterbrook for BBC R&D
4  * Based on the process described by Martin Weston for BBC R&D
5  * Author of FFmpeg filter: Mark Himsley for BBC Broadcast Systems Development
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/common.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "formats.h"
30 #include "internal.h"
31 #include "video.h"
32 #include "w3fdif.h"
33 
34 typedef struct W3FDIFContext {
35  const AVClass *class;
36  int filter; ///< 0 is simple, 1 is more complex
37  int mode; ///< 0 is frame, 1 is field
38  int parity; ///< frame field parity
39  int deint; ///< which frames to deinterlace
40  int linesize[4]; ///< bytes of pixel data per line for each plane
41  int planeheight[4]; ///< height of each plane
42  int field; ///< which field are we on, 0 or 1
43  int eof;
44  int nb_planes;
45  AVFrame *prev, *cur, *next; ///< previous, current, next frames
46  int32_t **work_line; ///< lines we are calculating
48  int max;
49 
52 
53 #define OFFSET(x) offsetof(W3FDIFContext, x)
54 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
55 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
56 
57 static const AVOption w3fdif_options[] = {
58  { "filter", "specify the filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "filter" },
59  CONST("simple", NULL, 0, "filter"),
60  CONST("complex", NULL, 1, "filter"),
61  { "mode", "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode"},
62  CONST("frame", "send one frame for each frame", 0, "mode"),
63  CONST("field", "send one frame for each field", 1, "mode"),
64  { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS, "parity" },
65  CONST("tff", "assume top field first", 0, "parity"),
66  CONST("bff", "assume bottom field first", 1, "parity"),
67  CONST("auto", "auto detect parity", -1, "parity"),
68  { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "deint" },
69  CONST("all", "deinterlace all frames", 0, "deint"),
70  CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
71  { NULL }
72 };
73 
74 AVFILTER_DEFINE_CLASS(w3fdif);
75 
77 {
78  static const enum AVPixelFormat pix_fmts[] = {
102  };
103 
104  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
105  if (!fmts_list)
106  return AVERROR(ENOMEM);
107  return ff_set_common_formats(ctx, fmts_list);
108 }
109 
111  uint8_t *in_lines_cur[2],
112  const int16_t *coef, int linesize)
113 {
114  int i;
115 
116  for (i = 0; i < linesize; i++) {
117  *work_line = *in_lines_cur[0]++ * coef[0];
118  *work_line++ += *in_lines_cur[1]++ * coef[1];
119  }
120 }
121 
123  uint8_t *in_lines_cur[4],
124  const int16_t *coef, int linesize)
125 {
126  int i;
127 
128  for (i = 0; i < linesize; i++) {
129  *work_line = *in_lines_cur[0]++ * coef[0];
130  *work_line += *in_lines_cur[1]++ * coef[1];
131  *work_line += *in_lines_cur[2]++ * coef[2];
132  *work_line++ += *in_lines_cur[3]++ * coef[3];
133  }
134 }
135 
137  uint8_t *in_lines_cur[3],
138  uint8_t *in_lines_adj[3],
139  const int16_t *coef, int linesize)
140 {
141  int i;
142 
143  for (i = 0; i < linesize; i++) {
144  *work_line += *in_lines_cur[0]++ * coef[0];
145  *work_line += *in_lines_adj[0]++ * coef[0];
146  *work_line += *in_lines_cur[1]++ * coef[1];
147  *work_line += *in_lines_adj[1]++ * coef[1];
148  *work_line += *in_lines_cur[2]++ * coef[2];
149  *work_line++ += *in_lines_adj[2]++ * coef[2];
150  }
151 }
152 
154  uint8_t *in_lines_cur[5],
155  uint8_t *in_lines_adj[5],
156  const int16_t *coef, int linesize)
157 {
158  int i;
159 
160  for (i = 0; i < linesize; i++) {
161  *work_line += *in_lines_cur[0]++ * coef[0];
162  *work_line += *in_lines_adj[0]++ * coef[0];
163  *work_line += *in_lines_cur[1]++ * coef[1];
164  *work_line += *in_lines_adj[1]++ * coef[1];
165  *work_line += *in_lines_cur[2]++ * coef[2];
166  *work_line += *in_lines_adj[2]++ * coef[2];
167  *work_line += *in_lines_cur[3]++ * coef[3];
168  *work_line += *in_lines_adj[3]++ * coef[3];
169  *work_line += *in_lines_cur[4]++ * coef[4];
170  *work_line++ += *in_lines_adj[4]++ * coef[4];
171  }
172 }
173 
174 static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
175 {
176  int j;
177 
178  for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
179  *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
180 }
181 
183  uint8_t *in_lines_cur8[2],
184  const int16_t *coef, int linesize)
185 {
186  uint16_t *in_lines_cur[2] = { (uint16_t *)in_lines_cur8[0], (uint16_t *)in_lines_cur8[1] };
187  int i;
188 
189  linesize /= 2;
190  for (i = 0; i < linesize; i++) {
191  *work_line = *in_lines_cur[0]++ * coef[0];
192  *work_line++ += *in_lines_cur[1]++ * coef[1];
193  }
194 }
195 
197  uint8_t *in_lines_cur8[4],
198  const int16_t *coef, int linesize)
199 {
200  uint16_t *in_lines_cur[4] = { (uint16_t *)in_lines_cur8[0],
201  (uint16_t *)in_lines_cur8[1],
202  (uint16_t *)in_lines_cur8[2],
203  (uint16_t *)in_lines_cur8[3] };
204  int i;
205 
206  linesize /= 2;
207  for (i = 0; i < linesize; i++) {
208  *work_line = *in_lines_cur[0]++ * coef[0];
209  *work_line += *in_lines_cur[1]++ * coef[1];
210  *work_line += *in_lines_cur[2]++ * coef[2];
211  *work_line++ += *in_lines_cur[3]++ * coef[3];
212  }
213 }
214 
216  uint8_t *in_lines_cur8[3],
217  uint8_t *in_lines_adj8[3],
218  const int16_t *coef, int linesize)
219 {
220  uint16_t *in_lines_cur[3] = { (uint16_t *)in_lines_cur8[0],
221  (uint16_t *)in_lines_cur8[1],
222  (uint16_t *)in_lines_cur8[2] };
223  uint16_t *in_lines_adj[3] = { (uint16_t *)in_lines_adj8[0],
224  (uint16_t *)in_lines_adj8[1],
225  (uint16_t *)in_lines_adj8[2] };
226  int i;
227 
228  linesize /= 2;
229  for (i = 0; i < linesize; i++) {
230  *work_line += *in_lines_cur[0]++ * coef[0];
231  *work_line += *in_lines_adj[0]++ * coef[0];
232  *work_line += *in_lines_cur[1]++ * coef[1];
233  *work_line += *in_lines_adj[1]++ * coef[1];
234  *work_line += *in_lines_cur[2]++ * coef[2];
235  *work_line++ += *in_lines_adj[2]++ * coef[2];
236  }
237 }
238 
240  uint8_t *in_lines_cur8[5],
241  uint8_t *in_lines_adj8[5],
242  const int16_t *coef, int linesize)
243 {
244  uint16_t *in_lines_cur[5] = { (uint16_t *)in_lines_cur8[0],
245  (uint16_t *)in_lines_cur8[1],
246  (uint16_t *)in_lines_cur8[2],
247  (uint16_t *)in_lines_cur8[3],
248  (uint16_t *)in_lines_cur8[4] };
249  uint16_t *in_lines_adj[5] = { (uint16_t *)in_lines_adj8[0],
250  (uint16_t *)in_lines_adj8[1],
251  (uint16_t *)in_lines_adj8[2],
252  (uint16_t *)in_lines_adj8[3],
253  (uint16_t *)in_lines_adj8[4] };
254  int i;
255 
256  linesize /= 2;
257  for (i = 0; i < linesize; i++) {
258  *work_line += *in_lines_cur[0]++ * coef[0];
259  *work_line += *in_lines_adj[0]++ * coef[0];
260  *work_line += *in_lines_cur[1]++ * coef[1];
261  *work_line += *in_lines_adj[1]++ * coef[1];
262  *work_line += *in_lines_cur[2]++ * coef[2];
263  *work_line += *in_lines_adj[2]++ * coef[2];
264  *work_line += *in_lines_cur[3]++ * coef[3];
265  *work_line += *in_lines_adj[3]++ * coef[3];
266  *work_line += *in_lines_cur[4]++ * coef[4];
267  *work_line++ += *in_lines_adj[4]++ * coef[4];
268  }
269 }
270 
271 static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
272 {
273  uint16_t *out_pixel = (uint16_t *)out_pixel8;
274  int j;
275 
276  linesize /= 2;
277  for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
278  *out_pixel = av_clip(*work_pixel, 0, max) >> 15;
279 }
280 
282 {
283  AVFilterContext *ctx = inlink->dst;
284  W3FDIFContext *s = ctx->priv;
286  int ret, i, depth;
287 
288  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
289  return ret;
290 
291  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
292  s->planeheight[0] = s->planeheight[3] = inlink->h;
293 
294  if (inlink->h < 3) {
295  av_log(ctx, AV_LOG_ERROR, "Video of less than 3 lines is not supported\n");
296  return AVERROR(EINVAL);
297  }
298 
301  s->work_line = av_calloc(s->nb_threads, sizeof(*s->work_line));
302  if (!s->work_line)
303  return AVERROR(ENOMEM);
304 
305  for (i = 0; i < s->nb_threads; i++) {
306  s->work_line[i] = av_calloc(FFALIGN(s->linesize[0], 32), sizeof(*s->work_line[0]));
307  if (!s->work_line[i])
308  return AVERROR(ENOMEM);
309  }
310 
311  depth = desc->comp[0].depth;
312  s->max = ((1 << depth) - 1) * 256 * 128;
313  if (depth <= 8) {
319  } else {
325  }
326 
327  if (ARCH_X86)
328  ff_w3fdif_init_x86(&s->dsp, depth);
329 
330  return 0;
331 }
332 
333 static int config_output(AVFilterLink *outlink)
334 {
335  AVFilterLink *inlink = outlink->src->inputs[0];
336 
337  outlink->time_base.num = inlink->time_base.num;
338  outlink->time_base.den = inlink->time_base.den * 2;
339  outlink->frame_rate.num = inlink->frame_rate.num * 2;
340  outlink->frame_rate.den = inlink->frame_rate.den;
341 
342  return 0;
343 }
344 
345 /*
346  * Filter coefficients from PH-2071, scaled by 256 * 128.
347  * Each set of coefficients has a set for low-frequencies and high-frequencies.
348  * n_coef_lf[] and n_coef_hf[] are the number of coefs for simple and more-complex.
349  * It is important for later that n_coef_lf[] is even and n_coef_hf[] is odd.
350  * coef_lf[][] and coef_hf[][] are the coefficients for low-frequencies
351  * and high-frequencies for simple and more-complex mode.
352  */
353 static const int8_t n_coef_lf[2] = { 2, 4 };
354 static const int16_t coef_lf[2][4] = {{ 16384, 16384, 0, 0},
355  { -852, 17236, 17236, -852}};
356 static const int8_t n_coef_hf[2] = { 3, 5 };
357 static const int16_t coef_hf[2][5] = {{ -2048, 4096, -2048, 0, 0},
358  { 1016, -3801, 5570, -3801, 1016}};
359 
360 typedef struct ThreadData {
361  AVFrame *out, *cur, *adj;
362 } ThreadData;
363 
365  int jobnr, int nb_jobs, int plane)
366 {
367  W3FDIFContext *s = ctx->priv;
368  ThreadData *td = arg;
369  AVFrame *out = td->out;
370  AVFrame *cur = td->cur;
371  AVFrame *adj = td->adj;
372  const int filter = s->filter;
373  uint8_t *in_line, *in_lines_cur[5], *in_lines_adj[5];
374  uint8_t *out_line, *out_pixel;
375  int32_t *work_line, *work_pixel;
376  uint8_t *cur_data = cur->data[plane];
377  uint8_t *adj_data = adj->data[plane];
378  uint8_t *dst_data = out->data[plane];
379  const int linesize = s->linesize[plane];
380  const int height = s->planeheight[plane];
381  const int cur_line_stride = cur->linesize[plane];
382  const int adj_line_stride = adj->linesize[plane];
383  const int dst_line_stride = out->linesize[plane];
384  const int start = (height * jobnr) / nb_jobs;
385  const int end = (height * (jobnr+1)) / nb_jobs;
386  const int max = s->max;
387  const int interlaced = cur->interlaced_frame;
388  const int tff = s->field == (s->parity == -1 ? interlaced ? cur->top_field_first : 1 :
389  s->parity ^ 1);
390  int j, y_in, y_out;
391 
392  /* copy unchanged the lines of the field */
393  y_out = start + (tff ^ (start & 1));
394 
395  in_line = cur_data + (y_out * cur_line_stride);
396  out_line = dst_data + (y_out * dst_line_stride);
397 
398  while (y_out < end) {
399  memcpy(out_line, in_line, linesize);
400  y_out += 2;
401  in_line += cur_line_stride * 2;
402  out_line += dst_line_stride * 2;
403  }
404 
405  /* interpolate other lines of the field */
406  y_out = start + ((!tff) ^ (start & 1));
407 
408  out_line = dst_data + (y_out * dst_line_stride);
409 
410  while (y_out < end) {
411  /* get low vertical frequencies from current field */
412  for (j = 0; j < n_coef_lf[filter]; j++) {
413  y_in = (y_out + 1) + (j * 2) - n_coef_lf[filter];
414 
415  while (y_in < 0)
416  y_in += 2;
417  while (y_in >= height)
418  y_in -= 2;
419 
420  in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
421  }
422 
423  work_line = s->work_line[jobnr];
424  switch (n_coef_lf[filter]) {
425  case 2:
426  s->dsp.filter_simple_low(work_line, in_lines_cur,
427  coef_lf[filter], linesize);
428  break;
429  case 4:
430  s->dsp.filter_complex_low(work_line, in_lines_cur,
431  coef_lf[filter], linesize);
432  }
433 
434  /* get high vertical frequencies from adjacent fields */
435  for (j = 0; j < n_coef_hf[filter]; j++) {
436  y_in = (y_out + 1) + (j * 2) - n_coef_hf[filter];
437 
438  while (y_in < 0)
439  y_in += 2;
440  while (y_in >= height)
441  y_in -= 2;
442 
443  in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
444  in_lines_adj[j] = adj_data + (y_in * adj_line_stride);
445  }
446 
447  work_line = s->work_line[jobnr];
448  switch (n_coef_hf[filter]) {
449  case 3:
450  s->dsp.filter_simple_high(work_line, in_lines_cur, in_lines_adj,
451  coef_hf[filter], linesize);
452  break;
453  case 5:
454  s->dsp.filter_complex_high(work_line, in_lines_cur, in_lines_adj,
455  coef_hf[filter], linesize);
456  }
457 
458  /* save scaled result to the output frame, scaling down by 256 * 128 */
459  work_pixel = s->work_line[jobnr];
460  out_pixel = out_line;
461 
462  s->dsp.filter_scale(out_pixel, work_pixel, linesize, max);
463 
464  /* move on to next line */
465  y_out += 2;
466  out_line += dst_line_stride * 2;
467  }
468 
469  return 0;
470 }
471 
473  int jobnr, int nb_jobs)
474 {
475  W3FDIFContext *s = ctx->priv;
476 
477  for (int p = 0; p < s->nb_planes; p++)
478  deinterlace_plane_slice(ctx, arg, jobnr, nb_jobs, p);
479 
480  return 0;
481 }
482 
483 static int filter(AVFilterContext *ctx, int is_second)
484 {
485  W3FDIFContext *s = ctx->priv;
486  AVFilterLink *outlink = ctx->outputs[0];
487  AVFrame *out, *adj;
488  ThreadData td;
489 
490  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
491  if (!out)
492  return AVERROR(ENOMEM);
493  av_frame_copy_props(out, s->cur);
494  out->interlaced_frame = 0;
495 
496  if (!is_second) {
497  if (out->pts != AV_NOPTS_VALUE)
498  out->pts *= 2;
499  } else {
500  int64_t cur_pts = s->cur->pts;
501  int64_t next_pts = s->next->pts;
502 
503  if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
504  out->pts = cur_pts + next_pts;
505  } else {
506  out->pts = AV_NOPTS_VALUE;
507  }
508  }
509 
510  adj = s->field ? s->next : s->prev;
511  td.out = out; td.cur = s->cur; td.adj = adj;
512  ctx->internal->execute(ctx, deinterlace_slice, &td, NULL, FFMIN(s->planeheight[1], s->nb_threads));
513 
514  if (s->mode)
515  s->field = !s->field;
516 
517  return ff_filter_frame(outlink, out);
518 }
519 
521 {
522  AVFilterContext *ctx = inlink->dst;
523  W3FDIFContext *s = ctx->priv;
524  int ret;
525 
526  av_frame_free(&s->prev);
527  s->prev = s->cur;
528  s->cur = s->next;
529  s->next = frame;
530 
531  if (!s->cur) {
532  s->cur = av_frame_clone(s->next);
533  if (!s->cur)
534  return AVERROR(ENOMEM);
535  }
536 
537  if ((s->deint && !s->cur->interlaced_frame) || ctx->is_disabled) {
538  AVFrame *out = av_frame_clone(s->cur);
539  if (!out)
540  return AVERROR(ENOMEM);
541 
542  av_frame_free(&s->prev);
543  if (out->pts != AV_NOPTS_VALUE)
544  out->pts *= 2;
545  return ff_filter_frame(ctx->outputs[0], out);
546  }
547 
548  if (!s->prev)
549  return 0;
550 
551  ret = filter(ctx, 0);
552  if (ret < 0 || s->mode == 0)
553  return ret;
554 
555  return filter(ctx, 1);
556 }
557 
558 static int request_frame(AVFilterLink *outlink)
559 {
560  AVFilterContext *ctx = outlink->src;
561  W3FDIFContext *s = ctx->priv;
562  int ret;
563 
564  if (s->eof)
565  return AVERROR_EOF;
566 
567  ret = ff_request_frame(ctx->inputs[0]);
568 
569  if (ret == AVERROR_EOF && s->cur) {
571  if (!next)
572  return AVERROR(ENOMEM);
573  next->pts = s->next->pts * 2 - s->cur->pts;
574  filter_frame(ctx->inputs[0], next);
575  s->eof = 1;
576  } else if (ret < 0) {
577  return ret;
578  }
579 
580  return 0;
581 }
582 
584 {
585  W3FDIFContext *s = ctx->priv;
586  int i;
587 
588  av_frame_free(&s->prev);
589  av_frame_free(&s->cur );
590  av_frame_free(&s->next);
591 
592  for (i = 0; i < s->nb_threads; i++)
593  av_freep(&s->work_line[i]);
594 
595  av_freep(&s->work_line);
596 }
597 
598 static const AVFilterPad w3fdif_inputs[] = {
599  {
600  .name = "default",
601  .type = AVMEDIA_TYPE_VIDEO,
602  .filter_frame = filter_frame,
603  .config_props = config_input,
604  },
605  { NULL }
606 };
607 
608 static const AVFilterPad w3fdif_outputs[] = {
609  {
610  .name = "default",
611  .type = AVMEDIA_TYPE_VIDEO,
612  .config_props = config_output,
613  .request_frame = request_frame,
614  },
615  { NULL }
616 };
617 
619  .name = "w3fdif",
620  .description = NULL_IF_CONFIG_SMALL("Apply Martin Weston three field deinterlace."),
621  .priv_size = sizeof(W3FDIFContext),
622  .priv_class = &w3fdif_class,
623  .uninit = uninit,
625  .inputs = w3fdif_inputs,
626  .outputs = w3fdif_outputs,
629 };
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
AVFrame * out
Definition: af_adeclick.c:502
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:401
AVFrame * prev
Definition: vf_w3fdif.c:45
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
AVFrame * cur
Definition: vf_w3fdif.c:45
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:419
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
const char * desc
Definition: libsvtav1.c:79
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
Main libavfilter public API header.
static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
Definition: vf_w3fdif.c:271
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
int num
Numerator.
Definition: rational.h:59
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:388
static void filter_complex_low(int32_t *work_line, uint8_t *in_lines_cur[4], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:122
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:287
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
static const AVOption w3fdif_options[]
Definition: vf_w3fdif.c:57
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
static int config_input(AVFilterLink *inlink)
Definition: vf_w3fdif.c:281
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1094
#define FLAGS
Definition: vf_w3fdif.c:54
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.
AVFILTER_DEFINE_CLASS(w3fdif)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:414
#define height
#define av_clip
Definition: common.h:122
static void filter16_complex_high(int32_t *work_line, uint8_t *in_lines_cur8[5], uint8_t *in_lines_adj8[5], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:239
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
void(* filter_complex_low)(int32_t *work_line, uint8_t *in_lines_cur[4], const int16_t *coef, int linesize)
Definition: w3fdif.h:31
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
static void filter_complex_high(int32_t *work_line, uint8_t *in_lines_cur[5], uint8_t *in_lines_adj[5], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:153
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
void(* filter_simple_high)(int32_t *work_line, uint8_t *in_lines_cur[3], uint8_t *in_lines_adj[3], const int16_t *coef, int linesize)
Definition: w3fdif.h:34
A filter pad used for either input or output.
Definition: internal.h:54
int linesize[4]
bytes of pixel data per line for each plane
Definition: vf_w3fdif.c:40
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
AVFrame * next
previous, current, next frames
Definition: vf_w3fdif.c:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:588
#define td
Definition: regdef.h:70
static int query_formats(AVFilterContext *ctx)
Definition: vf_w3fdif.c:76
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static const int16_t coef_hf[2][5]
Definition: vf_w3fdif.c:357
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:204
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
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:882
void * priv
private data for use by the filter
Definition: avfilter.h:356
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define OFFSET(x)
Definition: vf_w3fdif.c:53
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
const char * arg
Definition: jacosubdec.c:66
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:420
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
int planeheight[4]
height of each plane
Definition: vf_w3fdif.c:41
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:421
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
static void filter16_complex_low(int32_t *work_line, uint8_t *in_lines_cur8[4], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:196
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
#define FFMIN(a, b)
Definition: common.h:105
int field
which field are we on, 0 or 1
Definition: vf_w3fdif.c:42
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
uint8_t interlaced
Definition: mxfenc.c:2208
static int deinterlace_plane_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int plane)
Definition: vf_w3fdif.c:364
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_acrusher.c:336
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:440
int mode
0 is frame, 1 is field
Definition: vf_w3fdif.c:37
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
static const int16_t coef_lf[2][4]
Definition: vf_w3fdif.c:354
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
void(* filter_scale)(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
Definition: w3fdif.h:42
#define s(width, name)
Definition: cbs_vp9.c:257
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
static const int8_t n_coef_hf[2]
Definition: vf_w3fdif.c:356
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:417
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:541
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AVFilter ff_vf_w3fdif
Definition: vf_w3fdif.c:618
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
static int config_output(AVFilterLink *outlink)
Definition: vf_w3fdif.c:333
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
Used for passing data between threads.
Definition: dsddec.c:67
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
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:382
AVFrame * adj
Definition: vf_w3fdif.c:361
static const int8_t n_coef_lf[2]
Definition: vf_w3fdif.c:353
AVFrame * cur
Definition: vf_w3fdif.c:361
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
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
const char * name
Filter name.
Definition: avfilter.h:149
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:405
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
static void filter16_simple_high(int32_t *work_line, uint8_t *in_lines_cur8[3], uint8_t *in_lines_adj8[3], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:215
#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:134
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:303
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:381
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
#define CONST(name, help, val, unit)
Definition: vf_w3fdif.c:55
static const AVFilterPad w3fdif_inputs[]
Definition: vf_w3fdif.c:598
void(* filter_simple_low)(int32_t *work_line, uint8_t *in_lines_cur[2], const int16_t *coef, int linesize)
Definition: w3fdif.h:28
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
W3FDIFDSPContext dsp
Definition: vf_w3fdif.c:50
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
common internal and external API header
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_w3fdif.c:520
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
int deint
which frames to deinterlace
Definition: vf_w3fdif.c:39
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_w3fdif.c:472
void(* filter_complex_high)(int32_t *work_line, uint8_t *in_lines_cur[5], uint8_t *in_lines_adj[5], const int16_t *coef, int linesize)
Definition: w3fdif.h:38
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
int den
Denominator.
Definition: rational.h:60
int parity
frame field parity
Definition: vf_w3fdif.c:38
avfilter_execute_func * execute
Definition: internal.h:136
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:470
static const AVFilterPad w3fdif_outputs[]
Definition: vf_w3fdif.c:608
A list of supported formats for one end of a filter link.
Definition: formats.h:65
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
An instance of a filter.
Definition: avfilter.h:341
static void filter16_simple_low(int32_t *work_line, uint8_t *in_lines_cur8[2], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:182
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_w3fdif.c:583
FILE * out
Definition: movenc.c:54
void ff_w3fdif_init_x86(W3FDIFDSPContext *dsp, int depth)
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
Definition: vf_w3fdif.c:174
static void filter_simple_low(int32_t *work_line, uint8_t *in_lines_cur[2], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:110
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:408
int32_t ** work_line
lines we are calculating
Definition: vf_w3fdif.c:46
static int request_frame(AVFilterLink *outlink)
Definition: vf_w3fdif.c:558
internal API functions
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
int depth
Number of bits in the component.
Definition: pixdesc.h:58
int nb_threads
Definition: vf_w3fdif.c:47
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
int filter
0 is simple, 1 is more complex
Definition: vf_w3fdif.c:36
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
static void filter_simple_high(int32_t *work_line, uint8_t *in_lines_cur[3], uint8_t *in_lines_adj[3], const int16_t *coef, int linesize)
Definition: vf_w3fdif.c:136
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
int i
Definition: input.c:407
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:439
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58