FFmpeg  4.4.4
vf_rotate.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Stefano Sabatini
3  * Copyright (c) 2008 Vitor Sessak
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 Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along 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 /**
23  * @file
24  * rotation filter, partially based on the tests/rotozoom.c program
25 */
26 
27 #include "libavutil/avstring.h"
28 #include "libavutil/eval.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/parseutils.h"
32 #include "libavutil/pixdesc.h"
33 
34 #include "avfilter.h"
35 #include "drawutils.h"
36 #include "internal.h"
37 #include "video.h"
38 
39 #include <float.h>
40 
41 static const char * const var_names[] = {
42  "in_w" , "iw", ///< width of the input video
43  "in_h" , "ih", ///< height of the input video
44  "out_w", "ow", ///< width of the input video
45  "out_h", "oh", ///< height of the input video
46  "hsub", "vsub",
47  "n", ///< number of frame
48  "t", ///< timestamp expressed in seconds
49  NULL
50 };
51 
52 enum var_name {
61 };
62 
63 typedef struct RotContext {
64  const AVClass *class;
65  double angle;
66  char *angle_expr_str; ///< expression for the angle
67  AVExpr *angle_expr; ///< parsed expression for the angle
69  int outh, outw;
70  uint8_t fillcolor[4]; ///< color expressed either in YUVA or RGBA colorspace for the padding area
73  int hsub, vsub;
74  int nb_planes;
76  float sinx, cosx;
80  uint8_t *(*interpolate_bilinear)(uint8_t *dst_color,
81  const uint8_t *src, int src_linesize, int src_linestep,
82  int x, int y, int max_x, int max_y);
83 } RotContext;
84 
85 typedef struct ThreadData {
86  AVFrame *in, *out;
87  int inw, inh;
88  int outw, outh;
89  int plane;
90  int xi, yi;
91  int xprime, yprime;
92  int c, s;
93 } ThreadData;
94 
95 #define OFFSET(x) offsetof(RotContext, x)
96 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
97 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
98 
99 static const AVOption rotate_options[] = {
100  { "angle", "set angle (in radians)", OFFSET(angle_expr_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, .flags=TFLAGS },
101  { "a", "set angle (in radians)", OFFSET(angle_expr_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, .flags=TFLAGS },
102  { "out_w", "set output width expression", OFFSET(outw_expr_str), AV_OPT_TYPE_STRING, {.str="iw"}, 0, 0, .flags=FLAGS },
103  { "ow", "set output width expression", OFFSET(outw_expr_str), AV_OPT_TYPE_STRING, {.str="iw"}, 0, 0, .flags=FLAGS },
104  { "out_h", "set output height expression", OFFSET(outh_expr_str), AV_OPT_TYPE_STRING, {.str="ih"}, 0, 0, .flags=FLAGS },
105  { "oh", "set output height expression", OFFSET(outh_expr_str), AV_OPT_TYPE_STRING, {.str="ih"}, 0, 0, .flags=FLAGS },
106  { "fillcolor", "set background fill color", OFFSET(fillcolor_str), AV_OPT_TYPE_STRING, {.str="black"}, 0, 0, .flags=FLAGS },
107  { "c", "set background fill color", OFFSET(fillcolor_str), AV_OPT_TYPE_STRING, {.str="black"}, 0, 0, .flags=FLAGS },
108  { "bilinear", "use bilinear interpolation", OFFSET(use_bilinear), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, .flags=FLAGS },
109  { NULL }
110 };
111 
113 
115 {
116  RotContext *rot = ctx->priv;
117 
118  if (!strcmp(rot->fillcolor_str, "none"))
119  rot->fillcolor_enable = 0;
120  else if (av_parse_color(rot->fillcolor, rot->fillcolor_str, -1, ctx) >= 0)
121  rot->fillcolor_enable = 1;
122  else
123  return AVERROR(EINVAL);
124  return 0;
125 }
126 
128 {
129  RotContext *rot = ctx->priv;
130 
131  av_expr_free(rot->angle_expr);
132  rot->angle_expr = NULL;
133 }
134 
136 {
137  static const enum AVPixelFormat pix_fmts[] = {
158  };
159 
161  if (!fmts_list)
162  return AVERROR(ENOMEM);
163  return ff_set_common_formats(ctx, fmts_list);
164 }
165 
166 static double get_rotated_w(void *opaque, double angle)
167 {
168  RotContext *rot = opaque;
169  double inw = rot->var_values[VAR_IN_W];
170  double inh = rot->var_values[VAR_IN_H];
171  float sinx = sin(angle);
172  float cosx = cos(angle);
173 
174  return FFMAX(0, inh * sinx) + FFMAX(0, -inw * cosx) +
175  FFMAX(0, inw * cosx) + FFMAX(0, -inh * sinx);
176 }
177 
178 static double get_rotated_h(void *opaque, double angle)
179 {
180  RotContext *rot = opaque;
181  double inw = rot->var_values[VAR_IN_W];
182  double inh = rot->var_values[VAR_IN_H];
183  float sinx = sin(angle);
184  float cosx = cos(angle);
185 
186  return FFMAX(0, -inh * cosx) + FFMAX(0, -inw * sinx) +
187  FFMAX(0, inh * cosx) + FFMAX(0, inw * sinx);
188 }
189 
190 static double (* const func1[])(void *, double) = {
193  NULL
194 };
195 
196 static const char * const func1_names[] = {
197  "rotw",
198  "roth",
199  NULL
200 };
201 
202 #define FIXP (1<<16)
203 #define FIXP2 (1<<20)
204 #define INT_PI 3294199 //(M_PI * FIXP2)
205 
206 /**
207  * Compute the sin of a using integer values.
208  * Input is scaled by FIXP2 and output values are scaled by FIXP.
209  */
210 static int64_t int_sin(int64_t a)
211 {
212  int64_t a2, res = 0;
213  int i;
214  if (a < 0) a = INT_PI-a; // 0..inf
215  a %= 2 * INT_PI; // 0..2PI
216 
217  if (a >= INT_PI*3/2) a -= 2*INT_PI; // -PI/2 .. 3PI/2
218  if (a >= INT_PI/2 ) a = INT_PI - a; // -PI/2 .. PI/2
219 
220  /* compute sin using Taylor series approximated to the fifth term */
221  a2 = (a*a)/(FIXP2);
222  for (i = 2; i < 11; i += 2) {
223  res += a;
224  a = -a*a2 / (FIXP2*i*(i+1));
225  }
226  return (res + 8)>>4;
227 }
228 
229 /**
230  * Interpolate the color in src at position x and y using bilinear
231  * interpolation.
232  */
234  const uint8_t *src, int src_linesize, int src_linestep,
235  int x, int y, int max_x, int max_y)
236 {
237  int int_x = av_clip(x>>16, 0, max_x);
238  int int_y = av_clip(y>>16, 0, max_y);
239  int frac_x = x&0xFFFF;
240  int frac_y = y&0xFFFF;
241  int i;
242  int int_x1 = FFMIN(int_x+1, max_x);
243  int int_y1 = FFMIN(int_y+1, max_y);
244 
245  for (i = 0; i < src_linestep; i++) {
246  int s00 = src[src_linestep * int_x + i + src_linesize * int_y ];
247  int s01 = src[src_linestep * int_x1 + i + src_linesize * int_y ];
248  int s10 = src[src_linestep * int_x + i + src_linesize * int_y1];
249  int s11 = src[src_linestep * int_x1 + i + src_linesize * int_y1];
250  int s0 = (((1<<16) - frac_x)*s00 + frac_x*s01);
251  int s1 = (((1<<16) - frac_x)*s10 + frac_x*s11);
252 
253  dst_color[i] = ((int64_t)((1<<16) - frac_y)*s0 + (int64_t)frac_y*s1) >> 32;
254  }
255 
256  return dst_color;
257 }
258 
259 /**
260  * Interpolate the color in src at position x and y using bilinear
261  * interpolation.
262  */
264  const uint8_t *src, int src_linesize, int src_linestep,
265  int x, int y, int max_x, int max_y)
266 {
267  int int_x = av_clip(x>>16, 0, max_x);
268  int int_y = av_clip(y>>16, 0, max_y);
269  int frac_x = x&0xFFFF;
270  int frac_y = y&0xFFFF;
271  int i;
272  int int_x1 = FFMIN(int_x+1, max_x);
273  int int_y1 = FFMIN(int_y+1, max_y);
274 
275  for (i = 0; i < src_linestep; i+=2) {
276  int s00 = AV_RL16(&src[src_linestep * int_x + i + src_linesize * int_y ]);
277  int s01 = AV_RL16(&src[src_linestep * int_x1 + i + src_linesize * int_y ]);
278  int s10 = AV_RL16(&src[src_linestep * int_x + i + src_linesize * int_y1]);
279  int s11 = AV_RL16(&src[src_linestep * int_x1 + i + src_linesize * int_y1]);
280  int s0 = (((1<<16) - frac_x)*s00 + frac_x*s01);
281  int s1 = (((1<<16) - frac_x)*s10 + frac_x*s11);
282 
283  AV_WL16(&dst_color[i], ((int64_t)((1<<16) - frac_y)*s0 + (int64_t)frac_y*s1) >> 32);
284  }
285 
286  return dst_color;
287 }
288 
289 static int config_props(AVFilterLink *outlink)
290 {
291  AVFilterContext *ctx = outlink->src;
292  RotContext *rot = ctx->priv;
293  AVFilterLink *inlink = ctx->inputs[0];
294  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format);
295  int ret;
296  double res;
297  char *expr;
298 
299  ff_draw_init(&rot->draw, inlink->format, 0);
300  ff_draw_color(&rot->draw, &rot->color, rot->fillcolor);
301 
302  rot->hsub = pixdesc->log2_chroma_w;
303  rot->vsub = pixdesc->log2_chroma_h;
304 
305  if (pixdesc->comp[0].depth == 8)
307  else
309 
310  rot->var_values[VAR_IN_W] = rot->var_values[VAR_IW] = inlink->w;
311  rot->var_values[VAR_IN_H] = rot->var_values[VAR_IH] = inlink->h;
312  rot->var_values[VAR_HSUB] = 1<<rot->hsub;
313  rot->var_values[VAR_VSUB] = 1<<rot->vsub;
314  rot->var_values[VAR_N] = NAN;
315  rot->var_values[VAR_T] = NAN;
316  rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = NAN;
317  rot->var_values[VAR_OUT_H] = rot->var_values[VAR_OH] = NAN;
318 
319  av_expr_free(rot->angle_expr);
320  rot->angle_expr = NULL;
321  if ((ret = av_expr_parse(&rot->angle_expr, expr = rot->angle_expr_str, var_names,
322  func1_names, func1, NULL, NULL, 0, ctx)) < 0) {
324  "Error occurred parsing angle expression '%s'\n", rot->angle_expr_str);
325  return ret;
326  }
327 
328 #define SET_SIZE_EXPR(name, opt_name) do { \
329  ret = av_expr_parse_and_eval(&res, expr = rot->name##_expr_str, \
330  var_names, rot->var_values, \
331  func1_names, func1, NULL, NULL, rot, 0, ctx); \
332  if (ret < 0 || isnan(res) || isinf(res) || res <= 0) { \
333  av_log(ctx, AV_LOG_ERROR, \
334  "Error parsing or evaluating expression for option %s: " \
335  "invalid expression '%s' or non-positive or indefinite value %f\n", \
336  opt_name, expr, res); \
337  return ret; \
338  } \
339 } while (0)
340 
341  /* evaluate width and height */
342  av_expr_parse_and_eval(&res, expr = rot->outw_expr_str, var_names, rot->var_values,
343  func1_names, func1, NULL, NULL, rot, 0, ctx);
344  rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = res;
345  rot->outw = res + 0.5;
346  SET_SIZE_EXPR(outh, "out_h");
347  rot->var_values[VAR_OUT_H] = rot->var_values[VAR_OH] = res;
348  rot->outh = res + 0.5;
349 
350  /* evaluate the width again, as it may depend on the evaluated output height */
351  SET_SIZE_EXPR(outw, "out_w");
352  rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = res;
353  rot->outw = res + 0.5;
354 
355  /* compute number of planes */
356  rot->nb_planes = av_pix_fmt_count_planes(inlink->format);
357  outlink->w = rot->outw;
358  outlink->h = rot->outh;
359  return 0;
360 }
361 
362 static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
363 {
364  int v;
365  switch (elem_size) {
366  case 1:
367  *pout = *pin;
368  break;
369  case 2:
370  *((uint16_t *)pout) = *((uint16_t *)pin);
371  break;
372  case 3:
373  v = AV_RB24(pin);
374  AV_WB24(pout, v);
375  break;
376  case 4:
377  *((uint32_t *)pout) = *((uint32_t *)pin);
378  break;
379  default:
380  memcpy(pout, pin, elem_size);
381  break;
382  }
383 }
384 
385 static av_always_inline void simple_rotate_internal(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
386 {
387  int i;
388  switch(angle) {
389  case 0:
390  memcpy(dst, src, elem_size * len);
391  break;
392  case 1:
393  for (i = 0; i<len; i++)
394  copy_elem(dst + i*elem_size, src + (len-i-1)*src_linesize, elem_size);
395  break;
396  case 2:
397  for (i = 0; i<len; i++)
398  copy_elem(dst + i*elem_size, src + (len-i-1)*elem_size, elem_size);
399  break;
400  case 3:
401  for (i = 0; i<len; i++)
402  copy_elem(dst + i*elem_size, src + i*src_linesize, elem_size);
403  break;
404  }
405 }
406 
407 static av_always_inline void simple_rotate(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
408 {
409  switch(elem_size) {
410  case 1 : simple_rotate_internal(dst, src, src_linesize, angle, 1, len); break;
411  case 2 : simple_rotate_internal(dst, src, src_linesize, angle, 2, len); break;
412  case 3 : simple_rotate_internal(dst, src, src_linesize, angle, 3, len); break;
413  case 4 : simple_rotate_internal(dst, src, src_linesize, angle, 4, len); break;
414  default: simple_rotate_internal(dst, src, src_linesize, angle, elem_size, len); break;
415  }
416 }
417 
418 static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
419 {
420  ThreadData *td = arg;
421  AVFrame *in = td->in;
422  AVFrame *out = td->out;
423  RotContext *rot = ctx->priv;
424  const int outw = td->outw, outh = td->outh;
425  const int inw = td->inw, inh = td->inh;
426  const int plane = td->plane;
427  const int xi = td->xi, yi = td->yi;
428  const int c = td->c, s = td->s;
429  const int start = (outh * job ) / nb_jobs;
430  const int end = (outh * (job+1)) / nb_jobs;
431  int xprime = td->xprime + start * s;
432  int yprime = td->yprime + start * c;
433  int i, j, x, y;
434 
435  for (j = start; j < end; j++) {
436  x = xprime + xi + FIXP*(inw-1)/2;
437  y = yprime + yi + FIXP*(inh-1)/2;
438 
439  if (fabs(rot->angle - 0) < FLT_EPSILON && outw == inw && outh == inh) {
440  simple_rotate(out->data[plane] + j * out->linesize[plane],
441  in->data[plane] + j * in->linesize[plane],
442  in->linesize[plane], 0, rot->draw.pixelstep[plane], outw);
443  } else if (fabs(rot->angle - M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
444  simple_rotate(out->data[plane] + j * out->linesize[plane],
445  in->data[plane] + j * rot->draw.pixelstep[plane],
446  in->linesize[plane], 1, rot->draw.pixelstep[plane], outw);
447  } else if (fabs(rot->angle - M_PI) < FLT_EPSILON && outw == inw && outh == inh) {
448  simple_rotate(out->data[plane] + j * out->linesize[plane],
449  in->data[plane] + (outh-j-1) * in->linesize[plane],
450  in->linesize[plane], 2, rot->draw.pixelstep[plane], outw);
451  } else if (fabs(rot->angle - 3*M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
452  simple_rotate(out->data[plane] + j * out->linesize[plane],
453  in->data[plane] + (outh-j-1) * rot->draw.pixelstep[plane],
454  in->linesize[plane], 3, rot->draw.pixelstep[plane], outw);
455  } else {
456 
457  for (i = 0; i < outw; i++) {
458  int32_t v;
459  int x1, y1;
460  uint8_t *pin, *pout;
461  x1 = x>>16;
462  y1 = y>>16;
463 
464  /* the out-of-range values avoid border artifacts */
465  if (x1 >= -1 && x1 <= inw && y1 >= -1 && y1 <= inh) {
466  uint8_t inp_inv[4]; /* interpolated input value */
467  pout = out->data[plane] + j * out->linesize[plane] + i * rot->draw.pixelstep[plane];
468  if (rot->use_bilinear) {
469  pin = rot->interpolate_bilinear(inp_inv,
470  in->data[plane], in->linesize[plane], rot->draw.pixelstep[plane],
471  x, y, inw-1, inh-1);
472  } else {
473  int x2 = av_clip(x1, 0, inw-1);
474  int y2 = av_clip(y1, 0, inh-1);
475  pin = in->data[plane] + y2 * in->linesize[plane] + x2 * rot->draw.pixelstep[plane];
476  }
477  switch (rot->draw.pixelstep[plane]) {
478  case 1:
479  *pout = *pin;
480  break;
481  case 2:
482  v = AV_RL16(pin);
483  AV_WL16(pout, v);
484  break;
485  case 3:
486  v = AV_RB24(pin);
487  AV_WB24(pout, v);
488  break;
489  case 4:
490  *((uint32_t *)pout) = *((uint32_t *)pin);
491  break;
492  default:
493  memcpy(pout, pin, rot->draw.pixelstep[plane]);
494  break;
495  }
496  }
497  x += c;
498  y -= s;
499  }
500  }
501  xprime += s;
502  yprime += c;
503  }
504 
505  return 0;
506 }
507 
508 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
509 {
510  AVFilterContext *ctx = inlink->dst;
511  AVFilterLink *outlink = ctx->outputs[0];
512  AVFrame *out;
513  RotContext *rot = ctx->priv;
514  int angle_int, s, c, plane;
515  double res;
516 
517  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
518  if (!out) {
519  av_frame_free(&in);
520  return AVERROR(ENOMEM);
521  }
523 
524  rot->var_values[VAR_N] = inlink->frame_count_out;
525  rot->var_values[VAR_T] = TS2T(in->pts, inlink->time_base);
526  rot->angle = res = av_expr_eval(rot->angle_expr, rot->var_values, rot);
527 
528  av_log(ctx, AV_LOG_DEBUG, "n:%f time:%f angle:%f/PI\n",
529  rot->var_values[VAR_N], rot->var_values[VAR_T], rot->angle/M_PI);
530 
531  angle_int = res * FIXP * 16;
532  s = int_sin(angle_int);
533  c = int_sin(angle_int + INT_PI/2);
534 
535  /* fill background */
536  if (rot->fillcolor_enable)
537  ff_fill_rectangle(&rot->draw, &rot->color, out->data, out->linesize,
538  0, 0, outlink->w, outlink->h);
539 
540  for (plane = 0; plane < rot->nb_planes; plane++) {
541  int hsub = plane == 1 || plane == 2 ? rot->hsub : 0;
542  int vsub = plane == 1 || plane == 2 ? rot->vsub : 0;
543  const int outw = AV_CEIL_RSHIFT(outlink->w, hsub);
544  const int outh = AV_CEIL_RSHIFT(outlink->h, vsub);
545  ThreadData td = { .in = in, .out = out,
546  .inw = AV_CEIL_RSHIFT(inlink->w, hsub),
547  .inh = AV_CEIL_RSHIFT(inlink->h, vsub),
548  .outh = outh, .outw = outw,
549  .xi = -(outw-1) * c / 2, .yi = (outw-1) * s / 2,
550  .xprime = -(outh-1) * s / 2,
551  .yprime = -(outh-1) * c / 2,
552  .plane = plane, .c = c, .s = s };
553 
554 
556  }
557 
558  av_frame_free(&in);
559  return ff_filter_frame(outlink, out);
560 }
561 
562 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
563  char *res, int res_len, int flags)
564 {
565  RotContext *rot = ctx->priv;
566  int ret;
567 
568  if (!strcmp(cmd, "angle") || !strcmp(cmd, "a")) {
569  AVExpr *old = rot->angle_expr;
570  ret = av_expr_parse(&rot->angle_expr, args, var_names,
571  NULL, NULL, NULL, NULL, 0, ctx);
572  if (ret < 0) {
574  "Error when parsing the expression '%s' for angle command\n", args);
575  rot->angle_expr = old;
576  return ret;
577  }
578  av_expr_free(old);
579  } else
580  ret = AVERROR(ENOSYS);
581 
582  return ret;
583 }
584 
585 static const AVFilterPad rotate_inputs[] = {
586  {
587  .name = "default",
588  .type = AVMEDIA_TYPE_VIDEO,
589  .filter_frame = filter_frame,
590  },
591  { NULL }
592 };
593 
594 static const AVFilterPad rotate_outputs[] = {
595  {
596  .name = "default",
597  .type = AVMEDIA_TYPE_VIDEO,
598  .config_props = config_props,
599  },
600  { NULL }
601 };
602 
604  .name = "rotate",
605  .description = NULL_IF_CONFIG_SMALL("Rotate the input image."),
606  .priv_size = sizeof(RotContext),
607  .init = init,
608  .uninit = uninit,
613  .priv_class = &rotate_class,
615 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define av_always_inline
Definition: attributes.h:45
#define av_cold
Definition: attributes.h:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
int32_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
Main libavfilter public API header.
#define AV_RB24
Definition: intreadwrite.h:64
#define AV_RL16
Definition: intreadwrite.h:42
#define flags(name, subs,...)
Definition: cbs_av1.c:561
#define xi(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:404
#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
Definition: common.h:122
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:84
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:137
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
Definition: drawutils.c:224
misc drawing utilities
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:766
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:776
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
simple arithmetic expression evaluator
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_BOOL
Definition: opt.h:242
@ 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
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int i
Definition: input.c:407
#define AV_WB24(p, d)
Definition: intreadwrite.h:450
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
const char * arg
Definition: jacosubdec.c:66
#define TS2T(ts, tb)
Definition: internal.h:209
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
#define NAN
Definition: mathematics.h:64
#define M_PI
Definition: mathematics.h:52
AVOptions.
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:354
misc parsing utilities
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_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
@ 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_YUVA444P9LE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:183
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
@ AV_PIX_FMT_YUVA444P10LE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:189
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
@ AV_PIX_FMT_YUV420P9LE
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:157
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_YUVA420P10LE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:185
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
@ 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_YUV420P10LE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:159
@ 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_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
@ AV_PIX_FMT_YUVA420P9LE
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian
Definition: pixfmt.h:179
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
@ 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_YUV444P9LE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:163
@ 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_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
@ AV_PIX_FMT_YUVA444P16LE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:195
@ AV_PIX_FMT_YUVA420P16LE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:191
@ AV_PIX_FMT_YUV420P12LE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:243
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
@ AV_PIX_FMT_YUV444P16LE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:135
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
@ 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_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:165
@ 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
@ AV_PIX_FMT_YUV420P16LE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:131
@ AV_PIX_FMT_YUV444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:251
#define s1
Definition: regdef.h:38
#define s0
Definition: regdef.h:37
#define a2
Definition: regdef.h:48
#define td
Definition: regdef.h:70
var_name
Definition: setts_bsf.c:50
Describe the class of an AVClass context structure.
Definition: log.h:67
int depth
Number of bits in the component.
Definition: pixdesc.h:58
Definition: eval.c:157
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
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
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
int pixelstep[MAX_PLANES]
Definition: drawutils.h:39
double var_values[VAR_VARS_NB]
Definition: vf_rotate.c:77
int nb_planes
Definition: vf_rotate.c:74
char * fillcolor_str
Definition: vf_rotate.c:71
char * angle_expr_str
expression for the angle
Definition: vf_rotate.c:66
int outw
Definition: vf_rotate.c:69
char * outw_expr_str
Definition: vf_rotate.c:68
float sinx
Definition: vf_rotate.c:76
char * outh_expr_str
Definition: vf_rotate.c:68
uint8_t *(* interpolate_bilinear)(uint8_t *dst_color, const uint8_t *src, int src_linesize, int src_linestep, int x, int y, int max_x, int max_y)
Definition: vf_rotate.c:80
int vsub
Definition: vf_rotate.c:73
FFDrawContext draw
Definition: vf_rotate.c:78
float cosx
Definition: vf_rotate.c:76
int outh
Definition: vf_rotate.c:69
uint8_t fillcolor[4]
color expressed either in YUVA or RGBA colorspace for the padding area
Definition: vf_rotate.c:70
int use_bilinear
Definition: vf_rotate.c:75
int fillcolor_enable
Definition: vf_rotate.c:72
double angle
Definition: vf_rotate.c:65
FFDrawColor color
Definition: vf_rotate.c:79
int hsub
Definition: vf_rotate.c:73
AVExpr * angle_expr
parsed expression for the angle
Definition: vf_rotate.c:67
Used for passing data between threads.
Definition: dsddec.c:67
int yprime
Definition: vf_rotate.c:91
const void ** s
AVFrame * out
Definition: af_adeclick.c:502
int outh
Definition: vf_rotate.c:88
int xprime
Definition: vf_rotate.c:91
AVFrame * in
Definition: af_adenorm.c:223
int plane
Definition: vf_blend.c:58
int outw
Definition: vf_rotate.c:88
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:75
@ VAR_VSUB
Definition: vf_rotate.c:57
@ VAR_OUT_H
Definition: vf_rotate.c:56
@ VAR_OH
Definition: vf_rotate.c:56
@ VAR_IN_W
Definition: vf_rotate.c:53
@ VAR_IW
Definition: vf_rotate.c:53
@ VAR_OW
Definition: vf_rotate.c:55
@ VAR_N
Definition: vf_rotate.c:58
@ VAR_IH
Definition: vf_rotate.c:54
@ VAR_VARS_NB
Definition: vf_rotate.c:60
@ VAR_OUT_W
Definition: vf_rotate.c:55
@ VAR_HSUB
Definition: vf_rotate.c:57
@ VAR_IN_H
Definition: vf_rotate.c:54
@ VAR_T
Definition: vf_rotate.c:59
#define SET_SIZE_EXPR(name, opt_name)
static int config_props(AVFilterLink *outlink)
Definition: vf_rotate.c:289
static const AVFilterPad rotate_inputs[]
Definition: vf_rotate.c:585
static double get_rotated_w(void *opaque, double angle)
Definition: vf_rotate.c:166
static uint8_t * interpolate_bilinear8(uint8_t *dst_color, const uint8_t *src, int src_linesize, int src_linestep, int x, int y, int max_x, int max_y)
Interpolate the color in src at position x and y using bilinear interpolation.
Definition: vf_rotate.c:233
#define INT_PI
Definition: vf_rotate.c:204
static double get_rotated_h(void *opaque, double angle)
Definition: vf_rotate.c:178
static double(*const func1[])(void *, double)
Definition: vf_rotate.c:190
#define TFLAGS
Definition: vf_rotate.c:97
static int query_formats(AVFilterContext *ctx)
Definition: vf_rotate.c:135
AVFILTER_DEFINE_CLASS(rotate)
static int64_t int_sin(int64_t a)
Compute the sin of a using integer values.
Definition: vf_rotate.c:210
#define FLAGS
Definition: vf_rotate.c:96
#define FIXP
Definition: vf_rotate.c:202
static uint8_t * interpolate_bilinear16(uint8_t *dst_color, const uint8_t *src, int src_linesize, int src_linestep, int x, int y, int max_x, int max_y)
Interpolate the color in src at position x and y using bilinear interpolation.
Definition: vf_rotate.c:263
static const AVFilterPad rotate_outputs[]
Definition: vf_rotate.c:594
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_rotate.c:508
AVFilter ff_vf_rotate
Definition: vf_rotate.c:603
static av_always_inline void simple_rotate(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
Definition: vf_rotate.c:407
static av_always_inline void simple_rotate_internal(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
Definition: vf_rotate.c:385
static const char *const var_names[]
Definition: vf_rotate.c:41
static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
Definition: vf_rotate.c:362
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_rotate.c:562
static const AVOption rotate_options[]
Definition: vf_rotate.c:99
static av_cold int init(AVFilterContext *ctx)
Definition: vf_rotate.c:114
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_rotate.c:127
static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vf_rotate.c:418
static const char *const func1_names[]
Definition: vf_rotate.c:196
#define FIXP2
Definition: vf_rotate.c:203
#define OFFSET(x)
Definition: vf_rotate.c:95
static void rotate(const float rot_quaternion[2][4], float *vec)
Rotate vector with given rotation quaternion.
Definition: vf_v360.c:3919
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
int len
static double c[64]