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