FFmpeg  4.4.9
vf_pad.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 vmrsss
3  * Copyright (c) 2009 Stefano Sabatini
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  * video padding filter
25  */
26 
27 #include <float.h> /* DBL_MAX */
28 
29 #include "avfilter.h"
30 #include "filters.h"
31 #include "formats.h"
32 #include "internal.h"
33 #include "video.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/common.h"
36 #include "libavutil/eval.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/colorspace.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/parseutils.h"
41 #include "libavutil/mathematics.h"
42 #include "libavutil/opt.h"
43 
44 #include "drawutils.h"
45 
46 static const char *const var_names[] = {
47  "in_w", "iw",
48  "in_h", "ih",
49  "out_w", "ow",
50  "out_h", "oh",
51  "x",
52  "y",
53  "a",
54  "sar",
55  "dar",
56  "hsub",
57  "vsub",
58  NULL
59 };
60 
61 enum var_name {
73  VARS_NB
74 };
75 
77 {
79 }
80 
81 enum EvalMode {
85 };
86 
87 typedef struct PadContext {
88  const AVClass *class;
89  int w, h; ///< output dimensions, a value of 0 will result in the input size
90  int x, y; ///< offsets of the input area with respect to the padded area
91  int in_w, in_h; ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues
94 
95  char *w_expr; ///< width expression string
96  char *h_expr; ///< height expression string
97  char *x_expr; ///< width expression string
98  char *y_expr; ///< height expression string
99  uint8_t rgba_color[4]; ///< color for the padding area
102 
103  int eval_mode; ///< expression evaluation mode
104 } PadContext;
105 
106 static int config_input(AVFilterLink *inlink)
107 {
108  AVFilterContext *ctx = inlink->dst;
109  PadContext *s = ctx->priv;
110  AVRational adjusted_aspect = s->aspect;
111  int ret;
112  double var_values[VARS_NB], res;
113  char *expr;
114 
115  ret = ff_draw_init(&s->draw, inlink->format, 0);
116  if (ret < 0) {
117  av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
118  return ret;
119  }
120  ff_draw_color(&s->draw, &s->color, s->rgba_color);
121 
122  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
123  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
124  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
125  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
126  var_values[VAR_A] = (double) inlink->w / inlink->h;
127  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
128  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
129  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
130  var_values[VAR_HSUB] = 1 << s->draw.hsub_max;
131  var_values[VAR_VSUB] = 1 << s->draw.vsub_max;
132 
133  /* evaluate width and height */
134  av_expr_parse_and_eval(&res, (expr = s->w_expr),
135  var_names, var_values,
136  NULL, NULL, NULL, NULL, NULL, 0, ctx);
137  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
138  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
139  var_names, var_values,
140  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
141  goto eval_fail;
142  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
143  if (!s->h)
144  var_values[VAR_OUT_H] = var_values[VAR_OH] = s->h = inlink->h;
145 
146  /* evaluate the width again, as it may depend on the evaluated output height */
147  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
148  var_names, var_values,
149  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
150  goto eval_fail;
151  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
152  if (!s->w)
153  var_values[VAR_OUT_W] = var_values[VAR_OW] = s->w = inlink->w;
154 
155  if (adjusted_aspect.num && adjusted_aspect.den) {
156  adjusted_aspect = av_div_q(adjusted_aspect, inlink->sample_aspect_ratio);
157  if (s->h < av_rescale(s->w, adjusted_aspect.den, adjusted_aspect.num)) {
158  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = av_rescale(s->w, adjusted_aspect.den, adjusted_aspect.num);
159  } else {
160  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = av_rescale(s->h, adjusted_aspect.num, adjusted_aspect.den);
161  }
162  }
163 
164  /* evaluate x and y */
165  av_expr_parse_and_eval(&res, (expr = s->x_expr),
166  var_names, var_values,
167  NULL, NULL, NULL, NULL, NULL, 0, ctx);
168  s->x = var_values[VAR_X] = res;
169  if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),
170  var_names, var_values,
171  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
172  goto eval_fail;
173  s->y = var_values[VAR_Y] = res;
174  /* evaluate x again, as it may depend on the evaluated y value */
175  if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),
176  var_names, var_values,
177  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
178  goto eval_fail;
179  s->x = var_values[VAR_X] = res;
180 
181  if (s->x < 0 || (int64_t)s->x + inlink->w > s->w)
182  s->x = var_values[VAR_X] = ((int64_t)s->w - inlink->w) / 2;
183  if (s->y < 0 || (int64_t)s->y + inlink->h > s->h)
184  s->y = var_values[VAR_Y] = ((int64_t)s->h - inlink->h) / 2;
185 
186  s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
187  s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
188  /* sanity check params */
189  if (s->w < inlink->w || s->h < inlink->h) {
190  av_log(ctx, AV_LOG_ERROR, "Padded dimensions cannot be smaller than input dimensions.\n");
191  return AVERROR(EINVAL);
192  }
193 
194  s->x = ff_draw_round_to_sub(&s->draw, 0, -1, s->x);
195  s->y = ff_draw_round_to_sub(&s->draw, 1, -1, s->y);
196  s->in_w = ff_draw_round_to_sub(&s->draw, 0, -1, inlink->w);
197  s->in_h = ff_draw_round_to_sub(&s->draw, 1, -1, inlink->h);
198  s->inlink_w = inlink->w;
199  s->inlink_h = inlink->h;
200 
201  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X\n",
202  inlink->w, inlink->h, s->w, s->h, s->x, s->y,
203  s->rgba_color[0], s->rgba_color[1], s->rgba_color[2], s->rgba_color[3]);
204 
205  if (s->x < 0 || s->y < 0 ||
206  s->w <= 0 || s->h <= 0 ||
207  (unsigned)s->x + (unsigned)inlink->w > s->w ||
208  (unsigned)s->y + (unsigned)inlink->h > s->h) {
210  "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
211  s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);
212  return AVERROR(EINVAL);
213  }
214 
215  return 0;
216 
217 eval_fail:
219  "Error when evaluating the expression '%s'\n", expr);
220  return ret;
221 
222 }
223 
224 static int config_output(AVFilterLink *outlink)
225 {
226  PadContext *s = outlink->src->priv;
227 
228  outlink->w = s->w;
229  outlink->h = s->h;
230  return 0;
231 }
232 
233 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
234 {
235  PadContext *s = inlink->dst->priv;
236  AVFrame *frame;
237  int plane;
238 
239  if (s->inlink_w <= 0)
240  return NULL;
241 
242  frame = ff_get_video_buffer(inlink->dst->outputs[0],
243  w + (s->w - s->in_w),
244  h + (s->h - s->in_h) + (s->x > 0));
245 
246  if (!frame)
247  return NULL;
248 
249  frame->width = w;
250  frame->height = h;
251 
252  for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
253  int hsub = s->draw.hsub[plane];
254  int vsub = s->draw.vsub[plane];
255  frame->data[plane] += (s->x >> hsub) * s->draw.pixelstep[plane] +
256  (s->y >> vsub) * frame->linesize[plane];
257  }
258 
259  return frame;
260 }
261 
262 /* check whether each plane in this buffer can be padded without copying */
264 {
265  int planes[4] = { -1, -1, -1, -1}, *p = planes;
266  int i, j;
267 
268  /* get all planes in this buffer */
269  for (i = 0; i < FF_ARRAY_ELEMS(planes) && frame->data[i]; i++) {
270  if (av_frame_get_plane_buffer(frame, i) == buf)
271  *p++ = i;
272  }
273 
274  /* for each plane in this buffer, check that it can be padded without
275  * going over buffer bounds or other planes */
276  for (i = 0; i < FF_ARRAY_ELEMS(planes) && planes[i] >= 0; i++) {
277  int hsub = s->draw.hsub[planes[i]];
278  int vsub = s->draw.vsub[planes[i]];
279 
280  uint8_t *start = frame->data[planes[i]];
281  uint8_t *end = start + (frame->height >> vsub) *
282  frame->linesize[planes[i]];
283 
284  /* amount of free space needed before the start and after the end
285  * of the plane */
286  ptrdiff_t req_start = (s->x >> hsub) * s->draw.pixelstep[planes[i]] +
287  (s->y >> vsub) * frame->linesize[planes[i]];
288  ptrdiff_t req_end = ((s->w - s->x - frame->width) >> hsub) *
289  s->draw.pixelstep[planes[i]] +
290  ((s->h - s->y - frame->height) >> vsub) * frame->linesize[planes[i]];
291 
292  if (frame->linesize[planes[i]] < (s->w >> hsub) * s->draw.pixelstep[planes[i]])
293  return 1;
294  if (start - buf->data < req_start ||
295  (buf->data + buf->size) - end < req_end)
296  return 1;
297 
298  for (j = 0; j < FF_ARRAY_ELEMS(planes) && planes[j] >= 0; j++) {
299  int vsub1 = s->draw.vsub[planes[j]];
300  uint8_t *start1 = frame->data[planes[j]];
301  uint8_t *end1 = start1 + (frame->height >> vsub1) *
302  frame->linesize[planes[j]];
303  if (i == j)
304  continue;
305 
306  if (FFSIGN(start - end1) != FFSIGN(start - end1 - req_start) ||
307  FFSIGN(end - start1) != FFSIGN(end - start1 + req_end))
308  return 1;
309  }
310  }
311 
312  return 0;
313 }
314 
316 {
317  int i;
318 
320  return 1;
321 
322  for (i = 0; i < 4 && frame->buf[i]; i++)
323  if (buffer_needs_copy(s, frame, frame->buf[i]))
324  return 1;
325  return 0;
326 }
327 
328 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
329 {
330  PadContext *s = inlink->dst->priv;
331  AVFilterLink *outlink = inlink->dst->outputs[0];
332  AVFrame *out;
333  int needs_copy, ret;
334 
335  if (s->eval_mode == EVAL_MODE_INIT &&
336  (ret = ff_inlink_check_frame_params(inlink, in, 0)) < 0) {
337  av_frame_free(&in);
338  return ret;
339  }
340 
341  if(s->eval_mode == EVAL_MODE_FRAME && (
342  in->width != s->inlink_w
343  || in->height != s->inlink_h
344  || in->format != outlink->format
345  || in->sample_aspect_ratio.den != outlink->sample_aspect_ratio.den || in->sample_aspect_ratio.num != outlink->sample_aspect_ratio.num)) {
346  inlink->dst->inputs[0]->format = in->format;
347  inlink->dst->inputs[0]->w = in->width;
348  inlink->dst->inputs[0]->h = in->height;
349 
350  inlink->dst->inputs[0]->sample_aspect_ratio.den = in->sample_aspect_ratio.den;
351  inlink->dst->inputs[0]->sample_aspect_ratio.num = in->sample_aspect_ratio.num;
352 
353 
354  if ((ret = config_input(inlink)) < 0 ||
355  (ret = config_output(outlink)) < 0) {
356  s->inlink_w = -1;
357  av_frame_free(&in);
358  return ret;
359  }
360  }
361 
362  needs_copy = frame_needs_copy(s, in);
363 
364  if (needs_copy) {
365  av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
366  out = ff_get_video_buffer(inlink->dst->outputs[0],
367  FFMAX(inlink->w, s->w),
368  FFMAX(inlink->h, s->h));
369  if (!out) {
370  av_frame_free(&in);
371  return AVERROR(ENOMEM);
372  }
373 
375  } else {
376  int i;
377 
378  out = in;
379  for (i = 0; i < 4 && out->data[i] && out->linesize[i]; i++) {
380  int hsub = s->draw.hsub[i];
381  int vsub = s->draw.vsub[i];
382  out->data[i] -= (s->x >> hsub) * s->draw.pixelstep[i] +
383  (s->y >> vsub) * out->linesize[i];
384  }
385  }
386 
387  /* top bar */
388  if (s->y) {
389  ff_fill_rectangle(&s->draw, &s->color,
390  out->data, out->linesize,
391  0, 0, s->w, s->y);
392  }
393 
394  /* bottom bar */
395  if (s->h > s->y + s->in_h) {
396  ff_fill_rectangle(&s->draw, &s->color,
397  out->data, out->linesize,
398  0, s->y + s->in_h, s->w, s->h - s->y - s->in_h);
399  }
400 
401  /* left border */
402  ff_fill_rectangle(&s->draw, &s->color, out->data, out->linesize,
403  0, s->y, s->x, in->height);
404 
405  if (needs_copy) {
406  ff_copy_rectangle2(&s->draw,
407  out->data, out->linesize, in->data, in->linesize,
408  s->x, s->y, 0, 0, in->width, in->height);
409  }
410 
411  /* right border */
412  ff_fill_rectangle(&s->draw, &s->color, out->data, out->linesize,
413  s->x + s->in_w, s->y, s->w - s->x - s->in_w,
414  in->height);
415 
416  out->width = s->w;
417  out->height = s->h;
418 
419  if (in != out)
420  av_frame_free(&in);
421  return ff_filter_frame(inlink->dst->outputs[0], out);
422 }
423 
424 #define OFFSET(x) offsetof(PadContext, x)
425 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
426 
427 static const AVOption pad_options[] = {
428  { "width", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, 0, 0, FLAGS },
429  { "w", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, 0, 0, FLAGS },
430  { "height", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, 0, 0, FLAGS },
431  { "h", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, 0, 0, FLAGS },
432  { "x", "set the x offset expression for the input image position", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, 0, 0, FLAGS },
433  { "y", "set the y offset expression for the input image position", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, 0, 0, FLAGS },
434  { "color", "set the color of the padded area border", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
435  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
436  { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
437  { "frame", "eval expressions during initialization and per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
438  { "aspect", "pad to fit an aspect instead of a resolution", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, DBL_MAX, FLAGS },
439  { NULL }
440 };
441 
443 
445  {
446  .name = "default",
447  .type = AVMEDIA_TYPE_VIDEO,
448  .config_props = config_input,
449  .get_video_buffer = get_video_buffer,
450  .filter_frame = filter_frame,
451  },
452  { NULL }
453 };
454 
456  {
457  .name = "default",
458  .type = AVMEDIA_TYPE_VIDEO,
459  .config_props = config_output,
460  },
461  { NULL }
462 };
463 
465  .name = "pad",
466  .description = NULL_IF_CONFIG_SMALL("Pad the input video."),
467  .priv_size = sizeof(PadContext),
468  .priv_class = &pad_class,
472  .flags_internal = FF_FILTER_FLAG_DYNAMIC_FRAME_SIZE,
473 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
EvalMode
Definition: af_volume.h:39
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_inlink_check_frame_params(AVFilterLink *link, const AVFrame *frame, int dynamic_flags)
Check that a video frame has the size and pixel format its link was configured with.
Definition: avfilter.c:1538
Main libavfilter public API header.
#define s(width, name)
Definition: cbs_vp9.c:257
common internal and external API header
#define FFMAX(a, b)
Definition: common.h:103
#define FFSIGN(a)
Definition: common.h:73
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static AVFrame * frame
void ff_copy_rectangle2(FFDrawContext *draw, uint8_t *dst[], int dst_linesize[], uint8_t *src[], int src_linesize[], int dst_x, int dst_y, int src_x, int src_y, int w, int h)
Copy a rectangle from an image to another.
Definition: drawutils.c:209
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
Definition: drawutils.c:632
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:84
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:144
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:231
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:644
misc drawing utilities
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:791
simple arithmetic expression evaluator
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:230
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
@ AV_OPT_TYPE_COLOR
Definition: opt.h:240
#define AVERROR(e)
Definition: error.h:43
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:663
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
misc image utilities
int i
Definition: input.c:407
#define FF_FILTER_FLAG_DYNAMIC_FRAME_SIZE
The filter handles input frames whose size differs from the one its input link was configured with.
Definition: internal.h:345
Various defines for YUV<->RGB conversion.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
uint8_t w
Definition: llviddspenc.c:39
static const struct @323 planes[]
#define NAN
Definition: mathematics.h:64
AVOptions.
misc parsing utilities
var_name
Definition: setts_bsf.c:50
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition: buffer.h:84
int size
Size of data in bytes.
Definition: buffer.h:97
uint8_t * data
The data buffer.
Definition: buffer.h:92
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
void * priv
private data for use by the filter
Definition: avfilter.h:356
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:509
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
AVOption.
Definition: opt.h:248
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int num
Numerator.
Definition: rational.h:59
int den
Denominator.
Definition: rational.h:60
int w
Definition: vf_pad.c:89
int inlink_h
Definition: vf_pad.c:92
char * w_expr
width expression string
Definition: vf_pad.c:95
FFDrawColor color
Definition: vf_pad.c:101
int eval_mode
expression evaluation mode
Definition: vf_pad.c:103
uint8_t rgba_color[4]
color for the padding area
Definition: vf_pad.c:99
int in_h
width and height for the padded input video, which has to be aligned to the chroma values in order to...
Definition: vf_pad.c:91
int inlink_w
Definition: vf_pad.c:92
FFDrawContext draw
Definition: vf_pad.c:100
int in_w
Definition: vf_pad.c:91
int x
Definition: vf_pad.c:90
int h
output dimensions, a value of 0 will result in the input size
Definition: vf_pad.c:89
char * h_expr
height expression string
Definition: vf_pad.c:96
char * y_expr
height expression string
Definition: vf_pad.c:98
char * x_expr
width expression string
Definition: vf_pad.c:97
int y
offsets of the input area with respect to the padded area
Definition: vf_pad.c:90
AVRational aspect
Definition: vf_pad.c:93
#define av_log(a,...)
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
if(ret< 0)
Definition: vf_mcdeint.c:282
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:76
AVFilter ff_vf_pad
Definition: vf_pad.c:464
@ VAR_VSUB
Definition: vf_pad.c:72
@ VAR_OUT_H
Definition: vf_pad.c:65
@ VARS_NB
Definition: vf_pad.c:73
@ VAR_SAR
Definition: vf_pad.c:69
@ VAR_OH
Definition: vf_pad.c:65
@ VAR_IN_W
Definition: vf_pad.c:62
@ VAR_IW
Definition: vf_pad.c:62
@ VAR_OW
Definition: vf_pad.c:64
@ VAR_IH
Definition: vf_pad.c:63
@ VAR_A
Definition: vf_pad.c:68
@ VAR_OUT_W
Definition: vf_pad.c:64
@ VAR_HSUB
Definition: vf_pad.c:71
@ VAR_X
Definition: vf_pad.c:66
@ VAR_IN_H
Definition: vf_pad.c:63
@ VAR_DAR
Definition: vf_pad.c:70
@ VAR_Y
Definition: vf_pad.c:67
static const AVFilterPad avfilter_vf_pad_inputs[]
Definition: vf_pad.c:444
static const AVFilterPad avfilter_vf_pad_outputs[]
Definition: vf_pad.c:455
static int query_formats(AVFilterContext *ctx)
Definition: vf_pad.c:76
static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)
Definition: vf_pad.c:263
static const AVOption pad_options[]
Definition: vf_pad.c:427
static int config_input(AVFilterLink *inlink)
Definition: vf_pad.c:106
#define FLAGS
Definition: vf_pad.c:425
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pad.c:328
@ EVAL_MODE_NB
Definition: vf_pad.c:84
@ EVAL_MODE_FRAME
Definition: vf_pad.c:83
@ EVAL_MODE_INIT
Definition: vf_pad.c:82
static const char *const var_names[]
Definition: vf_pad.c:46
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: vf_pad.c:233
AVFILTER_DEFINE_CLASS(pad)
#define OFFSET(x)
Definition: vf_pad.c:424
static int config_output(AVFilterLink *outlink)
Definition: vf_pad.c:224
static int frame_needs_copy(PadContext *s, AVFrame *frame)
Definition: vf_pad.c:315
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104