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 "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/opt.h"
39 #include "libavutil/parseutils.h"
40 #include "libavutil/mathematics.h"
41 #include "libavutil/opt.h"
42 
43 #include "drawutils.h"
44 
45 static const char *const var_names[] = {
46  "in_w", "iw",
47  "in_h", "ih",
48  "out_w", "ow",
49  "out_h", "oh",
50  "x",
51  "y",
52  "a",
53  "sar",
54  "dar",
55  "hsub",
56  "vsub",
57  NULL
58 };
59 
60 enum var_name {
73 };
74 
76 {
78  return 0;
79 }
80 
81 typedef struct {
82  const AVClass *class;
83  int w, h; ///< output dimensions, a value of 0 will result in the input size
84  int x, y; ///< offsets of the input area with respect to the padded area
85  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
86 
87  char *w_expr; ///< width expression string
88  char *h_expr; ///< height expression string
89  char *x_expr; ///< width expression string
90  char *y_expr; ///< height expression string
91  char *color_str;
92  uint8_t rgba_color[4]; ///< color for the padding area
95 } PadContext;
96 
97 static av_cold int init(AVFilterContext *ctx)
98 {
99  PadContext *pad = ctx->priv;
100 
101  if (av_parse_color(pad->rgba_color, pad->color_str, -1, ctx) < 0)
102  return AVERROR(EINVAL);
103 
104  return 0;
105 }
106 
107 static int config_input(AVFilterLink *inlink)
108 {
109  AVFilterContext *ctx = inlink->dst;
110  PadContext *pad = ctx->priv;
111  int ret;
112  double var_values[VARS_NB], res;
113  char *expr;
114 
115  ff_draw_init(&pad->draw, inlink->format, 0);
116  ff_draw_color(&pad->draw, &pad->color, pad->rgba_color);
117 
118  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
119  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
120  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
121  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
122  var_values[VAR_A] = (double) inlink->w / inlink->h;
123  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
124  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
125  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
126  var_values[VAR_HSUB] = 1 << pad->draw.hsub_max;
127  var_values[VAR_VSUB] = 1 << pad->draw.vsub_max;
128 
129  /* evaluate width and height */
130  av_expr_parse_and_eval(&res, (expr = pad->w_expr),
131  var_names, var_values,
132  NULL, NULL, NULL, NULL, NULL, 0, ctx);
133  pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
134  if ((ret = av_expr_parse_and_eval(&res, (expr = pad->h_expr),
135  var_names, var_values,
136  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
137  goto eval_fail;
138  pad->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
139  /* evaluate the width again, as it may depend on the evaluated output height */
140  if ((ret = av_expr_parse_and_eval(&res, (expr = pad->w_expr),
141  var_names, var_values,
142  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
143  goto eval_fail;
144  pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
145 
146  /* evaluate x and y */
147  av_expr_parse_and_eval(&res, (expr = pad->x_expr),
148  var_names, var_values,
149  NULL, NULL, NULL, NULL, NULL, 0, ctx);
150  pad->x = var_values[VAR_X] = res;
151  if ((ret = av_expr_parse_and_eval(&res, (expr = pad->y_expr),
152  var_names, var_values,
153  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
154  goto eval_fail;
155  pad->y = var_values[VAR_Y] = res;
156  /* evaluate x again, as it may depend on the evaluated y value */
157  if ((ret = av_expr_parse_and_eval(&res, (expr = pad->x_expr),
158  var_names, var_values,
159  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
160  goto eval_fail;
161  pad->x = var_values[VAR_X] = res;
162 
163  /* sanity check params */
164  if (pad->w < 0 || pad->h < 0 || pad->x < 0 || pad->y < 0) {
165  av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n");
166  return AVERROR(EINVAL);
167  }
168 
169  if (!pad->w)
170  pad->w = inlink->w;
171  if (!pad->h)
172  pad->h = inlink->h;
173 
174  pad->w = ff_draw_round_to_sub(&pad->draw, 0, -1, pad->w);
175  pad->h = ff_draw_round_to_sub(&pad->draw, 1, -1, pad->h);
176  pad->x = ff_draw_round_to_sub(&pad->draw, 0, -1, pad->x);
177  pad->y = ff_draw_round_to_sub(&pad->draw, 1, -1, pad->y);
178  pad->in_w = ff_draw_round_to_sub(&pad->draw, 0, -1, inlink->w);
179  pad->in_h = ff_draw_round_to_sub(&pad->draw, 1, -1, inlink->h);
180 
181  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",
182  inlink->w, inlink->h, pad->w, pad->h, pad->x, pad->y,
183  pad->rgba_color[0], pad->rgba_color[1], pad->rgba_color[2], pad->rgba_color[3]);
184 
185  if (pad->x < 0 || pad->y < 0 ||
186  pad->w <= 0 || pad->h <= 0 ||
187  (unsigned)pad->x + (unsigned)inlink->w > pad->w ||
188  (unsigned)pad->y + (unsigned)inlink->h > pad->h) {
189  av_log(ctx, AV_LOG_ERROR,
190  "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
191  pad->x, pad->y, pad->x + inlink->w, pad->y + inlink->h, pad->w, pad->h);
192  return AVERROR(EINVAL);
193  }
194 
195  return 0;
196 
197 eval_fail:
199  "Error when evaluating the expression '%s'\n", expr);
200  return ret;
201 
202 }
203 
204 static int config_output(AVFilterLink *outlink)
205 {
206  PadContext *pad = outlink->src->priv;
207 
208  outlink->w = pad->w;
209  outlink->h = pad->h;
210  return 0;
211 }
212 
213 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
214 {
215  PadContext *pad = inlink->dst->priv;
216 
218  w + (pad->w - pad->in_w),
219  h + (pad->h - pad->in_h));
220  int plane;
221 
222  if (!frame)
223  return NULL;
224 
225  frame->width = w;
226  frame->height = h;
227 
228  for (plane = 0; plane < 4 && frame->data[plane]; plane++) {
229  int hsub = pad->draw.hsub[plane];
230  int vsub = pad->draw.vsub[plane];
231  frame->data[plane] += (pad->x >> hsub) * pad->draw.pixelstep[plane] +
232  (pad->y >> vsub) * frame->linesize[plane];
233  }
234 
235  return frame;
236 }
237 
238 /* check whether each plane in this buffer can be padded without copying */
240 {
241  int planes[4] = { -1, -1, -1, -1}, *p = planes;
242  int i, j;
243 
244  /* get all planes in this buffer */
245  for (i = 0; i < FF_ARRAY_ELEMS(planes) && frame->data[i]; i++) {
246  if (av_frame_get_plane_buffer(frame, i) == buf)
247  *p++ = i;
248  }
249 
250  /* for each plane in this buffer, check that it can be padded without
251  * going over buffer bounds or other planes */
252  for (i = 0; i < FF_ARRAY_ELEMS(planes) && planes[i] >= 0; i++) {
253  int hsub = s->draw.hsub[planes[i]];
254  int vsub = s->draw.vsub[planes[i]];
255 
256  uint8_t *start = frame->data[planes[i]];
257  uint8_t *end = start + (frame->height >> vsub) *
258  frame->linesize[planes[i]];
259 
260  /* amount of free space needed before the start and after the end
261  * of the plane */
262  ptrdiff_t req_start = (s->x >> hsub) * s->draw.pixelstep[planes[i]] +
263  (s->y >> vsub) * frame->linesize[planes[i]];
264  ptrdiff_t req_end = ((s->w - s->x - frame->width) >> hsub) *
265  s->draw.pixelstep[planes[i]] +
266  (s->y >> vsub) * frame->linesize[planes[i]];
267 
268  if (frame->linesize[planes[i]] < (s->w >> hsub) * s->draw.pixelstep[planes[i]])
269  return 1;
270  if (start - buf->data < req_start ||
271  (buf->data + buf->size) - end < req_end)
272  return 1;
273 
274 #define SIGN(x) ((x) > 0 ? 1 : -1)
275  for (j = 0; j < FF_ARRAY_ELEMS(planes) && planes[j] >= 0; j++) {
276  int vsub1 = s->draw.vsub[planes[j]];
277  uint8_t *start1 = frame->data[planes[j]];
278  uint8_t *end1 = start1 + (frame->height >> vsub1) *
279  frame->linesize[planes[j]];
280  if (i == j)
281  continue;
282 
283  if (SIGN(start - end1) != SIGN(start - end1 - req_start) ||
284  SIGN(end - start1) != SIGN(end - start1 + req_end))
285  return 1;
286  }
287  }
288 
289  return 0;
290 }
291 
293 {
294  int i;
295 
296  if (!av_frame_is_writable(frame))
297  return 1;
298 
299  for (i = 0; i < 4 && frame->buf[i]; i++)
300  if (buffer_needs_copy(s, frame, frame->buf[i]))
301  return 1;
302  return 0;
303 }
304 
305 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
306 {
307  PadContext *pad = inlink->dst->priv;
308  AVFrame *out;
309  int needs_copy = frame_needs_copy(pad, in);
310 
311  if (needs_copy) {
312  av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
313  out = ff_get_video_buffer(inlink->dst->outputs[0],
314  FFMAX(inlink->w, pad->w),
315  FFMAX(inlink->h, pad->h));
316  if (!out) {
317  av_frame_free(&in);
318  return AVERROR(ENOMEM);
319  }
320 
321  av_frame_copy_props(out, in);
322  } else {
323  int i;
324 
325  out = in;
326  for (i = 0; i < 4 && out->data[i]; i++) {
327  int hsub = pad->draw.hsub[i];
328  int vsub = pad->draw.vsub[i];
329  out->data[i] -= (pad->x >> hsub) * pad->draw.pixelstep[i] +
330  (pad->y >> vsub) * out->linesize[i];
331  }
332  }
333 
334  /* top bar */
335  if (pad->y) {
336  ff_fill_rectangle(&pad->draw, &pad->color,
337  out->data, out->linesize,
338  0, 0, pad->w, pad->y);
339  }
340 
341  /* bottom bar */
342  if (pad->h > pad->y + pad->in_h) {
343  ff_fill_rectangle(&pad->draw, &pad->color,
344  out->data, out->linesize,
345  0, pad->y + pad->in_h, pad->w, pad->h - pad->y - pad->in_h);
346  }
347 
348  /* left border */
349  ff_fill_rectangle(&pad->draw, &pad->color, out->data, out->linesize,
350  0, pad->y, pad->x, in->height);
351 
352  if (needs_copy) {
353  ff_copy_rectangle2(&pad->draw,
354  out->data, out->linesize, in->data, in->linesize,
355  pad->x, pad->y, 0, 0, in->width, in->height);
356  }
357 
358  /* right border */
359  ff_fill_rectangle(&pad->draw, &pad->color, out->data, out->linesize,
360  pad->x + pad->in_w, pad->y, pad->w - pad->x - pad->in_w,
361  in->height);
362 
363  out->width = pad->w;
364  out->height = pad->h;
365 
366  if (in != out)
367  av_frame_free(&in);
368  return ff_filter_frame(inlink->dst->outputs[0], out);
369 }
370 
371 #define OFFSET(x) offsetof(PadContext, x)
372 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
373 
374 static const AVOption pad_options[] = {
375  { "width", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
376  { "w", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
377  { "height", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
378  { "h", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
379  { "x", "set the x offset expression for the input image position", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
380  { "y", "set the y offset expression for the input image position", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
381  { "color", "set the color of the padded area border", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, .flags = FLAGS },
382  { NULL },
383 };
384 
386 
388  {
389  .name = "default",
390  .type = AVMEDIA_TYPE_VIDEO,
391  .config_props = config_input,
392  .get_video_buffer = get_video_buffer,
393  .filter_frame = filter_frame,
394  },
395  { NULL }
396 };
397 
399  {
400  .name = "default",
401  .type = AVMEDIA_TYPE_VIDEO,
402  .config_props = config_output,
403  },
404  { NULL }
405 };
406 
408  .name = "pad",
409  .description = NULL_IF_CONFIG_SMALL("Pad input image to width:height[:x:y[:color]] (default x and y: 0, default color: black)."),
410 
411  .priv_size = sizeof(PadContext),
412  .priv_class = &pad_class,
413  .init = init,
415 
416  .inputs = avfilter_vf_pad_inputs,
417 
418  .outputs = avfilter_vf_pad_outputs,
419 };
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:501
Definition: start.py:1
const char * s
Definition: avisynth_c.h:668
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: vf_pad.c:213
#define FLAGS
Definition: vf_pad.c:372
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:424
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
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:214
AVOption.
Definition: opt.h:251
misc image utilities
uint8_t hsub[MAX_PLANES]
Definition: drawutils.h:54
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
FFDrawColor color
Definition: vf_pad.c:94
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:343
#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:85
int x
Definition: vf_pad.c:84
int num
numerator
Definition: rational.h:44
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
Various defines for YUV<->RGB conversion.
char * x_expr
width expression string
Definition: vf_pad.c:89
static const AVFilterPad avfilter_vf_pad_outputs[]
Definition: vf_pad.c:398
#define FF_ARRAY_ELEMS(a)
static int config_output(AVFilterLink *outlink)
Definition: vf_pad.c:204
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:143
Definition: vf_pad.c:65
output residual component w
int w
Definition: vf_pad.c:83
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
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:489
const char * name
Pad name.
AVFILTER_DEFINE_CLASS(pad)
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
#define av_cold
Definition: attributes.h:78
Definition: vf_pad.c:68
AVOptions.
Definition: vf_pad.c:67
end end
#define NAN
Definition: math.h:7
static const char *const var_names[]
Definition: vf_pad.c:45
Definition: vf_pad.c:62
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:545
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:337
frame
Definition: stft.m:14
A filter pad used for either input or output.
Discrete Time axis x
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:701
int width
width and height of the video frame
Definition: frame.h:122
Definition: vf_pad.c:69
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
Definition: avfilter.h:545
static int config_input(AVFilterLink *inlink)
Definition: vf_pad.c:107
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:179
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:361
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:489
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:246
uint8_t vsub_max
Definition: drawutils.h:57
static const AVOption pad_options[]
Definition: vf_pad.c:374
#define FFMAX(a, b)
Definition: common.h:56
#define AV_LOG_VERBOSE
Definition: log.h:157
var_name
static int frame_needs_copy(PadContext *s, AVFrame *frame)
Definition: vf_pad.c:292
ret
Definition: avfilter.c:821
static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)
Definition: vf_pad.c:239
Definition: vf_pad.c:61
AVFilter avfilter_vf_pad
Definition: vf_pad.c:407
char * w_expr
width expression string
Definition: vf_pad.c:87
int y
offsets of the input area with respect to the padded area
Definition: vf_pad.c:84
int in_w
Definition: vf_pad.c:85
Definition: vf_pad.c:63
#define OFFSET(x)
Definition: vf_pad.c:371
uint8_t rgba_color[4]
color for the padding area
Definition: vf_pad.c:92
NULL
Definition: eval.c:55
static av_cold int init(AVFilterContext *ctx)
Definition: vf_pad.c:97
misc drawing utilities
Definition: vf_pad.c:72
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
static const AVFilterPad avfilter_vf_pad_inputs[]
Definition: vf_pad.c:387
uint8_t * data
The data buffer.
Definition: buffer.h:89
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
uint8_t hsub_max
Definition: drawutils.h:56
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
Definition: vf_pad.c:66
const char * name
filter name
Definition: avfilter.h:437
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:135
Definition: vf_pad.c:64
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
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:87
A reference to a data buffer.
Definition: buffer.h:81
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
common internal and external API header
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
int den
denominator
Definition: rational.h:45
FFDrawContext draw
Definition: vf_pad.c:93
char * y_expr
height expression string
Definition: vf_pad.c:90
int pixelstep[MAX_PLANES]
Definition: drawutils.h:52
int h
output dimensions, a value of 0 will result in the input size
Definition: vf_pad.c:83
char * h_expr
height expression string
Definition: vf_pad.c:88
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:236
An instance of a filter.
Definition: avfilter.h:524
int height
Definition: frame.h:122
uint8_t vsub[MAX_PLANES]
Definition: drawutils.h:55
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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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_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_dlog(ac->avr,"%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-> out
internal API functions
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
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pad.c:305
char * color_str
Definition: vf_pad.c:91
simple arithmetic expression evaluator