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