FFmpeg  4.3
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 deint; ///< which frames to deinterlace
38  int linesize[4]; ///< bytes of pixel data per line for each plane
39  int planeheight[4]; ///< height of each plane
40  int field; ///< which field are we on, 0 or 1
41  int eof;
42  int nb_planes;
43  AVFrame *prev, *cur, *next; ///< previous, current, next frames
44  int32_t **work_line; ///< lines we are calculating
46  int max;
47 
50 
51 #define OFFSET(x) offsetof(W3FDIFContext, x)
52 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
53 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
54 
55 static const AVOption w3fdif_options[] = {
56  { "filter", "specify the filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "filter" },
57  CONST("simple", NULL, 0, "filter"),
58  CONST("complex", NULL, 1, "filter"),
59  { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "deint" },
60  CONST("all", "deinterlace all frames", 0, "deint"),
61  CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
62  { NULL }
63 };
64 
65 AVFILTER_DEFINE_CLASS(w3fdif);
66 
68 {
69  static const enum AVPixelFormat pix_fmts[] = {
89  };
90 
91  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
92  if (!fmts_list)
93  return AVERROR(ENOMEM);
94  return ff_set_common_formats(ctx, fmts_list);
95 }
96 
98  uint8_t *in_lines_cur[2],
99  const int16_t *coef, int linesize)
100 {
101  int i;
102 
103  for (i = 0; i < linesize; i++) {
104  *work_line = *in_lines_cur[0]++ * coef[0];
105  *work_line++ += *in_lines_cur[1]++ * coef[1];
106  }
107 }
108 
110  uint8_t *in_lines_cur[4],
111  const int16_t *coef, int linesize)
112 {
113  int i;
114 
115  for (i = 0; i < linesize; i++) {
116  *work_line = *in_lines_cur[0]++ * coef[0];
117  *work_line += *in_lines_cur[1]++ * coef[1];
118  *work_line += *in_lines_cur[2]++ * coef[2];
119  *work_line++ += *in_lines_cur[3]++ * coef[3];
120  }
121 }
122 
124  uint8_t *in_lines_cur[3],
125  uint8_t *in_lines_adj[3],
126  const int16_t *coef, int linesize)
127 {
128  int i;
129 
130  for (i = 0; i < linesize; i++) {
131  *work_line += *in_lines_cur[0]++ * coef[0];
132  *work_line += *in_lines_adj[0]++ * coef[0];
133  *work_line += *in_lines_cur[1]++ * coef[1];
134  *work_line += *in_lines_adj[1]++ * coef[1];
135  *work_line += *in_lines_cur[2]++ * coef[2];
136  *work_line++ += *in_lines_adj[2]++ * coef[2];
137  }
138 }
139 
141  uint8_t *in_lines_cur[5],
142  uint8_t *in_lines_adj[5],
143  const int16_t *coef, int linesize)
144 {
145  int i;
146 
147  for (i = 0; i < linesize; i++) {
148  *work_line += *in_lines_cur[0]++ * coef[0];
149  *work_line += *in_lines_adj[0]++ * coef[0];
150  *work_line += *in_lines_cur[1]++ * coef[1];
151  *work_line += *in_lines_adj[1]++ * coef[1];
152  *work_line += *in_lines_cur[2]++ * coef[2];
153  *work_line += *in_lines_adj[2]++ * coef[2];
154  *work_line += *in_lines_cur[3]++ * coef[3];
155  *work_line += *in_lines_adj[3]++ * coef[3];
156  *work_line += *in_lines_cur[4]++ * coef[4];
157  *work_line++ += *in_lines_adj[4]++ * coef[4];
158  }
159 }
160 
161 static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
162 {
163  int j;
164 
165  for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
166  *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
167 }
168 
170  uint8_t *in_lines_cur8[2],
171  const int16_t *coef, int linesize)
172 {
173  uint16_t *in_lines_cur[2] = { (uint16_t *)in_lines_cur8[0], (uint16_t *)in_lines_cur8[1] };
174  int i;
175 
176  linesize /= 2;
177  for (i = 0; i < linesize; i++) {
178  *work_line = *in_lines_cur[0]++ * coef[0];
179  *work_line++ += *in_lines_cur[1]++ * coef[1];
180  }
181 }
182 
184  uint8_t *in_lines_cur8[4],
185  const int16_t *coef, int linesize)
186 {
187  uint16_t *in_lines_cur[4] = { (uint16_t *)in_lines_cur8[0],
188  (uint16_t *)in_lines_cur8[1],
189  (uint16_t *)in_lines_cur8[2],
190  (uint16_t *)in_lines_cur8[3] };
191  int i;
192 
193  linesize /= 2;
194  for (i = 0; i < linesize; i++) {
195  *work_line = *in_lines_cur[0]++ * coef[0];
196  *work_line += *in_lines_cur[1]++ * coef[1];
197  *work_line += *in_lines_cur[2]++ * coef[2];
198  *work_line++ += *in_lines_cur[3]++ * coef[3];
199  }
200 }
201 
203  uint8_t *in_lines_cur8[3],
204  uint8_t *in_lines_adj8[3],
205  const int16_t *coef, int linesize)
206 {
207  uint16_t *in_lines_cur[3] = { (uint16_t *)in_lines_cur8[0],
208  (uint16_t *)in_lines_cur8[1],
209  (uint16_t *)in_lines_cur8[2] };
210  uint16_t *in_lines_adj[3] = { (uint16_t *)in_lines_adj8[0],
211  (uint16_t *)in_lines_adj8[1],
212  (uint16_t *)in_lines_adj8[2] };
213  int i;
214 
215  linesize /= 2;
216  for (i = 0; i < linesize; i++) {
217  *work_line += *in_lines_cur[0]++ * coef[0];
218  *work_line += *in_lines_adj[0]++ * coef[0];
219  *work_line += *in_lines_cur[1]++ * coef[1];
220  *work_line += *in_lines_adj[1]++ * coef[1];
221  *work_line += *in_lines_cur[2]++ * coef[2];
222  *work_line++ += *in_lines_adj[2]++ * coef[2];
223  }
224 }
225 
227  uint8_t *in_lines_cur8[5],
228  uint8_t *in_lines_adj8[5],
229  const int16_t *coef, int linesize)
230 {
231  uint16_t *in_lines_cur[5] = { (uint16_t *)in_lines_cur8[0],
232  (uint16_t *)in_lines_cur8[1],
233  (uint16_t *)in_lines_cur8[2],
234  (uint16_t *)in_lines_cur8[3],
235  (uint16_t *)in_lines_cur8[4] };
236  uint16_t *in_lines_adj[5] = { (uint16_t *)in_lines_adj8[0],
237  (uint16_t *)in_lines_adj8[1],
238  (uint16_t *)in_lines_adj8[2],
239  (uint16_t *)in_lines_adj8[3],
240  (uint16_t *)in_lines_adj8[4] };
241  int i;
242 
243  linesize /= 2;
244  for (i = 0; i < linesize; i++) {
245  *work_line += *in_lines_cur[0]++ * coef[0];
246  *work_line += *in_lines_adj[0]++ * coef[0];
247  *work_line += *in_lines_cur[1]++ * coef[1];
248  *work_line += *in_lines_adj[1]++ * coef[1];
249  *work_line += *in_lines_cur[2]++ * coef[2];
250  *work_line += *in_lines_adj[2]++ * coef[2];
251  *work_line += *in_lines_cur[3]++ * coef[3];
252  *work_line += *in_lines_adj[3]++ * coef[3];
253  *work_line += *in_lines_cur[4]++ * coef[4];
254  *work_line++ += *in_lines_adj[4]++ * coef[4];
255  }
256 }
257 
258 static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
259 {
260  uint16_t *out_pixel = (uint16_t *)out_pixel8;
261  int j;
262 
263  linesize /= 2;
264  for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
265  *out_pixel = av_clip(*work_pixel, 0, max) >> 15;
266 }
267 
268 static int config_input(AVFilterLink *inlink)
269 {
270  AVFilterContext *ctx = inlink->dst;
271  W3FDIFContext *s = ctx->priv;
273  int ret, i, depth;
274 
275  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
276  return ret;
277 
278  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
279  s->planeheight[0] = s->planeheight[3] = inlink->h;
280 
281  if (inlink->h < 3) {
282  av_log(ctx, AV_LOG_ERROR, "Video of less than 3 lines is not supported\n");
283  return AVERROR(EINVAL);
284  }
285 
288  s->work_line = av_calloc(s->nb_threads, sizeof(*s->work_line));
289  if (!s->work_line)
290  return AVERROR(ENOMEM);
291 
292  for (i = 0; i < s->nb_threads; i++) {
293  s->work_line[i] = av_calloc(FFALIGN(s->linesize[0], 32), sizeof(*s->work_line[0]));
294  if (!s->work_line[i])
295  return AVERROR(ENOMEM);
296  }
297 
298  depth = desc->comp[0].depth;
299  s->max = ((1 << depth) - 1) * 256 * 128;
300  if (depth <= 8) {
306  } else {
312  }
313 
314  if (ARCH_X86)
315  ff_w3fdif_init_x86(&s->dsp, depth);
316 
317  return 0;
318 }
319 
320 static int config_output(AVFilterLink *outlink)
321 {
322  AVFilterLink *inlink = outlink->src->inputs[0];
323 
324  outlink->time_base.num = inlink->time_base.num;
325  outlink->time_base.den = inlink->time_base.den * 2;
326  outlink->frame_rate.num = inlink->frame_rate.num * 2;
327  outlink->frame_rate.den = inlink->frame_rate.den;
328 
329  return 0;
330 }
331 
332 /*
333  * Filter coefficients from PH-2071, scaled by 256 * 128.
334  * Each set of coefficients has a set for low-frequencies and high-frequencies.
335  * n_coef_lf[] and n_coef_hf[] are the number of coefs for simple and more-complex.
336  * It is important for later that n_coef_lf[] is even and n_coef_hf[] is odd.
337  * coef_lf[][] and coef_hf[][] are the coefficients for low-frequencies
338  * and high-frequencies for simple and more-complex mode.
339  */
340 static const int8_t n_coef_lf[2] = { 2, 4 };
341 static const int16_t coef_lf[2][4] = {{ 16384, 16384, 0, 0},
342  { -852, 17236, 17236, -852}};
343 static const int8_t n_coef_hf[2] = { 3, 5 };
344 static const int16_t coef_hf[2][5] = {{ -2048, 4096, -2048, 0, 0},
345  { 1016, -3801, 5570, -3801, 1016}};
346 
347 typedef struct ThreadData {
348  AVFrame *out, *cur, *adj;
349  int plane;
350 } ThreadData;
351 
352 static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
353 {
354  W3FDIFContext *s = ctx->priv;
355  ThreadData *td = arg;
356  AVFrame *out = td->out;
357  AVFrame *cur = td->cur;
358  AVFrame *adj = td->adj;
359  const int plane = td->plane;
360  const int filter = s->filter;
361  uint8_t *in_line, *in_lines_cur[5], *in_lines_adj[5];
362  uint8_t *out_line, *out_pixel;
363  int32_t *work_line, *work_pixel;
364  uint8_t *cur_data = cur->data[plane];
365  uint8_t *adj_data = adj->data[plane];
366  uint8_t *dst_data = out->data[plane];
367  const int linesize = s->linesize[plane];
368  const int height = s->planeheight[plane];
369  const int cur_line_stride = cur->linesize[plane];
370  const int adj_line_stride = adj->linesize[plane];
371  const int dst_line_stride = out->linesize[plane];
372  const int start = (height * jobnr) / nb_jobs;
373  const int end = (height * (jobnr+1)) / nb_jobs;
374  const int max = s->max;
375  int j, y_in, y_out;
376 
377  /* copy unchanged the lines of the field */
378  y_out = start + ((s->field == cur->top_field_first) ^ (start & 1));
379 
380  in_line = cur_data + (y_out * cur_line_stride);
381  out_line = dst_data + (y_out * dst_line_stride);
382 
383  while (y_out < end) {
384  memcpy(out_line, in_line, linesize);
385  y_out += 2;
386  in_line += cur_line_stride * 2;
387  out_line += dst_line_stride * 2;
388  }
389 
390  /* interpolate other lines of the field */
391  y_out = start + ((s->field != cur->top_field_first) ^ (start & 1));
392 
393  out_line = dst_data + (y_out * dst_line_stride);
394 
395  while (y_out < end) {
396  /* get low vertical frequencies from current field */
397  for (j = 0; j < n_coef_lf[filter]; j++) {
398  y_in = (y_out + 1) + (j * 2) - n_coef_lf[filter];
399 
400  while (y_in < 0)
401  y_in += 2;
402  while (y_in >= height)
403  y_in -= 2;
404 
405  in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
406  }
407 
408  work_line = s->work_line[jobnr];
409  switch (n_coef_lf[filter]) {
410  case 2:
411  s->dsp.filter_simple_low(work_line, in_lines_cur,
412  coef_lf[filter], linesize);
413  break;
414  case 4:
415  s->dsp.filter_complex_low(work_line, in_lines_cur,
416  coef_lf[filter], linesize);
417  }
418 
419  /* get high vertical frequencies from adjacent fields */
420  for (j = 0; j < n_coef_hf[filter]; j++) {
421  y_in = (y_out + 1) + (j * 2) - n_coef_hf[filter];
422 
423  while (y_in < 0)
424  y_in += 2;
425  while (y_in >= height)
426  y_in -= 2;
427 
428  in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
429  in_lines_adj[j] = adj_data + (y_in * adj_line_stride);
430  }
431 
432  work_line = s->work_line[jobnr];
433  switch (n_coef_hf[filter]) {
434  case 3:
435  s->dsp.filter_simple_high(work_line, in_lines_cur, in_lines_adj,
436  coef_hf[filter], linesize);
437  break;
438  case 5:
439  s->dsp.filter_complex_high(work_line, in_lines_cur, in_lines_adj,
440  coef_hf[filter], linesize);
441  }
442 
443  /* save scaled result to the output frame, scaling down by 256 * 128 */
444  work_pixel = s->work_line[jobnr];
445  out_pixel = out_line;
446 
447  s->dsp.filter_scale(out_pixel, work_pixel, linesize, max);
448 
449  /* move on to next line */
450  y_out += 2;
451  out_line += dst_line_stride * 2;
452  }
453 
454  return 0;
455 }
456 
457 static int filter(AVFilterContext *ctx, int is_second)
458 {
459  W3FDIFContext *s = ctx->priv;
460  AVFilterLink *outlink = ctx->outputs[0];
461  AVFrame *out, *adj;
462  ThreadData td;
463  int plane;
464 
465  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
466  if (!out)
467  return AVERROR(ENOMEM);
468  av_frame_copy_props(out, s->cur);
469  out->interlaced_frame = 0;
470 
471  if (!is_second) {
472  if (out->pts != AV_NOPTS_VALUE)
473  out->pts *= 2;
474  } else {
475  int64_t cur_pts = s->cur->pts;
476  int64_t next_pts = s->next->pts;
477 
478  if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
479  out->pts = cur_pts + next_pts;
480  } else {
481  out->pts = AV_NOPTS_VALUE;
482  }
483  }
484 
485  adj = s->field ? s->next : s->prev;
486  td.out = out; td.cur = s->cur; td.adj = adj;
487  for (plane = 0; plane < s->nb_planes; plane++) {
488  td.plane = plane;
489  ctx->internal->execute(ctx, deinterlace_slice, &td, NULL, FFMIN(s->planeheight[plane], s->nb_threads));
490  }
491 
492  s->field = !s->field;
493 
494  return ff_filter_frame(outlink, out);
495 }
496 
497 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
498 {
499  AVFilterContext *ctx = inlink->dst;
500  W3FDIFContext *s = ctx->priv;
501  int ret;
502 
503  av_frame_free(&s->prev);
504  s->prev = s->cur;
505  s->cur = s->next;
506  s->next = frame;
507 
508  if (!s->cur) {
509  s->cur = av_frame_clone(s->next);
510  if (!s->cur)
511  return AVERROR(ENOMEM);
512  }
513 
514  if ((s->deint && !s->cur->interlaced_frame) || ctx->is_disabled) {
515  AVFrame *out = av_frame_clone(s->cur);
516  if (!out)
517  return AVERROR(ENOMEM);
518 
519  av_frame_free(&s->prev);
520  if (out->pts != AV_NOPTS_VALUE)
521  out->pts *= 2;
522  return ff_filter_frame(ctx->outputs[0], out);
523  }
524 
525  if (!s->prev)
526  return 0;
527 
528  ret = filter(ctx, 0);
529  if (ret < 0)
530  return ret;
531 
532  return filter(ctx, 1);
533 }
534 
535 static int request_frame(AVFilterLink *outlink)
536 {
537  AVFilterContext *ctx = outlink->src;
538  W3FDIFContext *s = ctx->priv;
539  int ret;
540 
541  if (s->eof)
542  return AVERROR_EOF;
543 
544  ret = ff_request_frame(ctx->inputs[0]);
545 
546  if (ret == AVERROR_EOF && s->cur) {
548  if (!next)
549  return AVERROR(ENOMEM);
550  next->pts = s->next->pts * 2 - s->cur->pts;
551  filter_frame(ctx->inputs[0], next);
552  s->eof = 1;
553  } else if (ret < 0) {
554  return ret;
555  }
556 
557  return 0;
558 }
559 
561 {
562  W3FDIFContext *s = ctx->priv;
563  int i;
564 
565  av_frame_free(&s->prev);
566  av_frame_free(&s->cur );
567  av_frame_free(&s->next);
568 
569  for (i = 0; i < s->nb_threads; i++)
570  av_freep(&s->work_line[i]);
571 
572  av_freep(&s->work_line);
573 }
574 
575 static const AVFilterPad w3fdif_inputs[] = {
576  {
577  .name = "default",
578  .type = AVMEDIA_TYPE_VIDEO,
579  .filter_frame = filter_frame,
580  .config_props = config_input,
581  },
582  { NULL }
583 };
584 
585 static const AVFilterPad w3fdif_outputs[] = {
586  {
587  .name = "default",
588  .type = AVMEDIA_TYPE_VIDEO,
589  .config_props = config_output,
590  .request_frame = request_frame,
591  },
592  { NULL }
593 };
594 
596  .name = "w3fdif",
597  .description = NULL_IF_CONFIG_SMALL("Apply Martin Weston three field deinterlace."),
598  .priv_size = sizeof(W3FDIFContext),
599  .priv_class = &w3fdif_class,
600  .uninit = uninit,
602  .inputs = w3fdif_inputs,
603  .outputs = w3fdif_outputs,
605 };
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:440
AVFrame * out
Definition: af_adeclick.c:494
AVFrame * prev
Definition: vf_w3fdif.c:43
#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
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:434
AVFrame * cur
Definition: vf_w3fdif.c:43
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:407
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:417
#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
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2589
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:79
static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
Definition: vf_w3fdif.c:258
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:413
#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:99
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
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:109
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:247
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
static const AVOption w3fdif_options[]
Definition: vf_w3fdif.c:55
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
static int config_input(AVFilterLink *inlink)
Definition: vf_w3fdif.c:268
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
#define FLAGS
Definition: vf_w3fdif.c:52
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)
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:393
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:431
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:412
static AVFrame * frame
#define height
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:226
int plane
Definition: vf_blend.c:58
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:140
#define AVERROR_EOF
End of file.
Definition: error.h:55
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:447
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:402
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:439
#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:38
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:43
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:600
#define td
Definition: regdef.h:70
static int query_formats(AVFilterContext *ctx)
Definition: vf_w3fdif.c:67
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define ARCH_X86
Definition: config.h:38
#define AVERROR(e)
Definition: error.h:43
static const int16_t coef_hf[2][5]
Definition: vf_w3fdif.c:344
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:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
#define OFFSET(x)
Definition: vf_w3fdif.c:51
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:441
const char * arg
Definition: jacosubdec.c:66
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:418
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:400
int planeheight[4]
height of each plane
Definition: vf_w3fdif.c:39
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:419
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:395
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:183
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:784
#define FFMIN(a, b)
Definition: common.h:96
int field
which field are we on, 0 or 1
Definition: vf_w3fdif.c:40
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
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
static const int16_t coef_lf[2][4]
Definition: vf_w3fdif.c:341
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:436
static const int8_t n_coef_hf[2]
Definition: vf_w3fdif.c:343
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:415
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:595
static int config_output(AVFilterLink *outlink)
Definition: vf_w3fdif.c:320
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:405
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:331
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
AVFrame * adj
Definition: vf_w3fdif.c:348
static const int8_t n_coef_lf[2]
Definition: vf_w3fdif.c:340
AVFrame * cur
Definition: vf_w3fdif.c:348
#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
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
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:148
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:394
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:202
#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:133
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:406
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:414
#define flags(name, subs,...)
Definition: cbs_av1.c:564
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
#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
#define CONST(name, help, val, unit)
Definition: vf_w3fdif.c:53
static const AVFilterPad w3fdif_inputs[]
Definition: vf_w3fdif.c:575
void(* filter_simple_low)(int32_t *work_line, uint8_t *in_lines_cur[2], const int16_t *coef, int linesize)
Definition: w3fdif.h:28
W3FDIFDSPContext dsp
Definition: vf_w3fdif.c:48
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:497
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
int deint
which frames to deinterlace
Definition: vf_w3fdif.c:37
#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
static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_w3fdif.c:352
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
avfilter_execute_func * execute
Definition: internal.h:144
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:452
static const AVFilterPad w3fdif_outputs[]
Definition: vf_w3fdif.c:585
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
An instance of a filter.
Definition: avfilter.h:338
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:169
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_w3fdif.c:560
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:161
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:97
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:407
int32_t ** work_line
lines we are calculating
Definition: vf_w3fdif.c:44
static int request_frame(AVFilterLink *outlink)
Definition: vf_w3fdif.c:535
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
int nb_threads
Definition: vf_w3fdif.c:45
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
int filter
0 is simple, 1 is more complex
Definition: vf_w3fdif.c:36
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:123
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:437
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58