FFmpeg  4.4.9
vf_perspective.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (c) 2013 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/eval.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/opt.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "filters.h"
30 #include "internal.h"
31 #include "video.h"
32 
33 #define SUB_PIXEL_BITS 8
34 #define SUB_PIXELS (1 << SUB_PIXEL_BITS)
35 #define COEFF_BITS 11
36 
37 #define LINEAR 0
38 #define CUBIC 1
39 
40 typedef struct PerspectiveContext {
41  const AVClass *class;
42  char *expr_str[4][2];
43  double ref[4][2];
44  int32_t (*pv)[2];
47  int linesize[4];
48  int height[4];
49  int hsub, vsub;
50  int nb_planes;
51  int sense;
52  int eval_mode;
53 
55  void *arg, int job, int nb_jobs);
57 
58 #define OFFSET(x) offsetof(PerspectiveContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
60 
62  PERSPECTIVE_SENSE_SOURCE = 0, ///< coordinates give locations in source of corners of destination.
63  PERSPECTIVE_SENSE_DESTINATION = 1, ///< coordinates give locations in destination of corners of source.
64 };
65 
66 enum EvalMode {
70 };
71 
72 static const AVOption perspective_options[] = {
73  { "x0", "set top left x coordinate", OFFSET(expr_str[0][0]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
74  { "y0", "set top left y coordinate", OFFSET(expr_str[0][1]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
75  { "x1", "set top right x coordinate", OFFSET(expr_str[1][0]), AV_OPT_TYPE_STRING, {.str="W"}, 0, 0, FLAGS },
76  { "y1", "set top right y coordinate", OFFSET(expr_str[1][1]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
77  { "x2", "set bottom left x coordinate", OFFSET(expr_str[2][0]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
78  { "y2", "set bottom left y coordinate", OFFSET(expr_str[2][1]), AV_OPT_TYPE_STRING, {.str="H"}, 0, 0, FLAGS },
79  { "x3", "set bottom right x coordinate", OFFSET(expr_str[3][0]), AV_OPT_TYPE_STRING, {.str="W"}, 0, 0, FLAGS },
80  { "y3", "set bottom right y coordinate", OFFSET(expr_str[3][1]), AV_OPT_TYPE_STRING, {.str="H"}, 0, 0, FLAGS },
81  { "interpolation", "set interpolation", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=LINEAR}, 0, 1, FLAGS, "interpolation" },
82  { "linear", "", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "interpolation" },
83  { "cubic", "", 0, AV_OPT_TYPE_CONST, {.i64=CUBIC}, 0, 0, FLAGS, "interpolation" },
84  { "sense", "specify the sense of the coordinates", OFFSET(sense), AV_OPT_TYPE_INT, {.i64=PERSPECTIVE_SENSE_SOURCE}, 0, 1, FLAGS, "sense"},
85  { "source", "specify locations in source to send to corners in destination",
86  0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE_SENSE_SOURCE}, 0, 0, FLAGS, "sense"},
87  { "destination", "specify locations in destination to send corners of source",
88  0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE_SENSE_DESTINATION}, 0, 0, FLAGS, "sense"},
89  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
90  { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
91  { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
92 
93  { NULL }
94 };
95 
96 AVFILTER_DEFINE_CLASS(perspective);
97 
99 {
100  static const enum AVPixelFormat pix_fmts[] = {
105  };
106 
108  if (!fmts_list)
109  return AVERROR(ENOMEM);
110  return ff_set_common_formats(ctx, fmts_list);
111 }
112 
113 static inline double get_coeff(double d)
114 {
115  double coeff, A = -0.60;
116 
117  d = fabs(d);
118 
119  if (d < 1.0)
120  coeff = (1.0 - (A + 3.0) * d * d + (A + 2.0) * d * d * d);
121  else if (d < 2.0)
122  coeff = (-4.0 * A + 8.0 * A * d - 5.0 * A * d * d + A * d * d * d);
123  else
124  coeff = 0.0;
125 
126  return coeff;
127 }
128 
129 static const char *const var_names[] = { "W", "H", "in", "on", NULL };
131 
133 {
134  PerspectiveContext *s = ctx->priv;
135  AVFilterLink *outlink = ctx->outputs[0];
136  double (*ref)[2] = s->ref;
137 
138  double values[VAR_VARS_NB] = { [VAR_W] = inlink->w, [VAR_H] = inlink->h,
139  [VAR_IN] = inlink->frame_count_out + 1,
140  [VAR_ON] = outlink->frame_count_in + 1 };
141  const int h = values[VAR_H];
142  const int w = values[VAR_W];
143  double x0, x1, x2, x3, x4, x5, x6, x7, x8, q;
144  double t0, t1, t2, t3;
145  int x, y, i, j, ret;
146 
147  for (i = 0; i < 4; i++) {
148  for (j = 0; j < 2; j++) {
149  if (!s->expr_str[i][j])
150  return AVERROR(EINVAL);
151  ret = av_expr_parse_and_eval(&s->ref[i][j], s->expr_str[i][j],
152  var_names, &values[0],
153  NULL, NULL, NULL, NULL,
154  0, 0, ctx);
155  if (ret < 0)
156  return ret;
157  }
158  }
159 
160  switch (s->sense) {
162  x6 = ((ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0]) *
163  (ref[2][1] - ref[3][1]) -
164  ( ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1]) *
165  (ref[2][0] - ref[3][0])) * h;
166  x7 = ((ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1]) *
167  (ref[1][0] - ref[3][0]) -
168  ( ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0]) *
169  (ref[1][1] - ref[3][1])) * w;
170  q = ( ref[1][0] - ref[3][0]) * (ref[2][1] - ref[3][1]) -
171  ( ref[2][0] - ref[3][0]) * (ref[1][1] - ref[3][1]);
172 
173  x0 = q * (ref[1][0] - ref[0][0]) * h + x6 * ref[1][0];
174  x1 = q * (ref[2][0] - ref[0][0]) * w + x7 * ref[2][0];
175  x2 = q * ref[0][0] * w * h;
176  x3 = q * (ref[1][1] - ref[0][1]) * h + x6 * ref[1][1];
177  x4 = q * (ref[2][1] - ref[0][1]) * w + x7 * ref[2][1];
178  x5 = q * ref[0][1] * w * h;
179  x8 = q * w * h;
180  break;
182  t0 = ref[0][0] * (ref[3][1] - ref[1][1]) +
183  ref[1][0] * (ref[0][1] - ref[3][1]) +
184  ref[3][0] * (ref[1][1] - ref[0][1]);
185  t1 = ref[1][0] * (ref[2][1] - ref[3][1]) +
186  ref[2][0] * (ref[3][1] - ref[1][1]) +
187  ref[3][0] * (ref[1][1] - ref[2][1]);
188  t2 = ref[0][0] * (ref[3][1] - ref[2][1]) +
189  ref[2][0] * (ref[0][1] - ref[3][1]) +
190  ref[3][0] * (ref[2][1] - ref[0][1]);
191  t3 = ref[0][0] * (ref[1][1] - ref[2][1]) +
192  ref[1][0] * (ref[2][1] - ref[0][1]) +
193  ref[2][0] * (ref[0][1] - ref[1][1]);
194 
195  x0 = t0 * t1 * w * (ref[2][1] - ref[0][1]);
196  x1 = t0 * t1 * w * (ref[0][0] - ref[2][0]);
197  x2 = t0 * t1 * w * (ref[0][1] * ref[2][0] - ref[0][0] * ref[2][1]);
198  x3 = t1 * t2 * h * (ref[1][1] - ref[0][1]);
199  x4 = t1 * t2 * h * (ref[0][0] - ref[1][0]);
200  x5 = t1 * t2 * h * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]);
201  x6 = t1 * t2 * (ref[1][1] - ref[0][1]) +
202  t0 * t3 * (ref[2][1] - ref[3][1]);
203  x7 = t1 * t2 * (ref[0][0] - ref[1][0]) +
204  t0 * t3 * (ref[3][0] - ref[2][0]);
205  x8 = t1 * t2 * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]) +
206  t0 * t3 * (ref[2][0] * ref[3][1] - ref[2][1] * ref[3][0]);
207  break;
208  default:
209  av_assert0(0);
210  }
211 
212  for (y = 0; y < h; y++){
213  for (x = 0; x < w; x++){
214  int u, v;
215 
216  u = lrint(SUB_PIXELS * (x0 * x + x1 * y + x2) /
217  (x6 * x + x7 * y + x8));
218  v = lrint(SUB_PIXELS * (x3 * x + x4 * y + x5) /
219  (x6 * x + x7 * y + x8));
220 
221  s->pv[x + y * w][0] = u;
222  s->pv[x + y * w][1] = v;
223  }
224  }
225 
226  return 0;
227 }
228 
229 static int config_input(AVFilterLink *inlink)
230 {
231  AVFilterContext *ctx = inlink->dst;
232  PerspectiveContext *s = ctx->priv;
234  int h = inlink->h;
235  int w = inlink->w;
236  int i, j, ret;
237  s->hsub = desc->log2_chroma_w;
238  s->vsub = desc->log2_chroma_h;
239  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
240  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
241  return ret;
242 
243  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
244  s->height[0] = s->height[3] = inlink->h;
245 
246  s->pv = av_realloc_f(s->pv, w * h, 2 * sizeof(*s->pv));
247  if (!s->pv)
248  return AVERROR(ENOMEM);
249 
250  if (s->eval_mode == EVAL_MODE_INIT) {
251  if ((ret = calc_persp_luts(ctx, inlink)) < 0) {
252  return ret;
253  }
254  }
255 
256  for (i = 0; i < SUB_PIXELS; i++){
257  double d = i / (double)SUB_PIXELS;
258  double temp[4];
259  double sum = 0;
260 
261  for (j = 0; j < 4; j++)
262  temp[j] = get_coeff(j - d - 1);
263 
264  for (j = 0; j < 4; j++)
265  sum += temp[j];
266 
267  for (j = 0; j < 4; j++)
268  s->coeff[i][j] = lrint((1 << COEFF_BITS) * temp[j] / sum);
269  }
270 
271  return 0;
272 }
273 
274 typedef struct ThreadData {
276  int dst_linesize;
278  int src_linesize;
279  int w, h;
280  int hsub, vsub;
281 } ThreadData;
282 
284  int job, int nb_jobs)
285 {
286  PerspectiveContext *s = ctx->priv;
287  ThreadData *td = arg;
288  uint8_t *dst = td->dst;
289  int dst_linesize = td->dst_linesize;
290  uint8_t *src = td->src;
291  int src_linesize = td->src_linesize;
292  int w = td->w;
293  int h = td->h;
294  int hsub = td->hsub;
295  int vsub = td->vsub;
296  int start = ff_slice_pos(h, job, nb_jobs);
297  int end = ff_slice_pos(h, job + 1, nb_jobs);
298  const int linesize = s->linesize[0];
299  int x, y;
300 
301  for (y = start; y < end; y++) {
302  int sy = y << vsub;
303  for (x = 0; x < w; x++) {
304  int u, v, subU, subV, sum, sx;
305 
306  sx = x << hsub;
307  u = s->pv[sx + sy * linesize][0] >> hsub;
308  v = s->pv[sx + sy * linesize][1] >> vsub;
309  subU = u & (SUB_PIXELS - 1);
310  subV = v & (SUB_PIXELS - 1);
311  u >>= SUB_PIXEL_BITS;
312  v >>= SUB_PIXEL_BITS;
313 
314  if (u > 0 && v > 0 && u < w - 2 && v < h - 2){
315  const int index = u + v*src_linesize;
316  const int a = s->coeff[subU][0];
317  const int b = s->coeff[subU][1];
318  const int c = s->coeff[subU][2];
319  const int d = s->coeff[subU][3];
320 
321  sum = s->coeff[subV][0] * (a * src[index - 1 - src_linesize] + b * src[index - 0 - src_linesize] +
322  c * src[index + 1 - src_linesize] + d * src[index + 2 - src_linesize]) +
323  s->coeff[subV][1] * (a * src[index - 1 ] + b * src[index - 0 ] +
324  c * src[index + 1 ] + d * src[index + 2 ]) +
325  s->coeff[subV][2] * (a * src[index - 1 + src_linesize] + b * src[index - 0 + src_linesize] +
326  c * src[index + 1 + src_linesize] + d * src[index + 2 + src_linesize]) +
327  s->coeff[subV][3] * (a * src[index - 1 + 2 * src_linesize] + b * src[index - 0 + 2 * src_linesize] +
328  c * src[index + 1 + 2 * src_linesize] + d * src[index + 2 + 2 * src_linesize]);
329  } else {
330  int dx, dy;
331 
332  sum = 0;
333 
334  for (dy = 0; dy < 4; dy++) {
335  int iy = v + dy - 1;
336 
337  if (iy < 0)
338  iy = 0;
339  else if (iy >= h)
340  iy = h-1;
341  for (dx = 0; dx < 4; dx++) {
342  int ix = u + dx - 1;
343 
344  if (ix < 0)
345  ix = 0;
346  else if (ix >= w)
347  ix = w - 1;
348 
349  sum += s->coeff[subU][dx] * s->coeff[subV][dy] * src[ ix + iy * src_linesize];
350  }
351  }
352  }
353 
354  sum = (sum + (1<<(COEFF_BITS * 2 - 1))) >> (COEFF_BITS * 2);
355  sum = av_clip_uint8(sum);
356  dst[x + y * dst_linesize] = sum;
357  }
358  }
359  return 0;
360 }
361 
363  int job, int nb_jobs)
364 {
365  PerspectiveContext *s = ctx->priv;
366  ThreadData *td = arg;
367  uint8_t *dst = td->dst;
368  int dst_linesize = td->dst_linesize;
369  uint8_t *src = td->src;
370  int src_linesize = td->src_linesize;
371  int w = td->w;
372  int h = td->h;
373  int hsub = td->hsub;
374  int vsub = td->vsub;
375  int start = ff_slice_pos(h, job, nb_jobs);
376  int end = ff_slice_pos(h, job + 1, nb_jobs);
377  const int linesize = s->linesize[0];
378  int x, y;
379 
380  for (y = start; y < end; y++){
381  int sy = y << vsub;
382  for (x = 0; x < w; x++){
383  int u, v, subU, subV, sum, sx, index, subUI, subVI;
384 
385  sx = x << hsub;
386  u = s->pv[sx + sy * linesize][0] >> hsub;
387  v = s->pv[sx + sy * linesize][1] >> vsub;
388  subU = u & (SUB_PIXELS - 1);
389  subV = v & (SUB_PIXELS - 1);
390  u >>= SUB_PIXEL_BITS;
391  v >>= SUB_PIXEL_BITS;
392 
393  index = u + v * src_linesize;
394  subUI = SUB_PIXELS - subU;
395  subVI = SUB_PIXELS - subV;
396 
397  if ((unsigned)u < (unsigned)(w - 1)){
398  if((unsigned)v < (unsigned)(h - 1)){
399  sum = subVI * (subUI * src[index] + subU * src[index + 1]) +
400  subV * (subUI * src[index + src_linesize] + subU * src[index + src_linesize + 1]);
401  sum = (sum + (1 << (SUB_PIXEL_BITS * 2 - 1)))>> (SUB_PIXEL_BITS * 2);
402  } else {
403  if (v < 0)
404  v = 0;
405  else
406  v = h - 1;
407  index = u + v * src_linesize;
408  sum = subUI * src[index] + subU * src[index + 1];
409  sum = (sum + (1 << (SUB_PIXEL_BITS - 1))) >> SUB_PIXEL_BITS;
410  }
411  } else {
412  if (u < 0)
413  u = 0;
414  else
415  u = w - 1;
416  if ((unsigned)v < (unsigned)(h - 1)){
417  index = u + v * src_linesize;
418  sum = subVI * src[index] + subV * src[index + src_linesize];
419  sum = (sum + (1 << (SUB_PIXEL_BITS - 1))) >> SUB_PIXEL_BITS;
420  } else {
421  if (v < 0)
422  v = 0;
423  else
424  v = h - 1;
425  index = u + v * src_linesize;
426  sum = src[index];
427  }
428  }
429 
430  sum = av_clip_uint8(sum);
431  dst[x + y * dst_linesize] = sum;
432  }
433  }
434  return 0;
435 }
436 
438 {
439  PerspectiveContext *s = ctx->priv;
440 
441  switch (s->interpolation) {
442  case LINEAR: s->perspective = resample_linear; break;
443  case CUBIC: s->perspective = resample_cubic; break;
444  }
445 
446  return 0;
447 }
448 
449 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
450 {
451  AVFilterContext *ctx = inlink->dst;
452  AVFilterLink *outlink = ctx->outputs[0];
453  PerspectiveContext *s = ctx->priv;
454  AVFrame *out;
455  int plane;
456  int ret;
457 
458  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
459  if (!out) {
461  return AVERROR(ENOMEM);
462  }
464 
465  if (s->eval_mode == EVAL_MODE_FRAME) {
466  if ((ret = calc_persp_luts(ctx, inlink)) < 0) {
467  av_frame_free(&out);
468  return ret;
469  }
470  }
471 
472  for (plane = 0; plane < s->nb_planes; plane++) {
473  int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
474  int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
475  ThreadData td = {.dst = out->data[plane],
476  .dst_linesize = out->linesize[plane],
477  .src = frame->data[plane],
478  .src_linesize = frame->linesize[plane],
479  .w = s->linesize[plane],
480  .h = s->height[plane],
481  .hsub = hsub,
482  .vsub = vsub };
483  ctx->internal->execute(ctx, s->perspective, &td, NULL, FFMIN(td.h, ff_filter_get_nb_threads(ctx)));
484  }
485 
487  return ff_filter_frame(outlink, out);
488 }
489 
491 {
492  PerspectiveContext *s = ctx->priv;
493 
494  av_freep(&s->pv);
495 }
496 
497 static const AVFilterPad perspective_inputs[] = {
498  {
499  .name = "default",
500  .type = AVMEDIA_TYPE_VIDEO,
501  .filter_frame = filter_frame,
502  .config_props = config_input,
503  },
504  { NULL }
505 };
506 
508  {
509  .name = "default",
510  .type = AVMEDIA_TYPE_VIDEO,
511  },
512  { NULL }
513 };
514 
516  .name = "perspective",
517  .description = NULL_IF_CONFIG_SMALL("Correct the perspective of video."),
518  .priv_size = sizeof(PerspectiveContext),
519  .init = init,
520  .uninit = uninit,
524  .priv_class = &perspective_class,
526 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
Definition: af_adeclick.c:365
EvalMode
Definition: af_volume.h:39
#define A(x)
Definition: vp56_arith.h:28
#define av_cold
Definition: attributes.h:88
uint8_t
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#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:1099
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 u(width, name, range_min, range_max)
Definition: cbs_h2645.c:274
#define s(width, name)
Definition: cbs_vp9.c:257
#define FFMIN(a, b)
Definition: common.h:105
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define av_clip_uint8
Definition: common.h:128
#define NULL
Definition: coverity.c:32
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
static AVFrame * frame
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:791
simple arithmetic expression evaluator
int
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_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:126
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#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:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
@ 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
int index
Definition: gxfenc.c:89
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
uint8_t w
Definition: llviddspenc.c:39
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
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 t0
Definition: regdef.h:28
#define t1
Definition: regdef.h:29
#define t3
Definition: regdef.h:31
#define t2
Definition: regdef.h:30
#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
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
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
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
char * expr_str[4][2]
int(* perspective)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
double ref[4][2]
int32_t(* pv)[2]
int32_t coeff[SUB_PIXELS][4]
Used for passing data between threads.
Definition: dsddec.c:67
uint8_t * src
uint8_t * dst
int src_linesize
Definition: vf_bm3d.c:57
#define lrint
Definition: tablegen.h:53
#define av_realloc_f(p, o, n)
#define av_freep(p)
#define src
Definition: vp8dsp.c:255
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
const char * b
Definition: vf_curves.c:119
else temp
Definition: vf_mcdeint.c:259
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:76
static const double coeff[2][5]
Definition: vf_owdenoise.c:73
static int resample_cubic(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static const AVFilterPad perspective_inputs[]
AVFilter ff_vf_perspective
static int calc_persp_luts(AVFilterContext *ctx, AVFilterLink *inlink)
static int query_formats(AVFilterContext *ctx)
#define COEFF_BITS
static int config_input(AVFilterLink *inlink)
#define SUB_PIXELS
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define FLAGS
static double get_coeff(double d)
static const AVFilterPad perspective_outputs[]
#define CUBIC
static int resample_linear(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
@ EVAL_MODE_NB
@ EVAL_MODE_FRAME
@ EVAL_MODE_INIT
static const AVOption perspective_options[]
@ VAR_H
@ VAR_W
@ VAR_VARS_NB
@ VAR_ON
@ VAR_IN
#define SUB_PIXEL_BITS
static const char *const var_names[]
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
#define LINEAR
#define OFFSET(x)
PERSPECTIVESense
@ PERSPECTIVE_SENSE_DESTINATION
coordinates give locations in destination of corners of source.
@ PERSPECTIVE_SENSE_SOURCE
coordinates give locations in source of corners of destination.
AVFILTER_DEFINE_CLASS(perspective)
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
static double c[64]