FFmpeg  2.1.1
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/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  "in_w", "iw",
46  "in_h", "ih",
47  "out_w", "ow",
48  "out_h", "oh",
49  "x",
50  "y",
51  "a",
52  "sar",
53  "dar",
54  "hsub",
55  "vsub",
56  NULL
57 };
58 
59 enum var_name {
72 };
73 
75 {
77  return 0;
78 }
79 
80 typedef struct {
81  const AVClass *class;
82  int w, h; ///< output dimensions, a value of 0 will result in the input size
83  int x, y; ///< offsets of the input area with respect to the padded area
84  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
85 
86  char *w_expr; ///< width expression string
87  char *h_expr; ///< height expression string
88  char *x_expr; ///< width expression string
89  char *y_expr; ///< height expression string
90  uint8_t rgba_color[4]; ///< color for the padding area
93 } PadContext;
94 
95 static int config_input(AVFilterLink *inlink)
96 {
97  AVFilterContext *ctx = inlink->dst;
98  PadContext *s = ctx->priv;
99  int ret;
100  double var_values[VARS_NB], res;
101  char *expr;
102 
103  ff_draw_init(&s->draw, inlink->format, 0);
104  ff_draw_color(&s->draw, &s->color, s->rgba_color);
105 
106  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
107  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
108  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
109  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
110  var_values[VAR_A] = (double) inlink->w / inlink->h;
111  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
112  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
113  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
114  var_values[VAR_HSUB] = 1 << s->draw.hsub_max;
115  var_values[VAR_VSUB] = 1 << s->draw.vsub_max;
116 
117  /* evaluate width and height */
118  av_expr_parse_and_eval(&res, (expr = s->w_expr),
119  var_names, var_values,
120  NULL, NULL, NULL, NULL, NULL, 0, ctx);
121  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
122  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
123  var_names, var_values,
124  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
125  goto eval_fail;
126  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
127  /* evaluate the width again, as it may depend on the evaluated output height */
128  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
129  var_names, var_values,
130  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
131  goto eval_fail;
132  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
133 
134  /* evaluate x and y */
135  av_expr_parse_and_eval(&res, (expr = s->x_expr),
136  var_names, var_values,
137  NULL, NULL, NULL, NULL, NULL, 0, ctx);
138  s->x = var_values[VAR_X] = res;
139  if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),
140  var_names, var_values,
141  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
142  goto eval_fail;
143  s->y = var_values[VAR_Y] = res;
144  /* evaluate x again, as it may depend on the evaluated y value */
145  if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),
146  var_names, var_values,
147  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
148  goto eval_fail;
149  s->x = var_values[VAR_X] = res;
150 
151  /* sanity check params */
152  if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) {
153  av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n");
154  return AVERROR(EINVAL);
155  }
156 
157  if (!s->w)
158  s->w = inlink->w;
159  if (!s->h)
160  s->h = inlink->h;
161 
162  s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
163  s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
164  s->x = ff_draw_round_to_sub(&s->draw, 0, -1, s->x);
165  s->y = ff_draw_round_to_sub(&s->draw, 1, -1, s->y);
166  s->in_w = ff_draw_round_to_sub(&s->draw, 0, -1, inlink->w);
167  s->in_h = ff_draw_round_to_sub(&s->draw, 1, -1, inlink->h);
168 
169  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",
170  inlink->w, inlink->h, s->w, s->h, s->x, s->y,
171  s->rgba_color[0], s->rgba_color[1], s->rgba_color[2], s->rgba_color[3]);
172 
173  if (s->x < 0 || s->y < 0 ||
174  s->w <= 0 || s->h <= 0 ||
175  (unsigned)s->x + (unsigned)inlink->w > s->w ||
176  (unsigned)s->y + (unsigned)inlink->h > s->h) {
177  av_log(ctx, AV_LOG_ERROR,
178  "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
179  s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);
180  return AVERROR(EINVAL);
181  }
182 
183  return 0;
184 
185 eval_fail:
186  av_log(NULL, AV_LOG_ERROR,
187  "Error when evaluating the expression '%s'\n", expr);
188  return ret;
189 
190 }
191 
192 static int config_output(AVFilterLink *outlink)
193 {
194  PadContext *s = outlink->src->priv;
195 
196  outlink->w = s->w;
197  outlink->h = s->h;
198  return 0;
199 }
200 
201 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
202 {
203  PadContext *s = inlink->dst->priv;
204 
206  w + (s->w - s->in_w),
207  h + (s->h - s->in_h));
208  int plane;
209 
210  if (!frame)
211  return NULL;
212 
213  frame->width = w;
214  frame->height = h;
215 
216  for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
217  int hsub = s->draw.hsub[plane];
218  int vsub = s->draw.vsub[plane];
219  frame->data[plane] += (s->x >> hsub) * s->draw.pixelstep[plane] +
220  (s->y >> vsub) * frame->linesize[plane];
221  }
222 
223  return frame;
224 }
225 
226 /* check whether each plane in this buffer can be padded without copying */
228 {
229  int planes[4] = { -1, -1, -1, -1}, *p = planes;
230  int i, j;
231 
232  /* get all planes in this buffer */
233  for (i = 0; i < FF_ARRAY_ELEMS(planes) && frame->data[i]; i++) {
234  if (av_frame_get_plane_buffer(frame, i) == buf)
235  *p++ = i;
236  }
237 
238  /* for each plane in this buffer, check that it can be padded without
239  * going over buffer bounds or other planes */
240  for (i = 0; i < FF_ARRAY_ELEMS(planes) && planes[i] >= 0; i++) {
241  int hsub = s->draw.hsub[planes[i]];
242  int vsub = s->draw.vsub[planes[i]];
243 
244  uint8_t *start = frame->data[planes[i]];
245  uint8_t *end = start + (frame->height >> vsub) *
246  frame->linesize[planes[i]];
247 
248  /* amount of free space needed before the start and after the end
249  * of the plane */
250  ptrdiff_t req_start = (s->x >> hsub) * s->draw.pixelstep[planes[i]] +
251  (s->y >> vsub) * frame->linesize[planes[i]];
252  ptrdiff_t req_end = ((s->w - s->x - frame->width) >> hsub) *
253  s->draw.pixelstep[planes[i]] +
254  (s->y >> vsub) * frame->linesize[planes[i]];
255 
256  if (frame->linesize[planes[i]] < (s->w >> hsub) * s->draw.pixelstep[planes[i]])
257  return 1;
258  if (start - buf->data < req_start ||
259  (buf->data + buf->size) - end < req_end)
260  return 1;
261 
262  for (j = 0; j < FF_ARRAY_ELEMS(planes) && planes[j] >= 0; j++) {
263  int vsub1 = s->draw.vsub[planes[j]];
264  uint8_t *start1 = frame->data[planes[j]];
265  uint8_t *end1 = start1 + (frame->height >> vsub1) *
266  frame->linesize[planes[j]];
267  if (i == j)
268  continue;
269 
270  if (FFSIGN(start - end1) != FFSIGN(start - end1 - req_start) ||
271  FFSIGN(end - start1) != FFSIGN(end - start1 + req_end))
272  return 1;
273  }
274  }
275 
276  return 0;
277 }
278 
280 {
281  int i;
282 
283  if (!av_frame_is_writable(frame))
284  return 1;
285 
286  for (i = 0; i < 4 && frame->buf[i]; i++)
287  if (buffer_needs_copy(s, frame, frame->buf[i]))
288  return 1;
289  return 0;
290 }
291 
292 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
293 {
294  PadContext *s = inlink->dst->priv;
295  AVFrame *out;
296  int needs_copy = frame_needs_copy(s, in);
297 
298  if (needs_copy) {
299  av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
300  out = ff_get_video_buffer(inlink->dst->outputs[0],
301  FFMAX(inlink->w, s->w),
302  FFMAX(inlink->h, s->h));
303  if (!out) {
304  av_frame_free(&in);
305  return AVERROR(ENOMEM);
306  }
307 
308  av_frame_copy_props(out, in);
309  } else {
310  int i;
311 
312  out = in;
313  for (i = 0; i < 4 && out->data[i] && out->linesize[i]; i++) {
314  int hsub = s->draw.hsub[i];
315  int vsub = s->draw.vsub[i];
316  out->data[i] -= (s->x >> hsub) * s->draw.pixelstep[i] +
317  (s->y >> vsub) * out->linesize[i];
318  }
319  }
320 
321  /* top bar */
322  if (s->y) {
323  ff_fill_rectangle(&s->draw, &s->color,
324  out->data, out->linesize,
325  0, 0, s->w, s->y);
326  }
327 
328  /* bottom bar */
329  if (s->h > s->y + s->in_h) {
330  ff_fill_rectangle(&s->draw, &s->color,
331  out->data, out->linesize,
332  0, s->y + s->in_h, s->w, s->h - s->y - s->in_h);
333  }
334 
335  /* left border */
336  ff_fill_rectangle(&s->draw, &s->color, out->data, out->linesize,
337  0, s->y, s->x, in->height);
338 
339  if (needs_copy) {
341  out->data, out->linesize, in->data, in->linesize,
342  s->x, s->y, 0, 0, in->width, in->height);
343  }
344 
345  /* right border */
346  ff_fill_rectangle(&s->draw, &s->color, out->data, out->linesize,
347  s->x + s->in_w, s->y, s->w - s->x - s->in_w,
348  in->height);
349 
350  out->width = s->w;
351  out->height = s->h;
352 
353  if (in != out)
354  av_frame_free(&in);
355  return ff_filter_frame(inlink->dst->outputs[0], out);
356 }
357 
358 #define OFFSET(x) offsetof(PadContext, x)
359 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
360 
361 static const AVOption pad_options[] = {
362  { "width", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
363  { "w", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
364  { "height", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
365  { "h", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
366  { "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 },
367  { "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 },
368  { "color", "set the color of the padded area border", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
369  { NULL }
370 };
371 
373 
375  {
376  .name = "default",
377  .type = AVMEDIA_TYPE_VIDEO,
378  .config_props = config_input,
379  .get_video_buffer = get_video_buffer,
380  .filter_frame = filter_frame,
381  },
382  { NULL }
383 };
384 
386  {
387  .name = "default",
388  .type = AVMEDIA_TYPE_VIDEO,
389  .config_props = config_output,
390  },
391  { NULL }
392 };
393 
395  .name = "pad",
396  .description = NULL_IF_CONFIG_SMALL("Pad the input video."),
397  .priv_size = sizeof(PadContext),
398  .priv_class = &pad_class,
400  .inputs = avfilter_vf_pad_inputs,
401  .outputs = avfilter_vf_pad_outputs,
402 };
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:518
const char * s
Definition: avisynth_c.h:668
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: vf_pad.c:201
#define FLAGS
Definition: vf_pad.c:359
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
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:231
AVOption.
Definition: opt.h:253
const char * name
Filter name.
Definition: avfilter.h:468
uint8_t hsub[MAX_PLANES]
Definition: drawutils.h:54
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
FFDrawColor color
Definition: vf_pad.c:92
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:84
int x
Definition: vf_pad.c:83
int num
numerator
Definition: rational.h:44
Various defines for YUV&lt;-&gt;RGB conversion.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
char * x_expr
width expression string
Definition: vf_pad.c:88
static const AVFilterPad avfilter_vf_pad_outputs[]
Definition: vf_pad.c:385
static int config_output(AVFilterLink *outlink)
Definition: vf_pad.c:192
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:382
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:513
int w
Definition: vf_pad.c:82
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
Definition: vf_crop.c:61
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:506
const char * name
Pad name.
Definition: internal.h:66
static uint8_t * res
Definition: ffhash.c:43
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
uint8_t
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
static const char *const var_names[]
Definition: vf_pad.c:44
Definition: vf_crop.c:60
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
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:531
Definition: vf_blend.c:65
static AVFrame * frame
Definition: demuxing.c:51
A filter pad used for either input or output.
Definition: internal.h:60
int width
width and height of the video frame
Definition: frame.h:145
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
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){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));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=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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
static int config_input(AVFilterLink *inlink)
Definition: vf_pad.c:95
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:191
uint8_t vsub_max
Definition: drawutils.h:57
static const AVOption pad_options[]
Definition: vf_pad.c:361
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
#define FF_ARRAY_ELEMS(a)
Definition: avcodec.h:929
uint8_t * data
The data buffer.
Definition: buffer.h:89
Definition: vf_blend.c:65
var_name
static int frame_needs_copy(PadContext *s, AVFrame *frame)
Definition: vf_pad.c:279
ret
Definition: avfilter.c:961
static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)
Definition: vf_pad.c:227
AVFilter avfilter_vf_pad
Definition: vf_pad.c:394
char * w_expr
width expression string
Definition: vf_pad.c:86
int y
offsets of the input area with respect to the padded area
Definition: vf_pad.c:83
Definition: vf_blend.c:65
int av_expr_parse_and_eval(double *res, 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:702
int in_w
Definition: vf_pad.c:84
#define OFFSET(x)
Definition: vf_pad.c:358
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
uint8_t rgba_color[4]
color for the padding area
Definition: vf_pad.c:90
misc drawing utilities
#define FFMAX(a, b)
Definition: avcodec.h:923
static const AVFilterPad avfilter_vf_pad_inputs[]
Definition: vf_pad.c:374
Definition: vf_crop.c:59
void * buf
Definition: avisynth_c.h:594
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:366
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:464
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:149
Definition: vf_crop.c:62
int size
Size of data in bytes.
Definition: buffer.h:93
static int query_formats(AVFilterContext *ctx)
Definition: vf_pad.c:74
A reference to a data buffer.
Definition: buffer.h:81
int den
denominator
Definition: rational.h:45
FFDrawContext draw
Definition: vf_pad.c:91
#define FFSIGN(a)
Definition: avcodec.h:921
char * y_expr
height expression string
Definition: vf_pad.c:89
#define NAN
Definition: math.h:28
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){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));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=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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);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
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
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:82
char * h_expr
height expression string
Definition: vf_pad.c:87
#define AVERROR(e)
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:253
An instance of a filter.
Definition: avfilter.h:627
int height
Definition: frame.h:145
uint8_t vsub[MAX_PLANES]
Definition: drawutils.h:55
void INT64 start
Definition: avisynth_c.h:594
internal API functions
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pad.c:292