FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 {
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
68  char *outw_expr_str, *outh_expr_str;
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;
77  double var_values[VAR_VARS_NB];
80 } RotContext;
81 
82 typedef struct ThreadData {
83  AVFrame *in, *out;
84  int inw, inh;
85  int outw, outh;
86  int plane;
87  int xi, yi;
88  int xprime, yprime;
89  int c, s;
90 } ThreadData;
91 
92 #define OFFSET(x) offsetof(RotContext, x)
93 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
94 
95 static const AVOption rotate_options[] = {
96  { "angle", "set angle (in radians)", OFFSET(angle_expr_str), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
97  { "a", "set angle (in radians)", OFFSET(angle_expr_str), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
98  { "out_w", "set output width expression", OFFSET(outw_expr_str), AV_OPT_TYPE_STRING, {.str="iw"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
99  { "ow", "set output width expression", OFFSET(outw_expr_str), AV_OPT_TYPE_STRING, {.str="iw"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
100  { "out_h", "set output height expression", OFFSET(outh_expr_str), AV_OPT_TYPE_STRING, {.str="ih"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
101  { "oh", "set output height expression", OFFSET(outh_expr_str), AV_OPT_TYPE_STRING, {.str="ih"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
102  { "fillcolor", "set background fill color", OFFSET(fillcolor_str), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
103  { "c", "set background fill color", OFFSET(fillcolor_str), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX, .flags=FLAGS },
104  { "bilinear", "use bilinear interpolation", OFFSET(use_bilinear), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, .flags=FLAGS },
105  { NULL }
106 };
107 
108 AVFILTER_DEFINE_CLASS(rotate);
109 
111 {
112  RotContext *rot = ctx->priv;
113 
114  if (!strcmp(rot->fillcolor_str, "none"))
115  rot->fillcolor_enable = 0;
116  else if (av_parse_color(rot->fillcolor, rot->fillcolor_str, -1, ctx) >= 0)
117  rot->fillcolor_enable = 1;
118  else
119  return AVERROR(EINVAL);
120  return 0;
121 }
122 
124 {
125  RotContext *rot = ctx->priv;
126 
127  av_expr_free(rot->angle_expr);
128  rot->angle_expr = NULL;
129 }
130 
132 {
133  static const enum AVPixelFormat pix_fmts[] = {
146  };
147 
148  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
149  if (!fmts_list)
150  return AVERROR(ENOMEM);
151  return ff_set_common_formats(ctx, fmts_list);
152 }
153 
154 static double get_rotated_w(void *opaque, double angle)
155 {
156  RotContext *rot = opaque;
157  double inw = rot->var_values[VAR_IN_W];
158  double inh = rot->var_values[VAR_IN_H];
159  float sinx = sin(angle);
160  float cosx = cos(angle);
161 
162  return FFMAX(0, inh * sinx) + FFMAX(0, -inw * cosx) +
163  FFMAX(0, inw * cosx) + FFMAX(0, -inh * sinx);
164 }
165 
166 static double get_rotated_h(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 * cosx) + FFMAX(0, -inw * sinx) +
175  FFMAX(0, inh * cosx) + FFMAX(0, inw * sinx);
176 }
177 
178 static double (* const func1[])(void *, double) = {
181  NULL
182 };
183 
184 static const char * const func1_names[] = {
185  "rotw",
186  "roth",
187  NULL
188 };
189 
190 static int config_props(AVFilterLink *outlink)
191 {
192  AVFilterContext *ctx = outlink->src;
193  RotContext *rot = ctx->priv;
194  AVFilterLink *inlink = ctx->inputs[0];
195  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format);
196  int ret;
197  double res;
198  char *expr;
199 
200  ff_draw_init(&rot->draw, inlink->format, 0);
201  ff_draw_color(&rot->draw, &rot->color, rot->fillcolor);
202 
203  rot->hsub = pixdesc->log2_chroma_w;
204  rot->vsub = pixdesc->log2_chroma_h;
205 
206  rot->var_values[VAR_IN_W] = rot->var_values[VAR_IW] = inlink->w;
207  rot->var_values[VAR_IN_H] = rot->var_values[VAR_IH] = inlink->h;
208  rot->var_values[VAR_HSUB] = 1<<rot->hsub;
209  rot->var_values[VAR_VSUB] = 1<<rot->vsub;
210  rot->var_values[VAR_N] = NAN;
211  rot->var_values[VAR_T] = NAN;
212  rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = NAN;
213  rot->var_values[VAR_OUT_H] = rot->var_values[VAR_OH] = NAN;
214 
215  av_expr_free(rot->angle_expr);
216  rot->angle_expr = NULL;
217  if ((ret = av_expr_parse(&rot->angle_expr, expr = rot->angle_expr_str, var_names,
218  func1_names, func1, NULL, NULL, 0, ctx)) < 0) {
219  av_log(ctx, AV_LOG_ERROR,
220  "Error occurred parsing angle expression '%s'\n", rot->angle_expr_str);
221  return ret;
222  }
223 
224 #define SET_SIZE_EXPR(name, opt_name) do { \
225  ret = av_expr_parse_and_eval(&res, expr = rot->name##_expr_str, \
226  var_names, rot->var_values, \
227  func1_names, func1, NULL, NULL, rot, 0, ctx); \
228  if (ret < 0 || isnan(res) || isinf(res) || res <= 0) { \
229  av_log(ctx, AV_LOG_ERROR, \
230  "Error parsing or evaluating expression for option %s: " \
231  "invalid expression '%s' or non-positive or indefinite value %f\n", \
232  opt_name, expr, res); \
233  return ret; \
234  } \
235 } while (0)
236 
237  /* evaluate width and height */
238  av_expr_parse_and_eval(&res, expr = rot->outw_expr_str, var_names, rot->var_values,
239  func1_names, func1, NULL, NULL, rot, 0, ctx);
240  rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = res;
241  rot->outw = res + 0.5;
242  SET_SIZE_EXPR(outh, "out_h");
243  rot->var_values[VAR_OUT_H] = rot->var_values[VAR_OH] = res;
244  rot->outh = res + 0.5;
245 
246  /* evaluate the width again, as it may depend on the evaluated output height */
247  SET_SIZE_EXPR(outw, "out_w");
248  rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = res;
249  rot->outw = res + 0.5;
250 
251  /* compute number of planes */
252  rot->nb_planes = av_pix_fmt_count_planes(inlink->format);
253  outlink->w = rot->outw;
254  outlink->h = rot->outh;
255  return 0;
256 }
257 
258 #define FIXP (1<<16)
259 #define FIXP2 (1<<20)
260 #define INT_PI 3294199 //(M_PI * FIXP2)
261 
262 /**
263  * Compute the sin of a using integer values.
264  * Input is scaled by FIXP2 and output values are scaled by FIXP.
265  */
266 static int64_t int_sin(int64_t a)
267 {
268  int64_t a2, res = 0;
269  int i;
270  if (a < 0) a = INT_PI-a; // 0..inf
271  a %= 2 * INT_PI; // 0..2PI
272 
273  if (a >= INT_PI*3/2) a -= 2*INT_PI; // -PI/2 .. 3PI/2
274  if (a >= INT_PI/2 ) a = INT_PI - a; // -PI/2 .. PI/2
275 
276  /* compute sin using Taylor series approximated to the fifth term */
277  a2 = (a*a)/(FIXP2);
278  for (i = 2; i < 11; i += 2) {
279  res += a;
280  a = -a*a2 / (FIXP2*i*(i+1));
281  }
282  return (res + 8)>>4;
283 }
284 
285 /**
286  * Interpolate the color in src at position x and y using bilinear
287  * interpolation.
288  */
290  const uint8_t *src, int src_linesize, int src_linestep,
291  int x, int y, int max_x, int max_y)
292 {
293  int int_x = av_clip(x>>16, 0, max_x);
294  int int_y = av_clip(y>>16, 0, max_y);
295  int frac_x = x&0xFFFF;
296  int frac_y = y&0xFFFF;
297  int i;
298  int int_x1 = FFMIN(int_x+1, max_x);
299  int int_y1 = FFMIN(int_y+1, max_y);
300 
301  for (i = 0; i < src_linestep; i++) {
302  int s00 = src[src_linestep * int_x + i + src_linesize * int_y ];
303  int s01 = src[src_linestep * int_x1 + i + src_linesize * int_y ];
304  int s10 = src[src_linestep * int_x + i + src_linesize * int_y1];
305  int s11 = src[src_linestep * int_x1 + i + src_linesize * int_y1];
306  int s0 = (((1<<16) - frac_x)*s00 + frac_x*s01);
307  int s1 = (((1<<16) - frac_x)*s10 + frac_x*s11);
308 
309  dst_color[i] = ((int64_t)((1<<16) - frac_y)*s0 + (int64_t)frac_y*s1) >> 32;
310  }
311 
312  return dst_color;
313 }
314 
315 static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
316 {
317  int v;
318  switch (elem_size) {
319  case 1:
320  *pout = *pin;
321  break;
322  case 2:
323  *((uint16_t *)pout) = *((uint16_t *)pin);
324  break;
325  case 3:
326  v = AV_RB24(pin);
327  AV_WB24(pout, v);
328  break;
329  case 4:
330  *((uint32_t *)pout) = *((uint32_t *)pin);
331  break;
332  default:
333  memcpy(pout, pin, elem_size);
334  break;
335  }
336 }
337 
338 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)
339 {
340  int i;
341  switch(angle) {
342  case 0:
343  memcpy(dst, src, elem_size * len);
344  break;
345  case 1:
346  for (i = 0; i<len; i++)
347  copy_elem(dst + i*elem_size, src + (len-i-1)*src_linesize, elem_size);
348  break;
349  case 2:
350  for (i = 0; i<len; i++)
351  copy_elem(dst + i*elem_size, src + (len-i-1)*elem_size, elem_size);
352  break;
353  case 3:
354  for (i = 0; i<len; i++)
355  copy_elem(dst + i*elem_size, src + i*src_linesize, elem_size);
356  break;
357  }
358 }
359 
360 static av_always_inline void simple_rotate(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
361 {
362  switch(elem_size) {
363  case 1 : simple_rotate_internal(dst, src, src_linesize, angle, 1, len); break;
364  case 2 : simple_rotate_internal(dst, src, src_linesize, angle, 2, len); break;
365  case 3 : simple_rotate_internal(dst, src, src_linesize, angle, 3, len); break;
366  case 4 : simple_rotate_internal(dst, src, src_linesize, angle, 4, len); break;
367  default: simple_rotate_internal(dst, src, src_linesize, angle, elem_size, len); break;
368  }
369 }
370 
371 #define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb))
372 
373 static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
374 {
375  ThreadData *td = arg;
376  AVFrame *in = td->in;
377  AVFrame *out = td->out;
378  RotContext *rot = ctx->priv;
379  const int outw = td->outw, outh = td->outh;
380  const int inw = td->inw, inh = td->inh;
381  const int plane = td->plane;
382  const int xi = td->xi, yi = td->yi;
383  const int c = td->c, s = td->s;
384  const int start = (outh * job ) / nb_jobs;
385  const int end = (outh * (job+1)) / nb_jobs;
386  int xprime = td->xprime + start * s;
387  int yprime = td->yprime + start * c;
388  int i, j, x, y;
389 
390  for (j = start; j < end; j++) {
391  x = xprime + xi + FIXP*(inw-1)/2;
392  y = yprime + yi + FIXP*(inh-1)/2;
393 
394  if (fabs(rot->angle - 0) < FLT_EPSILON && outw == inw && outh == inh) {
395  simple_rotate(out->data[plane] + j * out->linesize[plane],
396  in->data[plane] + j * in->linesize[plane],
397  in->linesize[plane], 0, rot->draw.pixelstep[plane], outw);
398  } else if (fabs(rot->angle - M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
399  simple_rotate(out->data[plane] + j * out->linesize[plane],
400  in->data[plane] + j * rot->draw.pixelstep[plane],
401  in->linesize[plane], 1, rot->draw.pixelstep[plane], outw);
402  } else if (fabs(rot->angle - M_PI) < FLT_EPSILON && outw == inw && outh == inh) {
403  simple_rotate(out->data[plane] + j * out->linesize[plane],
404  in->data[plane] + (outh-j-1) * in->linesize[plane],
405  in->linesize[plane], 2, rot->draw.pixelstep[plane], outw);
406  } else if (fabs(rot->angle - 3*M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
407  simple_rotate(out->data[plane] + j * out->linesize[plane],
408  in->data[plane] + (outh-j-1) * rot->draw.pixelstep[plane],
409  in->linesize[plane], 3, rot->draw.pixelstep[plane], outw);
410  } else {
411 
412  for (i = 0; i < outw; i++) {
413  int32_t v;
414  int x1, y1;
415  uint8_t *pin, *pout;
416  x1 = x>>16;
417  y1 = y>>16;
418 
419  /* the out-of-range values avoid border artifacts */
420  if (x1 >= -1 && x1 <= inw && y1 >= -1 && y1 <= inh) {
421  uint8_t inp_inv[4]; /* interpolated input value */
422  pout = out->data[plane] + j * out->linesize[plane] + i * rot->draw.pixelstep[plane];
423  if (rot->use_bilinear) {
424  pin = interpolate_bilinear(inp_inv,
425  in->data[plane], in->linesize[plane], rot->draw.pixelstep[plane],
426  x, y, inw-1, inh-1);
427  } else {
428  int x2 = av_clip(x1, 0, inw-1);
429  int y2 = av_clip(y1, 0, inh-1);
430  pin = in->data[plane] + y2 * in->linesize[plane] + x2 * rot->draw.pixelstep[plane];
431  }
432  switch (rot->draw.pixelstep[plane]) {
433  case 1:
434  *pout = *pin;
435  break;
436  case 2:
437  *((uint16_t *)pout) = *((uint16_t *)pin);
438  break;
439  case 3:
440  v = AV_RB24(pin);
441  AV_WB24(pout, v);
442  break;
443  case 4:
444  *((uint32_t *)pout) = *((uint32_t *)pin);
445  break;
446  default:
447  memcpy(pout, pin, rot->draw.pixelstep[plane]);
448  break;
449  }
450  }
451  x += c;
452  y -= s;
453  }
454  }
455  xprime += s;
456  yprime += c;
457  }
458 
459  return 0;
460 }
461 
462 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
463 {
464  AVFilterContext *ctx = inlink->dst;
465  AVFilterLink *outlink = ctx->outputs[0];
466  AVFrame *out;
467  RotContext *rot = ctx->priv;
468  int angle_int, s, c, plane;
469  double res;
470 
471  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
472  if (!out) {
473  av_frame_free(&in);
474  return AVERROR(ENOMEM);
475  }
476  av_frame_copy_props(out, in);
477 
478  rot->var_values[VAR_N] = inlink->frame_count;
479  rot->var_values[VAR_T] = TS2T(in->pts, inlink->time_base);
480  rot->angle = res = av_expr_eval(rot->angle_expr, rot->var_values, rot);
481 
482  av_log(ctx, AV_LOG_DEBUG, "n:%f time:%f angle:%f/PI\n",
483  rot->var_values[VAR_N], rot->var_values[VAR_T], rot->angle/M_PI);
484 
485  angle_int = res * FIXP * 16;
486  s = int_sin(angle_int);
487  c = int_sin(angle_int + INT_PI/2);
488 
489  /* fill background */
490  if (rot->fillcolor_enable)
491  ff_fill_rectangle(&rot->draw, &rot->color, out->data, out->linesize,
492  0, 0, outlink->w, outlink->h);
493 
494  for (plane = 0; plane < rot->nb_planes; plane++) {
495  int hsub = plane == 1 || plane == 2 ? rot->hsub : 0;
496  int vsub = plane == 1 || plane == 2 ? rot->vsub : 0;
497  const int outw = AV_CEIL_RSHIFT(outlink->w, hsub);
498  const int outh = AV_CEIL_RSHIFT(outlink->h, vsub);
499  ThreadData td = { .in = in, .out = out,
500  .inw = AV_CEIL_RSHIFT(inlink->w, hsub),
501  .inh = AV_CEIL_RSHIFT(inlink->h, vsub),
502  .outh = outh, .outw = outw,
503  .xi = -(outw-1) * c / 2, .yi = (outw-1) * s / 2,
504  .xprime = -(outh-1) * s / 2,
505  .yprime = -(outh-1) * c / 2,
506  .plane = plane, .c = c, .s = s };
507 
508 
509  ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ctx->graph->nb_threads));
510  }
511 
512  av_frame_free(&in);
513  return ff_filter_frame(outlink, out);
514 }
515 
516 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
517  char *res, int res_len, int flags)
518 {
519  RotContext *rot = ctx->priv;
520  int ret;
521 
522  if (!strcmp(cmd, "angle") || !strcmp(cmd, "a")) {
523  AVExpr *old = rot->angle_expr;
524  ret = av_expr_parse(&rot->angle_expr, args, var_names,
525  NULL, NULL, NULL, NULL, 0, ctx);
526  if (ret < 0) {
527  av_log(ctx, AV_LOG_ERROR,
528  "Error when parsing the expression '%s' for angle command\n", args);
529  rot->angle_expr = old;
530  return ret;
531  }
532  av_expr_free(old);
533  } else
534  ret = AVERROR(ENOSYS);
535 
536  return ret;
537 }
538 
539 static const AVFilterPad rotate_inputs[] = {
540  {
541  .name = "default",
542  .type = AVMEDIA_TYPE_VIDEO,
543  .filter_frame = filter_frame,
544  },
545  { NULL }
546 };
547 
548 static const AVFilterPad rotate_outputs[] = {
549  {
550  .name = "default",
551  .type = AVMEDIA_TYPE_VIDEO,
552  .config_props = config_props,
553  },
554  { NULL }
555 };
556 
558  .name = "rotate",
559  .description = NULL_IF_CONFIG_SMALL("Rotate the input image."),
560  .priv_size = sizeof(RotContext),
561  .init = init,
562  .uninit = uninit,
565  .inputs = rotate_inputs,
566  .outputs = rotate_outputs,
567  .priv_class = &rotate_class,
569 };
int fillcolor_enable
Definition: vf_rotate.c:72
int plane
Definition: avisynth_c.h:291
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:360
static av_cold int init(AVFilterContext *ctx)
Definition: vf_rotate.c:110
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
AVFrame * out
Definition: af_sofalizer.c:585
static const char *const func1_names[]
Definition: vf_rotate.c:184
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2193
This structure describes decoded (raw) audio or video data.
Definition: frame.h:180
AVOption.
Definition: opt.h:245
AVFormatContext * ctx
Definition: movenc-test.c:48
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2233
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
int hsub
Definition: vf_rotate.c:73
static const AVOption rotate_options[]
Definition: vf_rotate.c:95
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:252
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:658
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:76
uint8_t fillcolor[4]
color expressed either in YUVA or RGBA colorspace for the padding area
Definition: vf_rotate.c:70
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:338
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
#define TS2T(ts, tb)
Definition: vf_rotate.c:371
static const AVFilterPad rotate_inputs[]
Definition: vf_rotate.c:539
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:322
#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:123
const char * name
Pad name.
Definition: internal.h:59
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:313
char * fillcolor_str
Definition: vf_rotate.c:71
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1180
AVFrame * in
Definition: af_sofalizer.c:585
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
uint8_t
#define av_cold
Definition: attributes.h:82
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:251
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:264
Definition: eval.c:149
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:95
int plane
Definition: vf_blend.c:57
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:804
#define INT_PI
Definition: vf_rotate.c:260
#define av_log(a,...)
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:349
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_rotate.c:123
A filter pad used for either input or output.
Definition: internal.h:53
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:723
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vf_rotate.c:373
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:568
#define td
Definition: regdef.h:70
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static double(*const func1[])(void *, double)
Definition: vf_rotate.c:178
#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:153
#define OFFSET(x)
Definition: vf_rotate.c:92
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:96
void * priv
private data for use by the filter
Definition: avfilter.h:320
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:114
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
#define s0
Definition: regdef.h:37
const char * arg
Definition: jacosubdec.c:66
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:221
int outw
Definition: vf_rotate.c:69
#define FFMAX(a, b)
Definition: common.h:94
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
var_name
Definition: aeval.c:46
static int query_formats(AVFilterContext *ctx)
Definition: vf_rotate.c:131
static 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)
Interpolate the color in src at position x and y using bilinear interpolation.
Definition: vf_rotate.c:289
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
static int config_props(AVFilterLink *outlink)
Definition: vf_rotate.c:190
int32_t
AVFILTER_DEFINE_CLASS(rotate)
#define a2
Definition: regdef.h:48
#define AV_WB24(p, d)
Definition: intreadwrite.h:450
double angle
Definition: vf_rotate.c:65
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
static int64_t int_sin(int64_t a)
Compute the sin of a using integer values.
Definition: vf_rotate.c:266
#define src
Definition: vp9dsp.c:530
AVExpr * angle_expr
parsed expression for the angle
Definition: vf_rotate.c:67
FILE * out
Definition: movenc-test.c:54
static const AVFilterPad rotate_outputs[]
Definition: vf_rotate.c:548
char * angle_expr_str
expression for the angle
Definition: vf_rotate.c:66
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
misc drawing utilities
int vsub
Definition: vf_rotate.c:73
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:87
static double get_rotated_h(void *opaque, double angle)
Definition: vf_rotate.c:166
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:318
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:211
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:188
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
int xprime
Definition: vf_rotate.c:88
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_rotate.c:516
FFDrawContext draw
Definition: vf_rotate.c:78
int yprime
Definition: vf_rotate.c:88
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-> in
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:142
#define SET_SIZE_EXPR(name, opt_name)
int nb_planes
Definition: vf_rotate.c:74
#define FIXP
Definition: vf_rotate.c:258
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:253
const char * name
Filter name.
Definition: avfilter.h:146
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:176
#define s1
Definition: regdef.h:38
float sinx
Definition: vf_rotate.c:76
static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
Definition: vf_rotate.c:315
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:317
int outw
Definition: vf_rotate.c:85
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:345
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:194
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:228
static double c[64]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
AVFilter ff_vf_rotate
Definition: vf_rotate.c:557
avfilter_execute_func * execute
Definition: internal.h:153
#define NAN
Definition: math.h:28
int len
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:713
FFDrawColor color
Definition: vf_rotate.c:79
int pixelstep[MAX_PLANES]
Definition: drawutils.h:52
A list of supported formats for one end of a filter link.
Definition: formats.h:64
static double get_rotated_w(void *opaque, double angle)
Definition: vf_rotate.c:154
int use_bilinear
Definition: vf_rotate.c:75
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:304
An instance of a filter.
Definition: avfilter.h:305
double var_values[VAR_VARS_NB]
Definition: vf_rotate.c:77
static const char *const var_names[]
Definition: vf_rotate.c:41
int outh
Definition: vf_rotate.c:69
void INT64 start
Definition: avisynth_c.h:553
#define av_always_inline
Definition: attributes.h:39
#define FLAGS
Definition: vf_rotate.c:93
#define M_PI
Definition: mathematics.h:46
int outh
Definition: vf_rotate.c:85
char * outw_expr_str
Definition: vf_rotate.c:68
internal API functions
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:250
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_rotate.c:462
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:574
#define FIXP2
Definition: vf_rotate.c:259
simple arithmetic expression evaluator
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58