FFmpeg
Loading...
Searching...
No Matches
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"
32#include "libavutil/pixdesc.h"
33
34#include "avfilter.h"
35#include "drawutils.h"
36#include "filters.h"
37#include "video.h"
38
39#include <float.h>
40
41static 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
62
63typedef 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;
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);
84
85typedef struct ThreadData {
86 AVFrame *in, *out;
87 int inw, inh;
88 int outw, outh;
89 int plane;
90 int xi, yi;
92 int c, s;
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
99static 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
132 rot->angle_expr = NULL;
133}
134
157
158static double get_rotated_w(void *opaque, double angle)
159{
160 RotContext *rot = opaque;
161 double inw = rot->var_values[VAR_IN_W];
162 double inh = rot->var_values[VAR_IN_H];
163 float sinx = sin(angle);
164 float cosx = cos(angle);
165
166 return FFMAX(0, inh * sinx) + FFMAX(0, -inw * cosx) +
167 FFMAX(0, inw * cosx) + FFMAX(0, -inh * sinx);
168}
169
170static double get_rotated_h(void *opaque, double angle)
171{
172 RotContext *rot = opaque;
173 double inw = rot->var_values[VAR_IN_W];
174 double inh = rot->var_values[VAR_IN_H];
175 float sinx = sin(angle);
176 float cosx = cos(angle);
177
178 return FFMAX(0, -inh * cosx) + FFMAX(0, -inw * sinx) +
179 FFMAX(0, inh * cosx) + FFMAX(0, inw * sinx);
180}
181
182static double (* const func1[])(void *, double) = {
185 NULL
186};
187
188static const char * const func1_names[] = {
189 "rotw",
190 "roth",
191 NULL
192};
193
194#define FIXP (1<<16)
195#define FIXP2 (1<<20)
196#define INT_PI 3294199 //(M_PI * FIXP2)
197
198/**
199 * Compute the sin of a using integer values.
200 * Input is scaled by FIXP2 and output values are scaled by FIXP.
201 */
203{
204 int64_t a2, res = 0;
205 int i;
206 if (a < 0) a = INT_PI-a; // 0..inf
207 a %= 2 * INT_PI; // 0..2PI
208
209 if (a >= INT_PI*3/2) a -= 2*INT_PI; // -PI/2 .. 3PI/2
210 if (a >= INT_PI/2 ) a = INT_PI - a; // -PI/2 .. PI/2
211
212 /* compute sin using Taylor series approximated to the fifth term */
213 a2 = (a*a)/(FIXP2);
214 for (i = 2; i < 11; i += 2) {
215 res += a;
216 a = -a*a2 / (FIXP2*i*(i+1));
217 }
218 return (res + 8)>>4;
219}
220
221/**
222 * Interpolate the color in src at position x and y using bilinear
223 * interpolation.
224 */
225static uint8_t *interpolate_bilinear8(uint8_t *dst_color,
226 const uint8_t *src, int src_linesize, int src_linestep,
227 int x, int y, int max_x, int max_y)
228{
229 int int_x = av_clip(x>>16, 0, max_x);
230 int int_y = av_clip(y>>16, 0, max_y);
231 int frac_x = x&0xFFFF;
232 int frac_y = y&0xFFFF;
233 int i;
234 int int_x1 = FFMIN(int_x+1, max_x);
235 int int_y1 = FFMIN(int_y+1, max_y);
236
237 for (i = 0; i < src_linestep; i++) {
238 int s00 = src[src_linestep * int_x + i + src_linesize * int_y ];
239 int s01 = src[src_linestep * int_x1 + i + src_linesize * int_y ];
240 int s10 = src[src_linestep * int_x + i + src_linesize * int_y1];
241 int s11 = src[src_linestep * int_x1 + i + src_linesize * int_y1];
242 int s0 = (((1<<16) - frac_x)*s00 + frac_x*s01);
243 int s1 = (((1<<16) - frac_x)*s10 + frac_x*s11);
244
245 dst_color[i] = ((int64_t)((1<<16) - frac_y)*s0 + (int64_t)frac_y*s1) >> 32;
246 }
247
248 return dst_color;
249}
250
251/**
252 * Interpolate the color in src at position x and y using bilinear
253 * interpolation.
254 */
255static uint8_t *interpolate_bilinear16(uint8_t *dst_color,
256 const uint8_t *src, int src_linesize, int src_linestep,
257 int x, int y, int max_x, int max_y)
258{
259 int int_x = av_clip(x>>16, 0, max_x);
260 int int_y = av_clip(y>>16, 0, max_y);
261 int64_t frac_x = x&0xFFFF;
262 int64_t frac_y = y&0xFFFF;
263 int i;
264 int int_x1 = FFMIN(int_x+1, max_x);
265 int int_y1 = FFMIN(int_y+1, max_y);
266
267 for (i = 0; i < src_linestep; i+=2) {
268 int s00 = AV_RL16(&src[src_linestep * int_x + i + src_linesize * int_y ]);
269 int s01 = AV_RL16(&src[src_linestep * int_x1 + i + src_linesize * int_y ]);
270 int s10 = AV_RL16(&src[src_linestep * int_x + i + src_linesize * int_y1]);
271 int s11 = AV_RL16(&src[src_linestep * int_x1 + i + src_linesize * int_y1]);
272 int64_t s0 = (((1<<16) - frac_x)*s00 + frac_x*s01);
273 int64_t s1 = (((1<<16) - frac_x)*s10 + frac_x*s11);
274
275 AV_WL16(&dst_color[i], (((1<<16) - frac_y)*s0 + frac_y*s1) >> 32);
276 }
277
278 return dst_color;
279}
280
281static int config_props(AVFilterLink *outlink)
282{
283 AVFilterContext *ctx = outlink->src;
284 RotContext *rot = ctx->priv;
285 AVFilterLink *inlink = ctx->inputs[0];
286 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format);
287 int ret;
288 double res;
289 char *expr;
290
291 ret = ff_draw_init_from_link(&rot->draw, inlink, 0);
292 if (ret < 0)
293 return ret;
294 ff_draw_color(&rot->draw, &rot->color, rot->fillcolor);
295
296 rot->hsub = pixdesc->log2_chroma_w;
297 rot->vsub = pixdesc->log2_chroma_h;
298
299 if (pixdesc->comp[0].depth == 8)
301 else
303
304 rot->var_values[VAR_IN_W] = rot->var_values[VAR_IW] = inlink->w;
305 rot->var_values[VAR_IN_H] = rot->var_values[VAR_IH] = inlink->h;
306 rot->var_values[VAR_HSUB] = 1<<rot->hsub;
307 rot->var_values[VAR_VSUB] = 1<<rot->vsub;
308 rot->var_values[VAR_N] = NAN;
309 rot->var_values[VAR_T] = NAN;
310 rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = NAN;
311 rot->var_values[VAR_OUT_H] = rot->var_values[VAR_OH] = NAN;
312
314 rot->angle_expr = NULL;
315 if ((ret = av_expr_parse(&rot->angle_expr, expr = rot->angle_expr_str, var_names,
316 func1_names, func1, NULL, NULL, 0, ctx)) < 0) {
318 "Error occurred parsing angle expression '%s'\n", rot->angle_expr_str);
319 return ret;
320 }
321
322#define SET_SIZE_EXPR(name, opt_name) do { \
323 ret = av_expr_parse_and_eval(&res, expr = rot->name##_expr_str, \
324 var_names, rot->var_values, \
325 func1_names, func1, NULL, NULL, rot, 0, ctx); \
326 if (ret < 0 || isnan(res) || isinf(res) || res <= 0) { \
327 av_log(ctx, AV_LOG_ERROR, \
328 "Error parsing or evaluating expression for option %s: " \
329 "invalid expression '%s' or non-positive or indefinite value %f\n", \
330 opt_name, expr, res); \
331 return ret; \
332 } \
333} while (0)
334
335 /* evaluate width and height */
337 func1_names, func1, NULL, NULL, rot, 0, ctx);
338 rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = res;
339 rot->outw = res + 0.5;
340 SET_SIZE_EXPR(outh, "out_h");
341 rot->var_values[VAR_OUT_H] = rot->var_values[VAR_OH] = res;
342 rot->outh = res + 0.5;
343
344 /* evaluate the width again, as it may depend on the evaluated output height */
345 SET_SIZE_EXPR(outw, "out_w");
346 rot->var_values[VAR_OUT_W] = rot->var_values[VAR_OW] = res;
347 rot->outw = res + 0.5;
348
349 /* compute number of planes */
351 outlink->w = rot->outw;
352 outlink->h = rot->outh;
353 return 0;
354}
355
356static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
357{
358 int v;
359 switch (elem_size) {
360 case 1:
361 *pout = *pin;
362 break;
363 case 2:
364 *((uint16_t *)pout) = *((uint16_t *)pin);
365 break;
366 case 3:
367 v = AV_RB24(pin);
368 AV_WB24(pout, v);
369 break;
370 case 4:
371 *((uint32_t *)pout) = *((uint32_t *)pin);
372 break;
373 default:
374 memcpy(pout, pin, elem_size);
375 break;
376 }
377}
378
379static av_always_inline void simple_rotate_internal(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
380{
381 int i;
382 switch(angle) {
383 case 0:
384 memcpy(dst, src, elem_size * len);
385 break;
386 case 1:
387 for (i = 0; i<len; i++)
388 copy_elem(dst + i*elem_size, src + (len-i-1)*src_linesize, elem_size);
389 break;
390 case 2:
391 for (i = 0; i<len; i++)
392 copy_elem(dst + i*elem_size, src + (len-i-1)*elem_size, elem_size);
393 break;
394 case 3:
395 for (i = 0; i<len; i++)
396 copy_elem(dst + i*elem_size, src + i*src_linesize, elem_size);
397 break;
398 }
399}
400
401static av_always_inline void simple_rotate(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
402{
403 switch(elem_size) {
404 case 1 : simple_rotate_internal(dst, src, src_linesize, angle, 1, len); break;
405 case 2 : simple_rotate_internal(dst, src, src_linesize, angle, 2, len); break;
406 case 3 : simple_rotate_internal(dst, src, src_linesize, angle, 3, len); break;
407 case 4 : simple_rotate_internal(dst, src, src_linesize, angle, 4, len); break;
408 default: simple_rotate_internal(dst, src, src_linesize, angle, elem_size, len); break;
409 }
410}
411
412static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
413{
414 ThreadData *td = arg;
415 AVFrame *in = td->in;
416 AVFrame *out = td->out;
417 RotContext *rot = ctx->priv;
418 const int outw = td->outw, outh = td->outh;
419 const int inw = td->inw, inh = td->inh;
420 const int plane = td->plane;
421 const int xi = td->xi, yi = td->yi;
422 const int c = td->c, s = td->s;
423 const int start = (outh * job ) / nb_jobs;
424 const int end = (outh * (job+1)) / nb_jobs;
425 int xprime = td->xprime + start * s;
426 int yprime = td->yprime + start * c;
427 int i, j, x, y;
428
429 for (j = start; j < end; j++) {
430 x = xprime + xi + FIXP*(inw-1)/2;
431 y = yprime + yi + FIXP*(inh-1)/2;
432
433 if (fabs(rot->angle - 0) < FLT_EPSILON && outw == inw && outh == inh) {
434 simple_rotate(out->data[plane] + j * out->linesize[plane],
435 in->data[plane] + j * in->linesize[plane],
436 in->linesize[plane], 0, rot->draw.pixelstep[plane], outw);
437 } else if (fabs(rot->angle - M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
438 simple_rotate(out->data[plane] + j * out->linesize[plane],
439 in->data[plane] + j * rot->draw.pixelstep[plane],
440 in->linesize[plane], 1, rot->draw.pixelstep[plane], outw);
441 } else if (fabs(rot->angle - M_PI) < FLT_EPSILON && outw == inw && outh == inh) {
442 simple_rotate(out->data[plane] + j * out->linesize[plane],
443 in->data[plane] + (outh-j-1) * in->linesize[plane],
444 in->linesize[plane], 2, rot->draw.pixelstep[plane], outw);
445 } else if (fabs(rot->angle - 3*M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
446 simple_rotate(out->data[plane] + j * out->linesize[plane],
447 in->data[plane] + (outh-j-1) * rot->draw.pixelstep[plane],
448 in->linesize[plane], 3, rot->draw.pixelstep[plane], outw);
449 } else {
450
451 for (i = 0; i < outw; i++) {
452 int32_t v;
453 int x1, y1;
454 uint8_t *pin, *pout;
455 x1 = x>>16;
456 y1 = y>>16;
457
458 /* the out-of-range values avoid border artifacts */
459 if (x1 >= -1 && x1 <= inw && y1 >= -1 && y1 <= inh) {
460 uint8_t inp_inv[4]; /* interpolated input value */
461 pout = out->data[plane] + j * out->linesize[plane] + i * rot->draw.pixelstep[plane];
462 if (rot->use_bilinear) {
463 pin = rot->interpolate_bilinear(inp_inv,
464 in->data[plane], in->linesize[plane], rot->draw.pixelstep[plane],
465 x, y, inw-1, inh-1);
466 } else {
467 int x2 = av_clip(x1, 0, inw-1);
468 int y2 = av_clip(y1, 0, inh-1);
469 pin = in->data[plane] + y2 * in->linesize[plane] + x2 * rot->draw.pixelstep[plane];
470 }
471 switch (rot->draw.pixelstep[plane]) {
472 case 1:
473 *pout = *pin;
474 break;
475 case 2:
476 v = AV_RL16(pin);
477 AV_WL16(pout, v);
478 break;
479 case 3:
480 v = AV_RB24(pin);
481 AV_WB24(pout, v);
482 break;
483 case 4:
484 *((uint32_t *)pout) = *((uint32_t *)pin);
485 break;
486 default:
487 memcpy(pout, pin, rot->draw.pixelstep[plane]);
488 break;
489 }
490 }
491 x += c;
492 y -= s;
493 }
494 }
495 xprime += s;
496 yprime += c;
497 }
498
499 return 0;
500}
501
502static int filter_frame(AVFilterLink *inlink, AVFrame *in)
503{
504 FilterLink *inl = ff_filter_link(inlink);
505 AVFilterContext *ctx = inlink->dst;
506 AVFilterLink *outlink = ctx->outputs[0];
507 AVFrame *out;
508 RotContext *rot = ctx->priv;
509 int angle_int, s, c, plane;
510 double res;
511
512 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
513 if (!out) {
514 av_frame_free(&in);
515 return AVERROR(ENOMEM);
516 }
518
519 rot->var_values[VAR_N] = inl->frame_count_out;
520 rot->var_values[VAR_T] = TS2T(in->pts, inlink->time_base);
521 rot->angle = res = av_expr_eval(rot->angle_expr, rot->var_values, rot);
522
523 av_log(ctx, AV_LOG_DEBUG, "n:%f time:%f angle:%f/PI\n",
524 rot->var_values[VAR_N], rot->var_values[VAR_T], rot->angle/M_PI);
525
526 angle_int = res * FIXP * 16;
527 s = int_sin(angle_int);
528 c = int_sin(angle_int + INT_PI/2);
529
530 /* fill background */
531 if (rot->fillcolor_enable)
532 ff_fill_rectangle(&rot->draw, &rot->color, out->data, out->linesize,
533 0, 0, outlink->w, outlink->h);
534
535 for (plane = 0; plane < rot->nb_planes; plane++) {
536 int hsub = plane == 1 || plane == 2 ? rot->hsub : 0;
537 int vsub = plane == 1 || plane == 2 ? rot->vsub : 0;
538 const int outw = AV_CEIL_RSHIFT(outlink->w, hsub);
539 const int outh = AV_CEIL_RSHIFT(outlink->h, vsub);
540 ThreadData td = { .in = in, .out = out,
541 .inw = AV_CEIL_RSHIFT(inlink->w, hsub),
542 .inh = AV_CEIL_RSHIFT(inlink->h, vsub),
543 .outh = outh, .outw = outw,
544 .xi = -(outw-1) * c / 2, .yi = (outw-1) * s / 2,
545 .xprime = -(outh-1) * s / 2,
546 .yprime = -(outh-1) * c / 2,
547 .plane = plane, .c = c, .s = s };
548
551 }
552
553 av_frame_free(&in);
554 return ff_filter_frame(outlink, out);
555}
556
557static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
558 char *res, int res_len, int flags)
559{
560 RotContext *rot = ctx->priv;
561 int ret;
562
563 if (!strcmp(cmd, "angle") || !strcmp(cmd, "a")) {
564 AVExpr *old = rot->angle_expr;
565 ret = av_expr_parse(&rot->angle_expr, args, var_names,
566 NULL, NULL, NULL, NULL, 0, ctx);
567 if (ret < 0) {
569 "Error when parsing the expression '%s' for angle command\n", args);
570 rot->angle_expr = old;
571 return ret;
572 }
573 av_expr_free(old);
574 } else
575 ret = AVERROR(ENOSYS);
576
577 return ret;
578}
579
580static const AVFilterPad rotate_inputs[] = {
581 {
582 .name = "default",
583 .type = AVMEDIA_TYPE_VIDEO,
584 .filter_frame = filter_frame,
585 },
586};
587
588static const AVFilterPad rotate_outputs[] = {
589 {
590 .name = "default",
591 .type = AVMEDIA_TYPE_VIDEO,
592 .config_props = config_props,
593 },
594};
595
597 .p.name = "rotate",
598 .p.description = NULL_IF_CONFIG_SMALL("Rotate the input image."),
599 .p.priv_class = &rotate_class,
601 .priv_size = sizeof(RotContext),
602 .init = init,
603 .uninit = uninit,
608};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
@ VAR_T
Definition aeval.c:53
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define TFLAGS
Definition af_afade.c:66
const FFFilter ff_vf_rotate
Definition vf_rotate.c:596
int32_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1696
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:846
Main libavfilter public API header.
@ VAR_VSUB
Definition boxblur.c:42
@ VAR_HSUB
Definition boxblur.c:41
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define xi(width, name, var, range_min, range_max, subs,...)
Definition cbs_h264.c:115
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:598
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float fabs(float a)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition drawutils.c:179
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:258
int ff_draw_init_from_link(FFDrawContext *draw, const AVFilterLink *link, unsigned flags)
Init a draw context, taking the format, colorspace and range from the given filter link.
Definition drawutils.c:168
misc drawing utilities
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition eval.c:368
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition eval.c:824
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:839
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:735
simple arithmetic expression evaluator
@ VAR_IW
Definition f_select.c:147
@ VAR_IH
Definition f_select.c:146
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#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:196
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int a
#define AV_WB24(p, d)
#define AV_RL16(p)
#define AV_WL16(p, v)
#define AV_RB24(x)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
const char * arg
Definition jacosubdec.c:65
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:244
#define TS2T(ts, tb)
Definition filters.h:483
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define NAN
#define M_PI
Definition mathematics.h:67
var_name
Definition noise.c:46
@ VAR_N
Definition noise.c:47
@ VAR_VARS_NB
Definition noise.c:59
static const char *const var_names[]
Definition noise.c:30
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:359
misc parsing utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUVA444P9LE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition pixfmt.h:180
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_YUVA444P10LE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition pixfmt.h:186
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_YUV420P9LE
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition pixfmt.h:154
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUVA420P10LE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition pixfmt.h:182
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition pixfmt.h:101
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_YUV420P10LE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition pixfmt.h:156
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition pixfmt.h:264
@ 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:176
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUV444P9LE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition pixfmt.h:160
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ AV_PIX_FMT_YUVA444P16LE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition pixfmt.h:192
@ AV_PIX_FMT_YUVA420P16LE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition pixfmt.h:188
@ AV_PIX_FMT_YUV420P12LE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition pixfmt.h:268
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ AV_PIX_FMT_YUV444P16LE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition pixfmt.h:132
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition pixfmt.h:262
@ 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:87
@ AV_PIX_FMT_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition pixfmt.h:162
@ 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:85
@ AV_PIX_FMT_YUV420P16LE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition pixfmt.h:128
@ AV_PIX_FMT_YUV444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition pixfmt.h:276
@ VAR_OUT_H
Definition scale_eval.c:47
@ VAR_OH
Definition scale_eval.c:47
@ VAR_IN_W
Definition scale_eval.c:44
@ VAR_OW
Definition scale_eval.c:46
@ VAR_OUT_W
Definition scale_eval.c:46
@ VAR_IN_H
Definition scale_eval.c:45
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181
Describe the class of an AVClass context structure.
Definition log.h:76
int depth
Number of bits in the component.
Definition pixdesc.h:57
Definition eval.c:171
An instance of a filter.
Definition avfilter.h:273
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:574
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
int pixelstep[MAX_PLANES]
Definition drawutils.h:40
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
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
FFDrawContext draw
Definition vf_rotate.c:78
float cosx
Definition vf_rotate.c:76
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
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
AVExpr * angle_expr
parsed expression for the angle
Definition vf_rotate.c:67
Used for passing data between threads.
Definition dsddec.c:71
const void ** s
AVFrame * out
int plane
Definition vf_blend.c:61
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void hsub(htype *dst, const htype *src, int bins)
Definition vf_median.c:74
@ VAR_VARS_NB
Definition vf_rotate.c:60
#define SET_SIZE_EXPR(name, opt_name)
static int config_props(AVFilterLink *outlink)
Definition vf_rotate.c:281
static const AVFilterPad rotate_inputs[]
Definition vf_rotate.c:580
static double(*const func1[])(void *, double)
Definition vf_rotate.c:182
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:255
static double get_rotated_w(void *opaque, double angle)
Definition vf_rotate.c:158
#define INT_PI
Definition vf_rotate.c:196
static double get_rotated_h(void *opaque, double angle)
Definition vf_rotate.c:170
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:225
static int64_t int_sin(int64_t a)
Compute the sin of a using integer values.
Definition vf_rotate.c:202
#define FIXP
Definition vf_rotate.c:194
static const AVFilterPad rotate_outputs[]
Definition vf_rotate.c:588
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition vf_rotate.c:502
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:401
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:379
static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
Definition vf_rotate.c:356
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition vf_rotate.c:557
static const AVOption rotate_options[]
Definition vf_rotate.c:99
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:412
static const char *const func1_names[]
Definition vf_rotate.c:188
#define FIXP2
Definition vf_rotate.c:195
#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:4081
static double a2(void *priv, double x, double y)
Definition vf_xfade.c:2030
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89
int len
static double c[64]