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