FFmpeg
vf_drawbox.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Affine Systems, Inc (Michael Sullivan, Bobby Impollonia)
3  * Copyright (c) 2013 Andrey Utkin <andrey.krieger.utkin gmail com>
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  * Box and grid drawing filters. Also a nice template for a filter
25  * that needs to write in the input frame.
26  */
27 
28 #include "libavutil/colorspace.h"
29 #include "libavutil/common.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/eval.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/parseutils.h"
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "internal.h"
37 #include "video.h"
38 
39 static const char *const var_names[] = {
40  "dar",
41  "hsub", "vsub",
42  "in_h", "ih", ///< height of the input video
43  "in_w", "iw", ///< width of the input video
44  "sar",
45  "x",
46  "y",
47  "h", ///< height of the rendered box
48  "w", ///< width of the rendered box
49  "t",
50  "fill",
51  NULL
52 };
53 
54 enum { Y, U, V, A };
55 
56 enum var_name {
69 };
70 
71 typedef struct DrawBoxContext {
72  const AVClass *class;
73  int x, y, w, h;
74  int thickness;
75  char *color_str;
76  unsigned char yuv_color[4];
77  int invert_color; ///< invert luma color
78  int vsub, hsub; ///< chroma subsampling
79  char *x_expr, *y_expr; ///< expression for x and y
80  char *w_expr, *h_expr; ///< expression for width and height
81  char *t_expr; ///< expression for thickness
83  int replace;
85 
86 static const int NUM_EXPR_EVALS = 5;
87 
89 {
90  DrawBoxContext *s = ctx->priv;
91  uint8_t rgba_color[4];
92 
93  if (!strcmp(s->color_str, "invert"))
94  s->invert_color = 1;
95  else if (av_parse_color(rgba_color, s->color_str, -1, ctx) < 0)
96  return AVERROR(EINVAL);
97 
98  if (!s->invert_color) {
99  s->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
100  s->yuv_color[U] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
101  s->yuv_color[V] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
102  s->yuv_color[A] = rgba_color[3];
103  }
104 
105  return 0;
106 }
107 
109 {
110  static const enum AVPixelFormat pix_fmts[] = {
117  };
118  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
119  if (!fmts_list)
120  return AVERROR(ENOMEM);
121  return ff_set_common_formats(ctx, fmts_list);
122 }
123 
125 {
126  AVFilterContext *ctx = inlink->dst;
127  DrawBoxContext *s = ctx->priv;
129  double var_values[VARS_NB], res;
130  char *expr;
131  int ret;
132  int i;
133 
134  s->hsub = desc->log2_chroma_w;
135  s->vsub = desc->log2_chroma_h;
137 
138  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
139  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
140  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? av_q2d(inlink->sample_aspect_ratio) : 1;
141  var_values[VAR_DAR] = (double)inlink->w / inlink->h * var_values[VAR_SAR];
142  var_values[VAR_HSUB] = s->hsub;
143  var_values[VAR_VSUB] = s->vsub;
144  var_values[VAR_X] = NAN;
145  var_values[VAR_Y] = NAN;
146  var_values[VAR_H] = NAN;
147  var_values[VAR_W] = NAN;
148  var_values[VAR_T] = NAN;
149 
150  for (i = 0; i <= NUM_EXPR_EVALS; i++) {
151  /* evaluate expressions, fail on last iteration */
152  var_values[VAR_MAX] = inlink->w;
153  if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),
154  var_names, var_values,
155  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0 && i == NUM_EXPR_EVALS)
156  goto fail;
157  s->x = var_values[VAR_X] = res;
158 
159  var_values[VAR_MAX] = inlink->h;
160  if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),
161  var_names, var_values,
162  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0 && i == NUM_EXPR_EVALS)
163  goto fail;
164  s->y = var_values[VAR_Y] = res;
165 
166  var_values[VAR_MAX] = inlink->w - s->x;
167  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
168  var_names, var_values,
169  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0 && i == NUM_EXPR_EVALS)
170  goto fail;
171  s->w = var_values[VAR_W] = res;
172 
173  var_values[VAR_MAX] = inlink->h - s->y;
174  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
175  var_names, var_values,
176  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0 && i == NUM_EXPR_EVALS)
177  goto fail;
178  s->h = var_values[VAR_H] = res;
179 
180  var_values[VAR_MAX] = INT_MAX;
181  if ((ret = av_expr_parse_and_eval(&res, (expr = s->t_expr),
182  var_names, var_values,
183  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0 && i == NUM_EXPR_EVALS)
184  goto fail;
185  s->thickness = var_values[VAR_T] = res;
186  }
187 
188  /* if w or h are zero, use the input w/h */
189  s->w = (s->w > 0) ? s->w : inlink->w;
190  s->h = (s->h > 0) ? s->h : inlink->h;
191 
192  /* sanity check width and height */
193  if (s->w < 0 || s->h < 0) {
194  av_log(ctx, AV_LOG_ERROR, "Size values less than 0 are not acceptable.\n");
195  return AVERROR(EINVAL);
196  }
197 
198  av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n",
199  s->x, s->y, s->w, s->h,
200  s->yuv_color[Y], s->yuv_color[U], s->yuv_color[V], s->yuv_color[A]);
201 
202  return 0;
203 
204 fail:
205  av_log(ctx, AV_LOG_ERROR,
206  "Error when evaluating the expression '%s'.\n",
207  expr);
208  return ret;
209 }
210 
212 {
213  return (y - s->y < s->thickness) || (s->y + s->h - 1 - y < s->thickness) ||
214  (x - s->x < s->thickness) || (s->x + s->w - 1 - x < s->thickness);
215 }
216 
218 {
219  DrawBoxContext *s = inlink->dst->priv;
220  int plane, x, y, xb = s->x, yb = s->y;
221  unsigned char *row[4];
222 
223  if (s->have_alpha && s->replace) {
224  for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) {
225  row[0] = frame->data[0] + y * frame->linesize[0];
226  row[3] = frame->data[3] + y * frame->linesize[3];
227 
228  for (plane = 1; plane < 3; plane++)
229  row[plane] = frame->data[plane] +
230  frame->linesize[plane] * (y >> s->vsub);
231 
232  if (s->invert_color) {
233  for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++)
234  if (pixel_belongs_to_box(s, x, y))
235  row[0][x] = 0xff - row[0][x];
236  } else {
237  for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) {
238  if (pixel_belongs_to_box(s, x, y)) {
239  row[0][x ] = s->yuv_color[Y];
240  row[1][x >> s->hsub] = s->yuv_color[U];
241  row[2][x >> s->hsub] = s->yuv_color[V];
242  row[3][x ] = s->yuv_color[A];
243  }
244  }
245  }
246  }
247  } else {
248  for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) {
249  row[0] = frame->data[0] + y * frame->linesize[0];
250 
251  for (plane = 1; plane < 3; plane++)
252  row[plane] = frame->data[plane] +
253  frame->linesize[plane] * (y >> s->vsub);
254 
255  if (s->invert_color) {
256  for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++)
257  if (pixel_belongs_to_box(s, x, y))
258  row[0][x] = 0xff - row[0][x];
259  } else {
260  for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) {
261  double alpha = (double)s->yuv_color[A] / 255;
262 
263  if (pixel_belongs_to_box(s, x, y)) {
264  row[0][x ] = (1 - alpha) * row[0][x ] + alpha * s->yuv_color[Y];
265  row[1][x >> s->hsub] = (1 - alpha) * row[1][x >> s->hsub] + alpha * s->yuv_color[U];
266  row[2][x >> s->hsub] = (1 - alpha) * row[2][x >> s->hsub] + alpha * s->yuv_color[V];
267  }
268  }
269  }
270  }
271  }
272 
273  return ff_filter_frame(inlink->dst->outputs[0], frame);
274 }
275 
276 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
277 {
278  AVFilterLink *inlink = ctx->inputs[0];
279  DrawBoxContext *s = ctx->priv;
280  int old_x = s->x;
281  int old_y = s->y;
282  int old_w = s->w;
283  int old_h = s->h;
284  int old_t = s->thickness;
285  int old_r = s->replace;
286  int ret;
287 
288  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
289  if (ret < 0)
290  return ret;
291 
292  ret = init(ctx);
293  if (ret < 0)
294  goto end;
295  ret = config_input(inlink);;
296 end:
297  if (ret < 0) {
298  s->x = old_x;
299  s->y = old_y;
300  s->w = old_w;
301  s->h = old_h;
302  s->thickness = old_t;
303  s->replace = old_r;
304  }
305 
306  return ret;
307 }
308 
309 #define OFFSET(x) offsetof(DrawBoxContext, x)
310 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
311 
312 #if CONFIG_DRAWBOX_FILTER
313 
314 static const AVOption drawbox_options[] = {
315  { "x", "set horizontal position of the left box edge", OFFSET(x_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
316  { "y", "set vertical position of the top box edge", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
317  { "width", "set width of the box", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
318  { "w", "set width of the box", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
319  { "height", "set height of the box", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
320  { "h", "set height of the box", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
321  { "color", "set color of the box", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
322  { "c", "set color of the box", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
323  { "thickness", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, CHAR_MIN, CHAR_MAX, FLAGS },
324  { "t", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, CHAR_MIN, CHAR_MAX, FLAGS },
325  { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS },
326  { NULL }
327 };
328 
329 AVFILTER_DEFINE_CLASS(drawbox);
330 
331 static const AVFilterPad drawbox_inputs[] = {
332  {
333  .name = "default",
334  .type = AVMEDIA_TYPE_VIDEO,
335  .config_props = config_input,
336  .filter_frame = filter_frame,
337  .needs_writable = 1,
338  },
339  { NULL }
340 };
341 
342 static const AVFilterPad drawbox_outputs[] = {
343  {
344  .name = "default",
345  .type = AVMEDIA_TYPE_VIDEO,
346  },
347  { NULL }
348 };
349 
351  .name = "drawbox",
352  .description = NULL_IF_CONFIG_SMALL("Draw a colored box on the input video."),
353  .priv_size = sizeof(DrawBoxContext),
354  .priv_class = &drawbox_class,
355  .init = init,
357  .inputs = drawbox_inputs,
358  .outputs = drawbox_outputs,
361 };
362 #endif /* CONFIG_DRAWBOX_FILTER */
363 
364 #if CONFIG_DRAWGRID_FILTER
365 static av_pure av_always_inline int pixel_belongs_to_grid(DrawBoxContext *drawgrid, int x, int y)
366 {
367  // x is horizontal (width) coord,
368  // y is vertical (height) coord
369  int x_modulo;
370  int y_modulo;
371 
372  // Abstract from the offset
373  x -= drawgrid->x;
374  y -= drawgrid->y;
375 
376  x_modulo = x % drawgrid->w;
377  y_modulo = y % drawgrid->h;
378 
379  // If x or y got negative, fix values to preserve logics
380  if (x_modulo < 0)
381  x_modulo += drawgrid->w;
382  if (y_modulo < 0)
383  y_modulo += drawgrid->h;
384 
385  return x_modulo < drawgrid->thickness // Belongs to vertical line
386  || y_modulo < drawgrid->thickness; // Belongs to horizontal line
387 }
388 
389 static int drawgrid_filter_frame(AVFilterLink *inlink, AVFrame *frame)
390 {
391  DrawBoxContext *drawgrid = inlink->dst->priv;
392  int plane, x, y;
393  uint8_t *row[4];
394 
395  if (drawgrid->have_alpha && drawgrid->replace) {
396  for (y = 0; y < frame->height; y++) {
397  row[0] = frame->data[0] + y * frame->linesize[0];
398  row[3] = frame->data[3] + y * frame->linesize[3];
399 
400  for (plane = 1; plane < 3; plane++)
401  row[plane] = frame->data[plane] +
402  frame->linesize[plane] * (y >> drawgrid->vsub);
403 
404  if (drawgrid->invert_color) {
405  for (x = 0; x < frame->width; x++)
406  if (pixel_belongs_to_grid(drawgrid, x, y))
407  row[0][x] = 0xff - row[0][x];
408  } else {
409  for (x = 0; x < frame->width; x++) {
410  if (pixel_belongs_to_grid(drawgrid, x, y)) {
411  row[0][x ] = drawgrid->yuv_color[Y];
412  row[1][x >> drawgrid->hsub] = drawgrid->yuv_color[U];
413  row[2][x >> drawgrid->hsub] = drawgrid->yuv_color[V];
414  row[3][x ] = drawgrid->yuv_color[A];
415  }
416  }
417  }
418  }
419  } else {
420  for (y = 0; y < frame->height; y++) {
421  row[0] = frame->data[0] + y * frame->linesize[0];
422 
423  for (plane = 1; plane < 3; plane++)
424  row[plane] = frame->data[plane] +
425  frame->linesize[plane] * (y >> drawgrid->vsub);
426 
427  if (drawgrid->invert_color) {
428  for (x = 0; x < frame->width; x++)
429  if (pixel_belongs_to_grid(drawgrid, x, y))
430  row[0][x] = 0xff - row[0][x];
431  } else {
432  for (x = 0; x < frame->width; x++) {
433  double alpha = (double)drawgrid->yuv_color[A] / 255;
434 
435  if (pixel_belongs_to_grid(drawgrid, x, y)) {
436  row[0][x ] = (1 - alpha) * row[0][x ] + alpha * drawgrid->yuv_color[Y];
437  row[1][x >> drawgrid->hsub] = (1 - alpha) * row[1][x >> drawgrid->hsub] + alpha * drawgrid->yuv_color[U];
438  row[2][x >> drawgrid->hsub] = (1 - alpha) * row[2][x >> drawgrid->hsub] + alpha * drawgrid->yuv_color[V];
439  }
440  }
441  }
442  }
443  }
444 
445  return ff_filter_frame(inlink->dst->outputs[0], frame);
446 }
447 
448 static const AVOption drawgrid_options[] = {
449  { "x", "set horizontal offset", OFFSET(x_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
450  { "y", "set vertical offset", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
451  { "width", "set width of grid cell", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
452  { "w", "set width of grid cell", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
453  { "height", "set height of grid cell", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
454  { "h", "set height of grid cell", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str="0" }, CHAR_MIN, CHAR_MAX, FLAGS },
455  { "color", "set color of the grid", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
456  { "c", "set color of the grid", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
457  { "thickness", "set grid line thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX, FLAGS },
458  { "t", "set grid line thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX, FLAGS },
459  { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS },
460  { NULL }
461 };
462 
463 AVFILTER_DEFINE_CLASS(drawgrid);
464 
465 static const AVFilterPad drawgrid_inputs[] = {
466  {
467  .name = "default",
468  .type = AVMEDIA_TYPE_VIDEO,
469  .config_props = config_input,
470  .filter_frame = drawgrid_filter_frame,
471  .needs_writable = 1,
472  },
473  { NULL }
474 };
475 
476 static const AVFilterPad drawgrid_outputs[] = {
477  {
478  .name = "default",
479  .type = AVMEDIA_TYPE_VIDEO,
480  },
481  { NULL }
482 };
483 
485  .name = "drawgrid",
486  .description = NULL_IF_CONFIG_SMALL("Draw a colored grid on the input video."),
487  .priv_size = sizeof(DrawBoxContext),
488  .priv_class = &drawgrid_class,
489  .init = init,
491  .inputs = drawgrid_inputs,
492  .outputs = drawgrid_outputs,
495 };
496 
497 #endif /* CONFIG_DRAWGRID_FILTER */
int plane
Definition: avisynth_c.h:384
#define NULL
Definition: coverity.c:32
AVFilter ff_vf_drawbox
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption.
Definition: opt.h:246
#define av_pure
Definition: attributes.h:70
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:68
AVFilter ff_vf_drawgrid
int num
Numerator.
Definition: rational.h:59
char * color_str
Definition: vf_drawbox.c:75
static const char *const var_names[]
Definition: vf_drawbox.c:39
char * y_expr
expression for x and y
Definition: vf_drawbox.c:79
Definition: vf_drawbox.c:54
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
char * w_expr
Definition: vf_drawbox.c:80
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_drawbox.c:276
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#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:125
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
#define OFFSET(x)
Definition: vf_drawbox.c:309
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1093
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
uint8_t
#define av_cold
Definition: attributes.h:82
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:177
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static int query_formats(AVFilterContext *ctx)
Definition: vf_drawbox.c:108
#define FLAGS
Definition: vf_drawbox.c:310
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
char * x_expr
Definition: vf_drawbox.c:79
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#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:354
int invert_color
invert luma color
Definition: vf_drawbox.c:77
A filter pad used for either input or output.
Definition: internal.h:54
static int config_input(AVFilterLink *inlink)
Definition: vf_drawbox.c:124
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:764
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
int width
Definition: frame.h:353
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:569
Various defines for YUV<->RGB conversion.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options...
Definition: avfilter.c:887
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
Definition: colorspace.h:102
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:122
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
var_name
Definition: aeval.c:46
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
char * t_expr
expression for thickness
Definition: vf_drawbox.c:81
#define NAN
Definition: mathematics.h:64
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AVFormatContext * ctx
Definition: movenc.c:48
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define s(width, name)
Definition: cbs_vp9.c:257
static av_pure av_always_inline int pixel_belongs_to_box(DrawBoxContext *s, int x, int y)
Definition: vf_drawbox.c:211
char * h_expr
expression for width and height
Definition: vf_drawbox.c:80
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
if(ret)
static const int NUM_EXPR_EVALS
Definition: vf_drawbox.c:86
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static const int16_t alpha[]
Definition: ilbcdata.h:55
int hsub
chroma subsampling
Definition: vf_drawbox.c:78
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
const char * name
Filter name.
Definition: avfilter.h:148
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
Definition: vf_drawbox.c:54
#define flags(name, subs,...)
Definition: cbs_av1.c:561
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
common internal and external API header
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
static av_cold int init(AVFilterContext *ctx)
Definition: vf_drawbox.c:88
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:334
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_drawbox.c:217
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
Definition: colorspace.h:106
An instance of a filter.
Definition: avfilter.h:338
int height
Definition: frame.h:353
unsigned char yuv_color[4]
Definition: vf_drawbox.c:76
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
#define av_always_inline
Definition: attributes.h:39
internal API functions
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
#define RGB_TO_Y_CCIR(r, g, b)
Definition: colorspace.h:98
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
for(j=16;j >0;--j)
Definition: vf_drawbox.c:54
Definition: vf_drawbox.c:54
simple arithmetic expression evaluator