FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_tinterlace.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * Copyright (c) 2010 Baptiste Coudurier
4  * Copyright (c) 2003 Michael Zucchi <notzed@ximian.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with FFmpeg if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 /**
24  * @file
25  * temporal field interlace filter, ported from MPlayer/libmpcodecs
26  */
27 
28 #include "libavutil/opt.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/avassert.h"
31 #include "avfilter.h"
32 #include "internal.h"
33 #include "tinterlace.h"
34 
35 #define OFFSET(x) offsetof(TInterlaceContext, x)
36 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
37 #define TINTERLACE_FLAG_VLPF 01
38 #define TINTERLACE_FLAG_EXACT_TB 2
39 
40 static const AVOption tinterlace_options[] = {
41  {"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_MERGE}, 0, MODE_NB-1, FLAGS, "mode"},
42  {"merge", "merge fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_MERGE}, INT_MIN, INT_MAX, FLAGS, "mode"},
43  {"drop_even", "drop even fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_EVEN}, INT_MIN, INT_MAX, FLAGS, "mode"},
44  {"drop_odd", "drop odd fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_ODD}, INT_MIN, INT_MAX, FLAGS, "mode"},
45  {"pad", "pad alternate lines with black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PAD}, INT_MIN, INT_MAX, FLAGS, "mode"},
46  {"interleave_top", "interleave top and bottom fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_TOP}, INT_MIN, INT_MAX, FLAGS, "mode"},
47  {"interleave_bottom", "interleave bottom and top fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, "mode"},
48  {"interlacex2", "interlace fields from two consecutive frames", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLACEX2}, INT_MIN, INT_MAX, FLAGS, "mode"},
49 
50  {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, 0, "flags" },
51  {"low_pass_filter", "enable vertical low-pass filter", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
52  {"vlpf", "enable vertical low-pass filter", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
53  {"exact_tb", "force a timebase which can represent timestamps exactly", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_EXACT_TB}, INT_MIN, INT_MAX, FLAGS, "flags" },
54 
55  {NULL}
56 };
57 
58 AVFILTER_DEFINE_CLASS(tinterlace);
59 
60 #define FULL_SCALE_YUVJ_FORMATS \
61  AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P
62 
63 static const enum AVPixelFormat full_scale_yuvj_pix_fmts[] = {
65 };
66 
67 static const AVRational standard_tbs[] = {
68  {1, 25},
69  {1, 30},
70  {1001, 30000},
71 };
72 
74 {
75  static const enum AVPixelFormat pix_fmts[] = {
82  };
83 
84  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
85  if (!fmts_list)
86  return AVERROR(ENOMEM);
87  return ff_set_common_formats(ctx, fmts_list);
88 }
89 
90 static void lowpass_line_c(uint8_t *dstp, ptrdiff_t width, const uint8_t *srcp,
91  const uint8_t *srcp_above, const uint8_t *srcp_below)
92 {
93  int i;
94  for (i = 0; i < width; i++) {
95  // this calculation is an integer representation of
96  // '0.5 * current + 0.25 * above + 0.25 * below'
97  // '1 +' is for rounding.
98  dstp[i] = (1 + srcp[i] + srcp[i] + srcp_above[i] + srcp_below[i]) >> 2;
99  }
100 }
101 
102 static av_cold void uninit(AVFilterContext *ctx)
103 {
104  TInterlaceContext *tinterlace = ctx->priv;
105 
106  av_frame_free(&tinterlace->cur );
107  av_frame_free(&tinterlace->next);
108  av_freep(&tinterlace->black_data[0]);
109 }
110 
111 static int config_out_props(AVFilterLink *outlink)
112 {
113  AVFilterContext *ctx = outlink->src;
114  AVFilterLink *inlink = outlink->src->inputs[0];
115  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
116  TInterlaceContext *tinterlace = ctx->priv;
117  int i;
118 
119  tinterlace->vsub = desc->log2_chroma_h;
120  outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
121  outlink->w = inlink->w;
122  outlink->h = tinterlace->mode == MODE_MERGE || tinterlace->mode == MODE_PAD ?
123  inlink->h*2 : inlink->h;
124  if (tinterlace->mode == MODE_MERGE || tinterlace->mode == MODE_PAD)
126  av_make_q(2, 1));
127 
128  if (tinterlace->mode == MODE_PAD) {
129  uint8_t black[4] = { 16, 128, 128, 16 };
130  int i, ret;
132  black[0] = black[3] = 0;
133  ret = av_image_alloc(tinterlace->black_data, tinterlace->black_linesize,
134  outlink->w, outlink->h, outlink->format, 1);
135  if (ret < 0)
136  return ret;
137 
138  /* fill black picture with black */
139  for (i = 0; i < 4 && tinterlace->black_data[i]; i++) {
140  int h = i == 1 || i == 2 ? FF_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h) : outlink->h;
141  memset(tinterlace->black_data[i], black[i],
142  tinterlace->black_linesize[i] * h);
143  }
144  }
145  if ((tinterlace->flags & TINTERLACE_FLAG_VLPF)
146  && !(tinterlace->mode == MODE_INTERLEAVE_TOP
147  || tinterlace->mode == MODE_INTERLEAVE_BOTTOM)) {
148  av_log(ctx, AV_LOG_WARNING, "low_pass_filter flag ignored with mode %d\n",
149  tinterlace->mode);
150  tinterlace->flags &= ~TINTERLACE_FLAG_VLPF;
151  }
152  tinterlace->preout_time_base = inlink->time_base;
153  if (tinterlace->mode == MODE_INTERLACEX2) {
154  tinterlace->preout_time_base.den *= 2;
155  outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){2,1});
156  outlink->time_base = av_mul_q(inlink->time_base , (AVRational){1,2});
157  } else if (tinterlace->mode != MODE_PAD) {
158  outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){1,2});
159  outlink->time_base = av_mul_q(inlink->time_base , (AVRational){2,1});
160  }
161 
162  for (i = 0; i<FF_ARRAY_ELEMS(standard_tbs); i++){
163  if (!av_cmp_q(standard_tbs[i], outlink->time_base))
164  break;
165  }
166  if (i == FF_ARRAY_ELEMS(standard_tbs) ||
167  (tinterlace->flags & TINTERLACE_FLAG_EXACT_TB))
168  outlink->time_base = tinterlace->preout_time_base;
169 
170  if (tinterlace->flags & TINTERLACE_FLAG_VLPF) {
171  tinterlace->lowpass_line = lowpass_line_c;
172  if (ARCH_X86)
173  ff_tinterlace_init_x86(tinterlace);
174  }
175 
176  av_log(ctx, AV_LOG_VERBOSE, "mode:%d filter:%s h:%d -> h:%d\n",
177  tinterlace->mode, (tinterlace->flags & TINTERLACE_FLAG_VLPF) ? "on" : "off",
178  inlink->h, outlink->h);
179 
180  return 0;
181 }
182 
183 #define FIELD_UPPER 0
184 #define FIELD_LOWER 1
185 #define FIELD_UPPER_AND_LOWER 2
186 
187 /**
188  * Copy picture field from src to dst.
189  *
190  * @param src_field copy from upper, lower field or both
191  * @param interleave leave a padding line between each copied line
192  * @param dst_field copy to upper or lower field,
193  * only meaningful when interleave is selected
194  * @param flags context flags
195  */
196 static inline
198  uint8_t *dst[4], int dst_linesize[4],
199  const uint8_t *src[4], int src_linesize[4],
200  enum AVPixelFormat format, int w, int src_h,
201  int src_field, int interleave, int dst_field,
202  int flags)
203 {
204  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
205  int hsub = desc->log2_chroma_w;
206  int plane, vsub = desc->log2_chroma_h;
207  int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;
208  int h;
209 
210  for (plane = 0; plane < desc->nb_components; plane++) {
211  int lines = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(src_h, vsub) : src_h;
212  int cols = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT( w, hsub) : w;
213  uint8_t *dstp = dst[plane];
214  const uint8_t *srcp = src[plane];
215 
216  lines = (lines + (src_field == FIELD_UPPER)) / k;
217  if (src_field == FIELD_LOWER)
218  srcp += src_linesize[plane];
219  if (interleave && dst_field == FIELD_LOWER)
220  dstp += dst_linesize[plane];
221  if (flags & TINTERLACE_FLAG_VLPF) {
222  // Low-pass filtering is required when creating an interlaced destination from
223  // a progressive source which contains high-frequency vertical detail.
224  // Filtering will reduce interlace 'twitter' and Moire patterning.
225  int srcp_linesize = src_linesize[plane] * k;
226  int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);
227  for (h = lines; h > 0; h--) {
228  const uint8_t *srcp_above = srcp - src_linesize[plane];
229  const uint8_t *srcp_below = srcp + src_linesize[plane];
230  if (h == lines) srcp_above = srcp; // there is no line above
231  if (h == 1) srcp_below = srcp; // there is no line below
232 
233  tinterlace->lowpass_line(dstp, cols, srcp, srcp_above, srcp_below);
234  dstp += dstp_linesize;
235  srcp += srcp_linesize;
236  }
237  } else {
238  av_image_copy_plane(dstp, dst_linesize[plane] * (interleave ? 2 : 1),
239  srcp, src_linesize[plane]*k, cols, lines);
240  }
241  }
242 }
243 
244 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
245 {
246  AVFilterContext *ctx = inlink->dst;
247  AVFilterLink *outlink = ctx->outputs[0];
248  TInterlaceContext *tinterlace = ctx->priv;
249  AVFrame *cur, *next, *out;
250  int field, tff, ret;
251 
252  av_frame_free(&tinterlace->cur);
253  tinterlace->cur = tinterlace->next;
254  tinterlace->next = picref;
255 
256  cur = tinterlace->cur;
257  next = tinterlace->next;
258  /* we need at least two frames */
259  if (!tinterlace->cur)
260  return 0;
261 
262  switch (tinterlace->mode) {
263  case MODE_MERGE: /* move the odd frame into the upper field of the new image, even into
264  * the lower field, generating a double-height video at half framerate */
265  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
266  if (!out)
267  return AVERROR(ENOMEM);
268  av_frame_copy_props(out, cur);
269  out->height = outlink->h;
270  out->interlaced_frame = 1;
271  out->top_field_first = 1;
273 
274  /* write odd frame lines into the upper field of the new frame */
275  copy_picture_field(tinterlace, out->data, out->linesize,
276  (const uint8_t **)cur->data, cur->linesize,
277  inlink->format, inlink->w, inlink->h,
278  FIELD_UPPER_AND_LOWER, 1, FIELD_UPPER, tinterlace->flags);
279  /* write even frame lines into the lower field of the new frame */
280  copy_picture_field(tinterlace, out->data, out->linesize,
281  (const uint8_t **)next->data, next->linesize,
282  inlink->format, inlink->w, inlink->h,
283  FIELD_UPPER_AND_LOWER, 1, FIELD_LOWER, tinterlace->flags);
284  av_frame_free(&tinterlace->next);
285  break;
286 
287  case MODE_DROP_ODD: /* only output even frames, odd frames are dropped; height unchanged, half framerate */
288  case MODE_DROP_EVEN: /* only output odd frames, even frames are dropped; height unchanged, half framerate */
289  out = av_frame_clone(tinterlace->mode == MODE_DROP_EVEN ? cur : next);
290  if (!out)
291  return AVERROR(ENOMEM);
292  av_frame_free(&tinterlace->next);
293  break;
294 
295  case MODE_PAD: /* expand each frame to double height, but pad alternate
296  * lines with black; framerate unchanged */
297  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
298  if (!out)
299  return AVERROR(ENOMEM);
300  av_frame_copy_props(out, cur);
301  out->height = outlink->h;
303 
304  field = (1 + tinterlace->frame) & 1 ? FIELD_UPPER : FIELD_LOWER;
305  /* copy upper and lower fields */
306  copy_picture_field(tinterlace, out->data, out->linesize,
307  (const uint8_t **)cur->data, cur->linesize,
308  inlink->format, inlink->w, inlink->h,
309  FIELD_UPPER_AND_LOWER, 1, field, tinterlace->flags);
310  /* pad with black the other field */
311  copy_picture_field(tinterlace, out->data, out->linesize,
312  (const uint8_t **)tinterlace->black_data, tinterlace->black_linesize,
313  inlink->format, inlink->w, inlink->h,
314  FIELD_UPPER_AND_LOWER, 1, !field, tinterlace->flags);
315  break;
316 
317  /* interleave upper/lower lines from odd frames with lower/upper lines from even frames,
318  * halving the frame rate and preserving image height */
319  case MODE_INTERLEAVE_TOP: /* top field first */
320  case MODE_INTERLEAVE_BOTTOM: /* bottom field first */
321  tff = tinterlace->mode == MODE_INTERLEAVE_TOP;
322  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
323  if (!out)
324  return AVERROR(ENOMEM);
325  av_frame_copy_props(out, cur);
326  out->interlaced_frame = 1;
327  out->top_field_first = tff;
328 
329  /* copy upper/lower field from cur */
330  copy_picture_field(tinterlace, out->data, out->linesize,
331  (const uint8_t **)cur->data, cur->linesize,
332  inlink->format, inlink->w, inlink->h,
333  tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER,
334  tinterlace->flags);
335  /* copy lower/upper field from next */
336  copy_picture_field(tinterlace, out->data, out->linesize,
337  (const uint8_t **)next->data, next->linesize,
338  inlink->format, inlink->w, inlink->h,
339  tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER,
340  tinterlace->flags);
341  av_frame_free(&tinterlace->next);
342  break;
343  case MODE_INTERLACEX2: /* re-interlace preserving image height, double frame rate */
344  /* output current frame first */
345  out = av_frame_clone(cur);
346  if (!out)
347  return AVERROR(ENOMEM);
348  out->interlaced_frame = 1;
349  if (cur->pts != AV_NOPTS_VALUE)
350  out->pts = cur->pts*2;
351 
352  out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base);
353  if ((ret = ff_filter_frame(outlink, out)) < 0)
354  return ret;
355 
356  /* output mix of current and next frame */
357  tff = next->top_field_first;
358  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
359  if (!out)
360  return AVERROR(ENOMEM);
361  av_frame_copy_props(out, next);
362  out->interlaced_frame = 1;
363  out->top_field_first = !tff;
364 
365  if (next->pts != AV_NOPTS_VALUE && cur->pts != AV_NOPTS_VALUE)
366  out->pts = cur->pts + next->pts;
367  else
368  out->pts = AV_NOPTS_VALUE;
369  /* write current frame second field lines into the second field of the new frame */
370  copy_picture_field(tinterlace, out->data, out->linesize,
371  (const uint8_t **)cur->data, cur->linesize,
372  inlink->format, inlink->w, inlink->h,
373  tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER,
374  tinterlace->flags);
375  /* write next frame first field lines into the first field of the new frame */
376  copy_picture_field(tinterlace, out->data, out->linesize,
377  (const uint8_t **)next->data, next->linesize,
378  inlink->format, inlink->w, inlink->h,
379  tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER,
380  tinterlace->flags);
381  break;
382  default:
383  av_assert0(0);
384  }
385 
386  out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base);
387  ret = ff_filter_frame(outlink, out);
388  tinterlace->frame++;
389 
390  return ret;
391 }
392 
393 static const AVFilterPad tinterlace_inputs[] = {
394  {
395  .name = "default",
396  .type = AVMEDIA_TYPE_VIDEO,
397  .filter_frame = filter_frame,
398  },
399  { NULL }
400 };
401 
402 static const AVFilterPad tinterlace_outputs[] = {
403  {
404  .name = "default",
405  .type = AVMEDIA_TYPE_VIDEO,
406  .config_props = config_out_props,
407  },
408  { NULL }
409 };
410 
412  .name = "tinterlace",
413  .description = NULL_IF_CONFIG_SMALL("Perform temporal field interlacing."),
414  .priv_size = sizeof(TInterlaceContext),
415  .uninit = uninit,
417  .inputs = tinterlace_inputs,
418  .outputs = tinterlace_outputs,
419  .priv_class = &tinterlace_class,
420 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat full_scale_yuvj_pix_fmts[]
Definition: vf_tinterlace.c:63
static int query_formats(AVFilterContext *ctx)
Definition: vf_tinterlace.c:73
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2129
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
#define OFFSET(x)
Definition: vf_tinterlace.c:35
AVOption.
Definition: opt.h:255
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
AVFrame * next
Definition: tinterlace.h:52
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:192
#define FIELD_LOWER
int mode
TInterlaceMode, interlace mode selected.
Definition: tinterlace.h:46
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:66
static av_always_inline void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
Definition: dirac_dwt.c:40
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
static AVRational av_make_q(int num, int den)
Create a rational.
Definition: rational.h:53
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
int flags
flags affecting interlacing algorithm
Definition: tinterlace.h:48
AVFilter ff_vf_tinterlace
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define FULL_SCALE_YUVJ_FORMATS
Definition: vf_tinterlace.c:60
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
const char * name
Pad name.
Definition: internal.h:69
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:103
uint8_t
#define av_cold
Definition: attributes.h:74
static const AVOption tinterlace_options[]
Definition: vf_tinterlace.c:40
temporal field interlace filter, ported from MPlayer/libmpcodecs
mode
Definition: f_perms.c:27
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
int frame
number of the output frame
Definition: tinterlace.h:49
static void lowpass_line_c(uint8_t *dstp, ptrdiff_t width, const uint8_t *srcp, const uint8_t *srcp_above, const uint8_t *srcp_below)
Definition: vf_tinterlace.c:90
int black_linesize[4]
Definition: tinterlace.h:54
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:367
int ff_fmt_is_in(int fmt, const int *fmts)
Tell is a format is contained in the provided list terminated by -1.
Definition: formats.c:254
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:63
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:281
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:542
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
void ff_tinterlace_init_x86(TInterlaceContext *interlace)
int vsub
chroma vertical subsampling
Definition: tinterlace.h:50
BYTE * dstp
Definition: avisynth_c.h:676
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define FLAGS
Definition: vf_tinterlace.c:36
static void copy_picture_field(TInterlaceContext *tinterlace, uint8_t *dst[4], int dst_linesize[4], const uint8_t *src[4], int src_linesize[4], enum AVPixelFormat format, int w, int src_h, int src_field, int interleave, int dst_field, int flags)
Copy picture field from src to dst.
simple assert() macros that are a bit more flexible than ISO C assert().
AVFILTER_DEFINE_CLASS(tinterlace)
#define TINTERLACE_FLAG_EXACT_TB
Definition: vf_tinterlace.c:38
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
#define FIELD_UPPER
static av_cold void uninit(AVFilterContext *ctx)
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
static const AVFilterPad tinterlace_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Frame requests may need to loop in order to be fulfilled.
Definition: internal.h:374
static const AVRational standard_tbs[]
Definition: vf_tinterlace.c:67
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:451
#define FF_ARRAY_ELEMS(a)
AVS_Value src
Definition: avisynth_c.h:482
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:280
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:252
uint8_t * black_data[4]
buffer used to fill padded lines
Definition: tinterlace.h:53
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
rational number numerator/denominator
Definition: rational.h:43
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
AVFrame * cur
Definition: tinterlace.h:51
static const AVFilterPad tinterlace_inputs[]
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
static int config_out_props(AVFilterLink *outlink)
void(* lowpass_line)(uint8_t *dstp, ptrdiff_t width, const uint8_t *srcp, const uint8_t *srcp_above, const uint8_t *srcp_below)
Definition: tinterlace.h:55
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
int den
denominator
Definition: rational.h:45
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:372
A list of supported formats for one end of a filter link.
Definition: formats.h:64
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
An instance of a filter.
Definition: avfilter.h:633
int height
Definition: frame.h:220
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:273
internal API functions
#define FIELD_UPPER_AND_LOWER
AVRational preout_time_base
Definition: tinterlace.h:47
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:553
#define TINTERLACE_FLAG_VLPF
Definition: vf_tinterlace.c:37
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
static int width