Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 #include "libavutil/avstring.h"
32 #include "libavutil/common.h"
33 #include "libavutil/eval.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/colorspace.h"
36 #include "libavutil/avassert.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/parseutils.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/opt.h"
41 
42 #include "drawutils.h"
43 
44 static const char *const var_names[] = {
45  "PI",
46  "PHI",
47  "E",
48  "in_w", "iw",
49  "in_h", "ih",
50  "out_w", "ow",
51  "out_h", "oh",
52  "x",
53  "y",
54  "a",
55  "hsub",
56  "vsub",
57  NULL
58 };
59 
60 enum var_name {
74 };
75 
77 {
78  static const enum AVPixelFormat pix_fmts[] = {
82 
89 
91  };
92 
94  return 0;
95 }
96 
97 typedef struct PadContext {
98  const AVClass *class;
99  int w, h;
100  int x, y;
101  int in_w, in_h;
102 
103  char *w_expr;
104  char *h_expr;
105  char *x_expr;
106  char *y_expr;
107  char *color_str;
108 
111  int line_step[4];
112  int hsub, vsub;
113 } PadContext;
114 
115 static av_cold int init(AVFilterContext *ctx)
116 {
117  PadContext *s = ctx->priv;
118 
119  if (av_parse_color(s->color, s->color_str, -1, ctx) < 0)
120  return AVERROR(EINVAL);
121 
122  return 0;
123 }
124 
125 static av_cold void uninit(AVFilterContext *ctx)
126 {
127  PadContext *s = ctx->priv;
128  int i;
129 
130  for (i = 0; i < 4; i++) {
131  av_freep(&s->line[i]);
132  s->line_step[i] = 0;
133  }
134 }
135 
136 static int config_input(AVFilterLink *inlink)
137 {
138  AVFilterContext *ctx = inlink->dst;
139  PadContext *s = ctx->priv;
140  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
141  uint8_t rgba_color[4];
142  int ret, is_packed_rgba;
143  double var_values[VARS_NB], res;
144  char *expr;
145 
146  s->hsub = pix_desc->log2_chroma_w;
147  s->vsub = pix_desc->log2_chroma_h;
148 
149  var_values[VAR_PI] = M_PI;
150  var_values[VAR_PHI] = M_PHI;
151  var_values[VAR_E] = M_E;
152  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
153  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
154  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
155  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
156  var_values[VAR_A] = (double) inlink->w / inlink->h;
157  var_values[VAR_HSUB] = 1<<s->hsub;
158  var_values[VAR_VSUB] = 1<<s->vsub;
159 
160  /* evaluate width and height */
161  av_expr_parse_and_eval(&res, (expr = s->w_expr),
162  var_names, var_values,
163  NULL, NULL, NULL, NULL, NULL, 0, ctx);
164  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
165  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
166  var_names, var_values,
167  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
168  goto eval_fail;
169  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
170  /* evaluate the width again, as it may depend on the evaluated output height */
171  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
172  var_names, var_values,
173  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
174  goto eval_fail;
175  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
176 
177  /* evaluate x and y */
178  av_expr_parse_and_eval(&res, (expr = s->x_expr),
179  var_names, var_values,
180  NULL, NULL, NULL, NULL, NULL, 0, ctx);
181  s->x = var_values[VAR_X] = res;
182  if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),
183  var_names, var_values,
184  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
185  goto eval_fail;
186  s->y = var_values[VAR_Y] = res;
187  /* evaluate x again, as it may depend on the evaluated y value */
188  if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),
189  var_names, var_values,
190  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
191  goto eval_fail;
192  s->x = var_values[VAR_X] = res;
193 
194  /* sanity check params */
195  if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) {
196  av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n");
197  return AVERROR(EINVAL);
198  }
199 
200  if (!s->w)
201  s->w = inlink->w;
202  if (!s->h)
203  s->h = inlink->h;
204 
205  s->w &= ~((1 << s->hsub) - 1);
206  s->h &= ~((1 << s->vsub) - 1);
207  s->x &= ~((1 << s->hsub) - 1);
208  s->y &= ~((1 << s->vsub) - 1);
209 
210  s->in_w = inlink->w & ~((1 << s->hsub) - 1);
211  s->in_h = inlink->h & ~((1 << s->vsub) - 1);
212 
213  memcpy(rgba_color, s->color, sizeof(rgba_color));
215  inlink->format, rgba_color, &is_packed_rgba, NULL);
216 
217  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n",
218  inlink->w, inlink->h, s->w, s->h, s->x, s->y,
219  s->color[0], s->color[1], s->color[2], s->color[3],
220  is_packed_rgba ? "rgba" : "yuva");
221 
222  if (s->x < 0 || s->y < 0 ||
223  s->w <= 0 || s->h <= 0 ||
224  (unsigned)s->x + (unsigned)inlink->w > s->w ||
225  (unsigned)s->y + (unsigned)inlink->h > s->h) {
226  av_log(ctx, AV_LOG_ERROR,
227  "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
228  s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);
229  return AVERROR(EINVAL);
230  }
231 
232  return 0;
233 
234 eval_fail:
235  av_log(NULL, AV_LOG_ERROR,
236  "Error when evaluating the expression '%s'\n", expr);
237  return ret;
238 
239 }
240 
241 static int config_output(AVFilterLink *outlink)
242 {
243  PadContext *s = outlink->src->priv;
244 
245  outlink->w = s->w;
246  outlink->h = s->h;
247  return 0;
248 }
249 
250 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
251 {
252  PadContext *s = inlink->dst->priv;
253 
254  AVFrame *frame = ff_get_video_buffer(inlink->dst->outputs[0],
255  w + (s->w - s->in_w),
256  h + (s->h - s->in_h));
257  int plane;
258 
259  if (!frame)
260  return NULL;
261 
262  frame->width = w;
263  frame->height = h;
264 
265  for (plane = 0; plane < 4 && frame->data[plane]; plane++) {
266  int hsub = (plane == 1 || plane == 2) ? s->hsub : 0;
267  int vsub = (plane == 1 || plane == 2) ? s->vsub : 0;
268 
269  frame->data[plane] += (s->x >> hsub) * s->line_step[plane] +
270  (s->y >> vsub) * frame->linesize[plane];
271  }
272 
273  return frame;
274 }
275 
276 /* check whether each plane in this buffer can be padded without copying */
277 static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)
278 {
279  int planes[4] = { -1, -1, -1, -1}, *p = planes;
280  int i, j;
281 
282  /* get all planes in this buffer */
283  for (i = 0; i < FF_ARRAY_ELEMS(planes) && frame->data[i]; i++) {
284  if (av_frame_get_plane_buffer(frame, i) == buf)
285  *p++ = i;
286  }
287 
288  /* for each plane in this buffer, check that it can be padded without
289  * going over buffer bounds or other planes */
290  for (i = 0; i < FF_ARRAY_ELEMS(planes) && planes[i] >= 0; i++) {
291  int hsub = (planes[i] == 1 || planes[i] == 2) ? s->hsub : 0;
292  int vsub = (planes[i] == 1 || planes[i] == 2) ? s->vsub : 0;
293 
294  uint8_t *start = frame->data[planes[i]];
295  uint8_t *end = start + (frame->height >> hsub) *
296  frame->linesize[planes[i]];
297 
298  /* amount of free space needed before the start and after the end
299  * of the plane */
300  ptrdiff_t req_start = (s->x >> hsub) * s->line_step[planes[i]] +
301  (s->y >> vsub) * frame->linesize[planes[i]];
302  ptrdiff_t req_end = ((s->w - s->x - frame->width) >> hsub) *
303  s->line_step[planes[i]] +
304  (s->y >> vsub) * frame->linesize[planes[i]];
305 
306  if (frame->linesize[planes[i]] < (s->w >> hsub) * s->line_step[planes[i]])
307  return 1;
308  if (start - buf->data < req_start ||
309  (buf->data + buf->size) - end < req_end)
310  return 1;
311 
312 #define SIGN(x) ((x) > 0 ? 1 : -1)
313  for (j = 0; j < FF_ARRAY_ELEMS(planes) && planes[j] >= 0; j++) {
314  int hsub1 = (planes[j] == 1 || planes[j] == 2) ? s->hsub : 0;
315  uint8_t *start1 = frame->data[planes[j]];
316  uint8_t *end1 = start1 + (frame->height >> hsub1) *
317  frame->linesize[planes[j]];
318  if (i == j)
319  continue;
320 
321  if (SIGN(start - end1) != SIGN(start - end1 - req_start) ||
322  SIGN(end - start1) != SIGN(end - start1 + req_end))
323  return 1;
324  }
325  }
326 
327  return 0;
328 }
329 
330 static int frame_needs_copy(PadContext *s, AVFrame *frame)
331 {
332  int i;
333 
334  if (!av_frame_is_writable(frame))
335  return 1;
336 
337  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++)
338  if (buffer_needs_copy(s, frame, frame->buf[i]))
339  return 1;
340  return 0;
341 }
342 
343 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
344 {
345  PadContext *s = inlink->dst->priv;
346  AVFrame *out;
347  int needs_copy = frame_needs_copy(s, in);
348 
349  if (needs_copy) {
350  av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
351  out = ff_get_video_buffer(inlink->dst->outputs[0],
352  FFMAX(inlink->w, s->w),
353  FFMAX(inlink->h, s->h));
354  if (!out) {
355  av_frame_free(&in);
356  return AVERROR(ENOMEM);
357  }
358 
359  av_frame_copy_props(out, in);
360  } else {
361  int i;
362 
363  out = in;
364  for (i = 0; i < FF_ARRAY_ELEMS(out->data) && out->data[i]; i++) {
365  int hsub = (i == 1 || i == 2) ? s->hsub : 0;
366  int vsub = (i == 1 || i == 2) ? s->vsub : 0;
367  out->data[i] -= (s->x >> hsub) * s->line_step[i] +
368  (s->y >> vsub) * out->linesize[i];
369  }
370  }
371 
372  /* top bar */
373  if (s->y) {
374  ff_draw_rectangle(out->data, out->linesize,
375  s->line, s->line_step, s->hsub, s->vsub,
376  0, 0, s->w, s->y);
377  }
378 
379  /* bottom bar */
380  if (s->h > s->y + s->in_h) {
381  ff_draw_rectangle(out->data, out->linesize,
382  s->line, s->line_step, s->hsub, s->vsub,
383  0, s->y + s->in_h, s->w, s->h - s->y - s->in_h);
384  }
385 
386  /* left border */
387  ff_draw_rectangle(out->data, out->linesize, s->line, s->line_step,
388  s->hsub, s->vsub, 0, s->y, s->x, in->height);
389 
390  if (needs_copy) {
391  ff_copy_rectangle(out->data, out->linesize, in->data, in->linesize,
392  s->line_step, s->hsub, s->vsub,
393  s->x, s->y, 0, in->width, in->height);
394  }
395 
396  /* right border */
397  ff_draw_rectangle(out->data, out->linesize,
398  s->line, s->line_step, s->hsub, s->vsub,
399  s->x + s->in_w, s->y, s->w - s->x - s->in_w,
400  in->height);
401 
402  out->width = s->w;
403  out->height = s->h;
404 
405  if (in != out)
406  av_frame_free(&in);
407  return ff_filter_frame(inlink->dst->outputs[0], out);
408 }
409 
410 #define OFFSET(x) offsetof(PadContext, x)
411 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
412 static const AVOption options[] = {
413  { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
414  { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
415  { "x", "Horizontal position of the left edge of the input video in the "
416  "output video", OFFSET(x_expr), AV_OPT_TYPE_STRING, { .str = "0" }, .flags = FLAGS },
417  { "y", "Vertical position of the top edge of the input video in the "
418  "output video", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str = "0" }, .flags = FLAGS },
419  { "color", "Color of the padded area", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, .flags = FLAGS },
420  { NULL },
421 };
422 
423 static const AVClass pad_class = {
424  .class_name = "pad",
425  .item_name = av_default_item_name,
426  .option = options,
427  .version = LIBAVUTIL_VERSION_INT,
428 };
429 
431  {
432  .name = "default",
433  .type = AVMEDIA_TYPE_VIDEO,
434  .config_props = config_input,
435  .get_video_buffer = get_video_buffer,
436  .filter_frame = filter_frame,
437  },
438  { NULL }
439 };
440 
442  {
443  .name = "default",
444  .type = AVMEDIA_TYPE_VIDEO,
445  .config_props = config_output,
446  },
447  { NULL }
448 };
449 
451  .name = "pad",
452  .description = NULL_IF_CONFIG_SMALL("Pad input image to width:height[:x:y[:color]] (default x and y: 0, default color: black)."),
453 
454  .priv_size = sizeof(PadContext),
455  .priv_class = &pad_class,
456  .init = init,
457  .uninit = uninit,
459 
460  .inputs = avfilter_vf_pad_inputs,
461 
462  .outputs = avfilter_vf_pad_outputs,
463 };
static const AVOption options[]
Definition: vf_pad.c:412
Definition: vf_pad.c:61
int vsub
chroma subsampling values
Definition: vf_pad.c:112
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: vf_pad.c:250
#define FLAGS
Definition: vf_pad.c:411
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
AVOption.
Definition: opt.h:234
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:393
#define SIGN(x)
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:101
int x
Definition: vf_pad.c:100
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_dlog(ac->avr,"%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
Various defines for YUV<->RGB conversion.
char * x_expr
width expression string
Definition: vf_pad.c:105
static const AVFilterPad avfilter_vf_pad_outputs[]
Definition: vf_pad.c:441
#define FF_ARRAY_ELEMS(a)
static int config_output(AVFilterLink *outlink)
Definition: vf_pad.c:241
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
Definition: vf_pad.c:68
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
int w
Definition: vf_pad.c:99
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
const char * name
Pad name.
Definition: internal.h:42
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:728
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:104
uint8_t
#define av_cold
Definition: attributes.h:66
AVOptions.
Definition: vf_pad.c:70
static const char *const var_names[]
Definition: vf_pad.c:44
Definition: vf_pad.c:65
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:97
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:103
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
void 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:379
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:300
A filter pad used for either input or output.
Definition: internal.h:36
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:551
int width
width and height of the video frame
Definition: frame.h:174
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#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:69
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:98
void * priv
private data for use by the filter
Definition: avfilter.h:584
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
static int config_input(AVFilterLink *inlink)
Definition: vf_pad.c:136
Definition: graph2dot.c:49
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:168
#define FFMAX(a, b)
Definition: common.h:55
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:95
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
Definition: vf_pad.c:62
static const AVClass pad_class
Definition: vf_pad.c:423
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
static int frame_needs_copy(PadContext *s, AVFrame *frame)
Definition: vf_pad.c:330
#define M_E
Definition: ratecontrol.c:39
static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)
Definition: vf_pad.c:277
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:414
Definition: vf_pad.c:64
char * w_expr
width expression string
Definition: vf_pad.c:103
int y
offsets of the input area with respect to the padded area
Definition: vf_pad.c:100
int in_w
Definition: vf_pad.c:101
Definition: vf_pad.c:66
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
#define OFFSET(x)
Definition: vf_pad.c:410
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
NULL
Definition: eval.c:55
static av_cold int init(AVFilterContext *ctx)
Definition: vf_pad.c:115
misc drawing utilities
Definition: vf_pad.c:73
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:309
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
av_default_item_name
Definition: dnxhdenc.c:52
static const AVFilterPad avfilter_vf_pad_inputs[]
Definition: vf_pad.c:430
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
uint8_t * data
The data buffer.
Definition: buffer.h:89
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4], uint8_t *src[4], int src_linesize[4], int pixelstep[4], int hsub, int vsub, int x, int y, int y2, int w, int h)
Definition: drawutils.c:102
uint8_t color[4]
color expressed either in YUVA or RGBA colorspace for the padding area
Definition: vf_pad.c:109
#define M_PHI
Definition: mathematics.h:34
Definition: vf_pad.c:69
const char * name
Filter name.
Definition: avfilter.h:425
Definition: vf_pad.c:67
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
int size
Size of data in bytes.
Definition: buffer.h:93
static int query_formats(AVFilterContext *ctx)
Definition: vf_pad.c:76
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
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_dlog(ac->avr,"%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-> out
A reference to a data buffer.
Definition: buffer.h:81
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
common internal and external API header
Definition: vf_pad.c:63
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:79
uint8_t * line[4]
Definition: vf_pad.c:110
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
char * y_expr
height expression string
Definition: vf_pad.c:106
#define NAN
Definition: math.h:28
int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4], enum AVPixelFormat pix_fmt, uint8_t rgba_color[4], int *is_packed_rgba, uint8_t rgba_map_ptr[4])
Definition: drawutils.c:29
AVFilter ff_vf_pad
Definition: vf_pad.c:450
int h
output dimensions, a value of 0 will result in the input size
Definition: vf_pad.c:99
int line_step[4]
Definition: vf_pad.c:111
char * h_expr
height expression string
Definition: vf_pad.c:104
An instance of a filter.
Definition: avfilter.h:563
int height
Definition: frame.h:174
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:102
int hsub
Definition: vf_pad.c:112
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_pad.c:125
internal API functions
void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4], uint8_t *src[4], int pixelstep[4], int hsub, int vsub, int x, int y, int w, int h)
Definition: drawutils.c:82
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pad.c:343
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367
var_name
Definition: setpts.c:58
char * color_str
Definition: vf_pad.c:107
simple arithmetic expression evaluator