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 "internal.h"
30 #include "video.h"
31 #include "w3fdif.h"
32 
33 typedef struct W3FDIFContext {
34  const AVClass *class;
35  int filter; ///< 0 is simple, 1 is more complex
36  int mode; ///< 0 is frame, 1 is field
37  int parity; ///< frame field parity
38  int deint; ///< which frames to deinterlace
39  int linesize[4]; ///< bytes of pixel data per line for each plane
40  int planeheight[4]; ///< height of each plane
41  int field; ///< which field are we on, 0 or 1
42  int eof;
43  int nb_planes;
44  AVFrame *prev, *cur, *next; ///< previous, current, next frames
45  int32_t **work_line; ///< lines we are calculating
47  int max;
48 
51 
52 #define OFFSET(x) offsetof(W3FDIFContext, x)
53 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
54 #define CONST(name, help, val, u) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, .unit = u }
55 
56 static const AVOption w3fdif_options[] = {
57  { "filter", "specify the filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, .unit = "filter" },
58  CONST("simple", NULL, 0, "filter"),
59  CONST("complex", NULL, 1, "filter"),
60  { "mode", "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, .unit = "mode"},
61  CONST("frame", "send one frame for each frame", 0, "mode"),
62  CONST("field", "send one frame for each field", 1, "mode"),
63  { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS, .unit = "parity" },
64  CONST("tff", "assume top field first", 0, "parity"),
65  CONST("bff", "assume bottom field first", 1, "parity"),
66  CONST("auto", "auto detect parity", -1, "parity"),
67  { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, .unit = "deint" },
68  CONST("all", "deinterlace all frames", 0, "deint"),
69  CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
70  { NULL }
71 };
72 
73 AVFILTER_DEFINE_CLASS(w3fdif);
74 
75 static const enum AVPixelFormat pix_fmts[] = {
99 };
100 
101 static void filter_simple_low(int32_t *work_line,
102  uint8_t *in_lines_cur[2],
103  const int16_t *coef, int linesize)
104 {
105  int i;
106 
107  for (i = 0; i < linesize; i++) {
108  *work_line = *in_lines_cur[0]++ * coef[0];
109  *work_line++ += *in_lines_cur[1]++ * coef[1];
110  }
111 }
112 
113 static void filter_complex_low(int32_t *work_line,
114  uint8_t *in_lines_cur[4],
115  const int16_t *coef, int linesize)
116 {
117  int i;
118 
119  for (i = 0; i < linesize; i++) {
120  *work_line = *in_lines_cur[0]++ * coef[0];
121  *work_line += *in_lines_cur[1]++ * coef[1];
122  *work_line += *in_lines_cur[2]++ * coef[2];
123  *work_line++ += *in_lines_cur[3]++ * coef[3];
124  }
125 }
126 
127 static void filter_simple_high(int32_t *work_line,
128  uint8_t *in_lines_cur[3],
129  uint8_t *in_lines_adj[3],
130  const int16_t *coef, int linesize)
131 {
132  int i;
133 
134  for (i = 0; i < linesize; i++) {
135  *work_line += *in_lines_cur[0]++ * coef[0];
136  *work_line += *in_lines_adj[0]++ * coef[0];
137  *work_line += *in_lines_cur[1]++ * coef[1];
138  *work_line += *in_lines_adj[1]++ * coef[1];
139  *work_line += *in_lines_cur[2]++ * coef[2];
140  *work_line++ += *in_lines_adj[2]++ * coef[2];
141  }
142 }
143 
144 static void filter_complex_high(int32_t *work_line,
145  uint8_t *in_lines_cur[5],
146  uint8_t *in_lines_adj[5],
147  const int16_t *coef, int linesize)
148 {
149  int i;
150 
151  for (i = 0; i < linesize; i++) {
152  *work_line += *in_lines_cur[0]++ * coef[0];
153  *work_line += *in_lines_adj[0]++ * coef[0];
154  *work_line += *in_lines_cur[1]++ * coef[1];
155  *work_line += *in_lines_adj[1]++ * coef[1];
156  *work_line += *in_lines_cur[2]++ * coef[2];
157  *work_line += *in_lines_adj[2]++ * coef[2];
158  *work_line += *in_lines_cur[3]++ * coef[3];
159  *work_line += *in_lines_adj[3]++ * coef[3];
160  *work_line += *in_lines_cur[4]++ * coef[4];
161  *work_line++ += *in_lines_adj[4]++ * coef[4];
162  }
163 }
164 
165 static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
166 {
167  int j;
168 
169  for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
170  *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
171 }
172 
173 static void filter16_simple_low(int32_t *work_line,
174  uint8_t *in_lines_cur8[2],
175  const int16_t *coef, int linesize)
176 {
177  uint16_t *in_lines_cur[2] = { (uint16_t *)in_lines_cur8[0], (uint16_t *)in_lines_cur8[1] };
178  int i;
179 
180  linesize /= 2;
181  for (i = 0; i < linesize; i++) {
182  *work_line = *in_lines_cur[0]++ * coef[0];
183  *work_line++ += *in_lines_cur[1]++ * coef[1];
184  }
185 }
186 
187 static void filter16_complex_low(int32_t *work_line,
188  uint8_t *in_lines_cur8[4],
189  const int16_t *coef, int linesize)
190 {
191  uint16_t *in_lines_cur[4] = { (uint16_t *)in_lines_cur8[0],
192  (uint16_t *)in_lines_cur8[1],
193  (uint16_t *)in_lines_cur8[2],
194  (uint16_t *)in_lines_cur8[3] };
195  int i;
196 
197  linesize /= 2;
198  for (i = 0; i < linesize; i++) {
199  *work_line = *in_lines_cur[0]++ * coef[0];
200  *work_line += *in_lines_cur[1]++ * coef[1];
201  *work_line += *in_lines_cur[2]++ * coef[2];
202  *work_line++ += *in_lines_cur[3]++ * coef[3];
203  }
204 }
205 
206 static void filter16_simple_high(int32_t *work_line,
207  uint8_t *in_lines_cur8[3],
208  uint8_t *in_lines_adj8[3],
209  const int16_t *coef, int linesize)
210 {
211  uint16_t *in_lines_cur[3] = { (uint16_t *)in_lines_cur8[0],
212  (uint16_t *)in_lines_cur8[1],
213  (uint16_t *)in_lines_cur8[2] };
214  uint16_t *in_lines_adj[3] = { (uint16_t *)in_lines_adj8[0],
215  (uint16_t *)in_lines_adj8[1],
216  (uint16_t *)in_lines_adj8[2] };
217  int i;
218 
219  linesize /= 2;
220  for (i = 0; i < linesize; i++) {
221  *work_line += *in_lines_cur[0]++ * coef[0];
222  *work_line += *in_lines_adj[0]++ * coef[0];
223  *work_line += *in_lines_cur[1]++ * coef[1];
224  *work_line += *in_lines_adj[1]++ * coef[1];
225  *work_line += *in_lines_cur[2]++ * coef[2];
226  *work_line++ += *in_lines_adj[2]++ * coef[2];
227  }
228 }
229 
230 static void filter16_complex_high(int32_t *work_line,
231  uint8_t *in_lines_cur8[5],
232  uint8_t *in_lines_adj8[5],
233  const int16_t *coef, int linesize)
234 {
235  uint16_t *in_lines_cur[5] = { (uint16_t *)in_lines_cur8[0],
236  (uint16_t *)in_lines_cur8[1],
237  (uint16_t *)in_lines_cur8[2],
238  (uint16_t *)in_lines_cur8[3],
239  (uint16_t *)in_lines_cur8[4] };
240  uint16_t *in_lines_adj[5] = { (uint16_t *)in_lines_adj8[0],
241  (uint16_t *)in_lines_adj8[1],
242  (uint16_t *)in_lines_adj8[2],
243  (uint16_t *)in_lines_adj8[3],
244  (uint16_t *)in_lines_adj8[4] };
245  int i;
246 
247  linesize /= 2;
248  for (i = 0; i < linesize; i++) {
249  *work_line += *in_lines_cur[0]++ * coef[0];
250  *work_line += *in_lines_adj[0]++ * coef[0];
251  *work_line += *in_lines_cur[1]++ * coef[1];
252  *work_line += *in_lines_adj[1]++ * coef[1];
253  *work_line += *in_lines_cur[2]++ * coef[2];
254  *work_line += *in_lines_adj[2]++ * coef[2];
255  *work_line += *in_lines_cur[3]++ * coef[3];
256  *work_line += *in_lines_adj[3]++ * coef[3];
257  *work_line += *in_lines_cur[4]++ * coef[4];
258  *work_line++ += *in_lines_adj[4]++ * coef[4];
259  }
260 }
261 
262 static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
263 {
264  uint16_t *out_pixel = (uint16_t *)out_pixel8;
265  int j;
266 
267  linesize /= 2;
268  for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
269  *out_pixel = av_clip(*work_pixel, 0, max) >> 15;
270 }
271 
273 {
274  AVFilterContext *ctx = inlink->dst;
275  W3FDIFContext *s = ctx->priv;
277  int ret, i, depth, nb_threads;
278 
279  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
280  return ret;
281 
282  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
283  s->planeheight[0] = s->planeheight[3] = inlink->h;
284 
285  if (inlink->h < 3) {
286  av_log(ctx, AV_LOG_ERROR, "Video of less than 3 lines is not supported\n");
287  return AVERROR(EINVAL);
288  }
289 
290  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
291  nb_threads = ff_filter_get_nb_threads(ctx);
292  s->work_line = av_calloc(nb_threads, sizeof(*s->work_line));
293  if (!s->work_line)
294  return AVERROR(ENOMEM);
295  s->nb_threads = nb_threads;
296 
297  for (i = 0; i < s->nb_threads; i++) {
298  s->work_line[i] = av_calloc(FFALIGN(s->linesize[0], 32), sizeof(*s->work_line[0]));
299  if (!s->work_line[i])
300  return AVERROR(ENOMEM);
301  }
302 
303  depth = desc->comp[0].depth;
304  s->max = ((1 << depth) - 1) * 256 * 128;
305  if (depth <= 8) {
306  s->dsp.filter_simple_low = filter_simple_low;
307  s->dsp.filter_complex_low = filter_complex_low;
308  s->dsp.filter_simple_high = filter_simple_high;
309  s->dsp.filter_complex_high = filter_complex_high;
310  s->dsp.filter_scale = filter_scale;
311  } else {
312  s->dsp.filter_simple_low = filter16_simple_low;
313  s->dsp.filter_complex_low = filter16_complex_low;
314  s->dsp.filter_simple_high = filter16_simple_high;
315  s->dsp.filter_complex_high = filter16_complex_high;
316  s->dsp.filter_scale = filter16_scale;
317  }
318 
319 #if ARCH_X86
320  ff_w3fdif_init_x86(&s->dsp, depth);
321 #endif
322 
323  return 0;
324 }
325 
326 static int config_output(AVFilterLink *outlink)
327 {
328  AVFilterContext *ctx = outlink->src;
329  AVFilterLink *inlink = ctx->inputs[0];
330  W3FDIFContext *s = ctx->priv;
331 
332  outlink->time_base = av_mul_q(inlink->time_base, (AVRational){1, 2});
333  if (s->mode)
334  outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){2, 1});
335 
336  return 0;
337 }
338 
339 /*
340  * Filter coefficients from PH-2071, scaled by 256 * 128.
341  * Each set of coefficients has a set for low-frequencies and high-frequencies.
342  * n_coef_lf[] and n_coef_hf[] are the number of coefs for simple and more-complex.
343  * It is important for later that n_coef_lf[] is even and n_coef_hf[] is odd.
344  * coef_lf[][] and coef_hf[][] are the coefficients for low-frequencies
345  * and high-frequencies for simple and more-complex mode.
346  */
347 static const int8_t n_coef_lf[2] = { 2, 4 };
348 static const int16_t coef_lf[2][4] = {{ 16384, 16384, 0, 0},
349  { -852, 17236, 17236, -852}};
350 static const int8_t n_coef_hf[2] = { 3, 5 };
351 static const int16_t coef_hf[2][5] = {{ -2048, 4096, -2048, 0, 0},
352  { 1016, -3801, 5570, -3801, 1016}};
353 
354 typedef struct ThreadData {
356 } ThreadData;
357 
359  int jobnr, int nb_jobs, int plane)
360 {
361  W3FDIFContext *s = ctx->priv;
362  ThreadData *td = arg;
363  AVFrame *out = td->out;
364  AVFrame *cur = td->cur;
365  AVFrame *adj = td->adj;
366  const int filter = s->filter;
367  uint8_t *in_line, *in_lines_cur[5], *in_lines_adj[5];
368  uint8_t *out_line, *out_pixel;
369  int32_t *work_line, *work_pixel;
370  uint8_t *cur_data = cur->data[plane];
371  uint8_t *adj_data = adj->data[plane];
372  uint8_t *dst_data = out->data[plane];
373  const int linesize = s->linesize[plane];
374  const int height = s->planeheight[plane];
375  const int cur_line_stride = cur->linesize[plane];
376  const int adj_line_stride = adj->linesize[plane];
377  const int dst_line_stride = out->linesize[plane];
378  const int start = (height * jobnr) / nb_jobs;
379  const int end = (height * (jobnr+1)) / nb_jobs;
380  const int max = s->max;
381  const int interlaced = !!(cur->flags & AV_FRAME_FLAG_INTERLACED);
382  const int tff = s->field == (s->parity == -1 ? interlaced ? !!(cur->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) : 1 :
383  s->parity ^ 1);
384  int j, y_in, y_out;
385 
386  /* copy unchanged the lines of the field */
387  y_out = start + (tff ^ (start & 1));
388 
389  in_line = cur_data + (y_out * cur_line_stride);
390  out_line = dst_data + (y_out * dst_line_stride);
391 
392  while (y_out < end) {
393  memcpy(out_line, in_line, linesize);
394  y_out += 2;
395  in_line += cur_line_stride * 2;
396  out_line += dst_line_stride * 2;
397  }
398 
399  /* interpolate other lines of the field */
400  y_out = start + ((!tff) ^ (start & 1));
401 
402  out_line = dst_data + (y_out * dst_line_stride);
403 
404  while (y_out < end) {
405  /* get low vertical frequencies from current field */
406  for (j = 0; j < n_coef_lf[filter]; j++) {
407  y_in = (y_out + 1) + (j * 2) - n_coef_lf[filter];
408 
409  while (y_in < 0)
410  y_in += 2;
411  while (y_in >= height)
412  y_in -= 2;
413 
414  in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
415  }
416 
417  work_line = s->work_line[jobnr];
418  switch (n_coef_lf[filter]) {
419  case 2:
420  s->dsp.filter_simple_low(work_line, in_lines_cur,
421  coef_lf[filter], linesize);
422  break;
423  case 4:
424  s->dsp.filter_complex_low(work_line, in_lines_cur,
425  coef_lf[filter], linesize);
426  }
427 
428  /* get high vertical frequencies from adjacent fields */
429  for (j = 0; j < n_coef_hf[filter]; j++) {
430  y_in = (y_out + 1) + (j * 2) - n_coef_hf[filter];
431 
432  while (y_in < 0)
433  y_in += 2;
434  while (y_in >= height)
435  y_in -= 2;
436 
437  in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
438  in_lines_adj[j] = adj_data + (y_in * adj_line_stride);
439  }
440 
441  work_line = s->work_line[jobnr];
442  switch (n_coef_hf[filter]) {
443  case 3:
444  s->dsp.filter_simple_high(work_line, in_lines_cur, in_lines_adj,
445  coef_hf[filter], linesize);
446  break;
447  case 5:
448  s->dsp.filter_complex_high(work_line, in_lines_cur, in_lines_adj,
449  coef_hf[filter], linesize);
450  }
451 
452  /* save scaled result to the output frame, scaling down by 256 * 128 */
453  work_pixel = s->work_line[jobnr];
454  out_pixel = out_line;
455 
456  s->dsp.filter_scale(out_pixel, work_pixel, linesize, max);
457 
458  /* move on to next line */
459  y_out += 2;
460  out_line += dst_line_stride * 2;
461  }
462 
463  return 0;
464 }
465 
467  int jobnr, int nb_jobs)
468 {
469  W3FDIFContext *s = ctx->priv;
470 
471  for (int p = 0; p < s->nb_planes; p++)
472  deinterlace_plane_slice(ctx, arg, jobnr, nb_jobs, p);
473 
474  return 0;
475 }
476 
477 static int filter(AVFilterContext *ctx, int is_second)
478 {
479  W3FDIFContext *s = ctx->priv;
480  AVFilterLink *outlink = ctx->outputs[0];
481  AVFrame *out, *adj;
482  ThreadData td;
483 
484  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
485  if (!out)
486  return AVERROR(ENOMEM);
487  av_frame_copy_props(out, s->cur);
488 #if FF_API_INTERLACED_FRAME
490  out->interlaced_frame = 0;
492 #endif
493  out->flags &= ~AV_FRAME_FLAG_INTERLACED;
494 
495  if (!is_second) {
496  if (out->pts != AV_NOPTS_VALUE)
497  out->pts *= 2;
498  } else {
499  int64_t cur_pts = s->cur->pts;
500  int64_t next_pts = s->next->pts;
501 
502  if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
503  out->pts = cur_pts + next_pts;
504  } else {
505  out->pts = AV_NOPTS_VALUE;
506  }
507  }
508 
509  adj = s->field ? s->next : s->prev;
510  td.out = out; td.cur = s->cur; td.adj = adj;
512  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->prev)
538  return 0;
539 
540  if ((s->deint && !(s->cur->flags & AV_FRAME_FLAG_INTERLACED)) || ctx->is_disabled) {
541  AVFrame *out = av_frame_clone(s->cur);
542  if (!out)
543  return AVERROR(ENOMEM);
544 
545  av_frame_free(&s->prev);
546  if (out->pts != AV_NOPTS_VALUE)
547  out->pts *= 2;
548  return ff_filter_frame(ctx->outputs[0], out);
549  }
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) {
570  AVFrame *next = av_frame_clone(s->next);
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 };
606 
607 static const AVFilterPad w3fdif_outputs[] = {
608  {
609  .name = "default",
610  .type = AVMEDIA_TYPE_VIDEO,
611  .config_props = config_output,
612  .request_frame = request_frame,
613  },
614 };
615 
617  .name = "w3fdif",
618  .description = NULL_IF_CONFIG_SMALL("Apply Martin Weston three field deinterlace."),
619  .priv_size = sizeof(W3FDIFContext),
620  .priv_class = &w3fdif_class,
621  .uninit = uninit,
626  .process_command = ff_filter_process_command,
627 };
W3FDIFContext::linesize
int linesize[4]
bytes of pixel data per line for each plane
Definition: vf_w3fdif.c:39
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:112
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:522
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:501
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
W3FDIFContext::parity
int parity
frame field parity
Definition: vf_w3fdif.c:37
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
av_clip
#define av_clip
Definition: common.h:98
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
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:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
W3FDIFContext::max
int max
Definition: vf_w3fdif.c:47
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:162
ff_w3fdif_init_x86
void ff_w3fdif_init_x86(W3FDIFDSPContext *dsp, int depth)
Definition: vf_w3fdif_init.c:48
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:160
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:514
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:487
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:521
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:516
AVOption
AVOption.
Definition: opt.h:346
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
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:462
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: vf_w3fdif.c:558
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:647
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:526
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:517
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:458
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:396
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:639
W3FDIFContext::filter
int filter
0 is simple, 1 is more complex
Definition: vf_w3fdif.c:35
coef_hf
static const int16_t coef_hf[2][5]
Definition: vf_w3fdif.c:351
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3002
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:513
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:496
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:494
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:523
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:476
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
w3fdif_outputs
static const AVFilterPad w3fdif_outputs[]
Definition: vf_w3fdif.c:607
W3FDIFContext::prev
AVFrame * prev
Definition: vf_w3fdif.c:44
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_w3fdif.c:272
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:283
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_w3fdif.c:583
filter16_scale
static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
Definition: vf_w3fdif.c:262
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_w3fdif.c:75
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:490
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:86
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:498
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:198
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:499
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:108
W3FDIFContext::cur
AVFrame * cur
Definition: vf_w3fdif.c:44
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:491
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:466
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:127
coef_lf
static const int16_t coef_lf[2][4]
Definition: vf_w3fdif.c:348
W3FDIFContext::dsp
W3FDIFDSPContext dsp
Definition: vf_w3fdif.c:49
W3FDIFContext
Definition: vf_w3fdif.c:33
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:520
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:475
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:489
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:461
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:593
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:113
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:73
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
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:87
arg
const char * arg
Definition: jacosubdec.c:67
W3FDIFDSPContext
Definition: w3fdif.h:27
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:497
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:709
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:480
W3FDIFContext::eof
int eof
Definition: vf_w3fdif.c:42
W3FDIFContext::work_line
int32_t ** work_line
lines we are calculating
Definition: vf_w3fdif.c:45
w3fdif.h
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:493
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_w3fdif.c:520
W3FDIFContext::deint
int deint
which frames to deinterlace
Definition: vf_w3fdif.c:38
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_w3fdif.c:326
w3fdif_inputs
static const AVFilterPad w3fdif_inputs[]
Definition: vf_w3fdif.c:598
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:106
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(w3fdif)
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
parity
mcdeint parity
Definition: vf_mcdeint.c:281
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
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:230
filter_scale
static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
Definition: vf_w3fdif.c:165
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:890
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:101
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
ThreadData::adj
AVFrame * adj
Definition: vf_w3fdif.c:355
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:518
w3fdif_options
static const AVOption w3fdif_options[]
Definition: vf_w3fdif.c:56
internal.h
FLAGS
#define FLAGS
Definition: vf_w3fdif.c:53
ff_vf_w3fdif
const AVFilter ff_vf_w3fdif
Definition: vf_w3fdif.c:616
interlaced
uint8_t interlaced
Definition: mxfenc.c:2263
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
W3FDIFContext::nb_planes
int nb_planes
Definition: vf_w3fdif.c:43
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:495
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:825
ThreadData
Used for passing data between threads.
Definition: dsddec.c:69
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:107
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:634
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:477
AVFilter
Filter definition.
Definition: avfilter.h:166
ThreadData::cur
AVFrame * cur
Definition: vf_w3fdif.c:355
ret
ret
Definition: filter_design.txt:187
W3FDIFContext::field
int field
which field are we on, 0 or 1
Definition: vf_w3fdif.c:41
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_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:515
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
W3FDIFContext::planeheight
int planeheight[4]
height of each plane
Definition: vf_w3fdif.c:40
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:487
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:187
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:206
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
W3FDIFContext::next
AVFrame * next
previous, current, next frames
Definition: vf_w3fdif.c:44
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:519
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
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:173
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:144
W3FDIFContext::mode
int mode
0 is frame, 1 is field
Definition: vf_w3fdif.c:36
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
n_coef_lf
static const int8_t n_coef_lf[2]
Definition: vf_w3fdif.c:347
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:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
filter
static int filter(AVFilterContext *ctx, int is_second)
Definition: vf_w3fdif.c:477
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
desc
const char * desc
Definition: libsvtav1.c:75
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:77
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
deinterlace_plane_slice
static int deinterlace_plane_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int plane)
Definition: vf_w3fdif.c:358
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:80
int32_t
int32_t
Definition: audioconvert.c:56
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:155
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:420
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:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
W3FDIFContext::nb_threads
int nb_threads
Definition: vf_w3fdif.c:46
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:484
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:488
CONST
#define CONST(name, help, val, u)
Definition: vf_w3fdif.c:54
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:134
n_coef_hf
static const int8_t n_coef_hf[2]
Definition: vf_w3fdif.c:350
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:173
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:486
OFFSET
#define OFFSET(x)
Definition: vf_w3fdif.c:52