FFmpeg: libavfilter/vf_pad.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2008 vmrsss
3 * Copyright (c) 2009 Stefano Sabatini
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * video padding filter
25 */
26
27 #include <float.h> /* DBL_MAX */
28
42
44
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",
58 };
59
73 };
74
76 {
78 }
79
84 };
85
88 int w,
h;
///< output dimensions, a value of 0 will result in the input size
89 int x,
y;
///< offsets of the input area with respect to the padded area
90 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
93
94 char *
w_expr;
///< width expression string
95 char *
h_expr;
///< height expression string
96 char *
x_expr;
///< width expression string
97 char *
y_expr;
///< height expression string
101
104
106 {
111 double var_values[
VARS_NB], res;
112 char *expr;
113
116
123 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
125 var_values[
VAR_HSUB] = 1 <<
s->draw.hsub_max;
126 var_values[
VAR_VSUB] = 1 <<
s->draw.vsub_max;
127
128 /* evaluate width and height */
136 goto eval_fail;
140
141 /* evaluate the width again, as it may depend on the evaluated output height */
145 goto eval_fail;
149
150 if (adjusted_aspect.
num && adjusted_aspect.
den) {
151 adjusted_aspect =
av_div_q(adjusted_aspect,
inlink->sample_aspect_ratio);
154 } else {
156 }
157 }
158
159 /* evaluate x and y */
163 s->x = var_values[
VAR_X] = res;
167 goto eval_fail;
168 s->y = var_values[
VAR_Y] = res;
169 /* evaluate x again, as it may depend on the evaluated y value */
173 goto eval_fail;
174 s->x = var_values[
VAR_X] = res;
175
180
183 /* sanity check params */
187 }
188
195
198 s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2],
s->rgba_color[3]);
199
200 if (
s->x < 0 ||
s->y < 0 ||
201 s->w <= 0 ||
s->h <= 0 ||
202 (
unsigned)
s->x + (
unsigned)
inlink->w >
s->w ||
203 (
unsigned)
s->y + (
unsigned)
inlink->h >
s->h) {
205 "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
208 }
209
210 return 0;
211
212 eval_fail:
214 "Error when evaluating the expression '%s'\n", expr);
216
217 }
218
220 {
222
225 return 0;
226 }
227
229 {
232 int plane;
233
234 if (
s->inlink_w <= 0)
236
238 w + (
s->w -
s->in_w),
239 h + (
s->h -
s->in_h) + (
s->x > 0));
240
243
246
248 int hsub =
s->draw.hsub[plane];
249 int vsub =
s->draw.vsub[plane];
252 }
253
255 }
256
257 /* check whether each plane in this buffer can be padded without copying */
259 {
262
263 /* get all planes in this buffer */
267 }
268
269 /* for each plane in this buffer, check that it can be padded without
270 * going over buffer bounds or other planes */
274
278
279 /* amount of free space needed before the start and after the end
280 * of the plane */
281 ptrdiff_t req_start = (
s->x >>
hsub) *
s->draw.pixelstep[
planes[
i]] +
286
288 return 1;
289 if (start - buf->
data < req_start ||
290 (buf->
data + buf->
size) - end < req_end)
291 return 1;
292
294 int vsub1 =
s->draw.vsub[
planes[j]];
296 uint8_t *end1 = start1 + (
frame->
height >> vsub1) *
299 continue;
300
301 if (
FFSIGN(start - end1) !=
FFSIGN(start - end1 - req_start) ||
303 return 1;
304 }
305 }
306
307 return 0;
308 }
309
311 {
313
315 return 1;
316
319 return 1;
320 return 0;
321 }
322
324 {
328 int needs_copy;
335
339
342
343
347 }
351 }
352 }
353
355
356 if (needs_copy) {
364 }
365
367 } else {
369
371 for (
i = 0;
i < 4 &&
out->data[
i] &&
out->linesize[
i];
i++) {
372 int hsub =
s->draw.hsub[
i];
373 int vsub =
s->draw.vsub[
i];
374 out->data[
i] -= (
s->x >>
hsub) *
s->draw.pixelstep[
i] +
375 (
s->y >> vsub) *
out->linesize[
i];
376 }
377 }
378
379 /* top bar */
384 }
385
386 /* bottom bar */
387 if (
s->h >
s->y +
s->in_h) {
390 0,
s->y +
s->in_h,
s->w,
s->h -
s->y -
s->in_h);
391 }
392
393 /* left border */
396
397 if (needs_copy) {
401 }
402
403 /* right border */
405 s->x +
s->in_w,
s->y,
s->w -
s->x -
s->in_w,
407
410
414 }
415
416 #define OFFSET(x) offsetof(PadContext, x)
417 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
418
432 };
433
435
437 {
443 },
444 };
445
447 {
451 },
452 };
453
458 .priv_class = &pad_class,
462 };
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
char * w_expr
width expression string
int eval_mode
expression evaluation mode
int y
offsets of the input area with respect to the padded area
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint8_t * data
The data buffer.
char * y_expr
height expression string
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
This structure describes decoded (raw) audio or video data.
#define FILTER_QUERY_FUNC(func)
static const char *const var_names[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
A link between two filters.
static const AVFilterPad avfilter_vf_pad_outputs[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * priv
private data for use by the filter
A filter pad used for either input or output.
static int config_output(AVFilterLink *outlink)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
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.
static int config_input(AVFilterLink *inlink)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVFILTER_DEFINE_CLASS(pad)
#define FILTER_INPUTS(array)
int h
output dimensions, a value of 0 will result in the input size
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
static const AVFilterPad avfilter_vf_pad_inputs[]
AVBufferRef * av_frame_get_plane_buffer(const AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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.
static const AVOption pad_options[]
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, unsigned flags)
Init a draw context.
int format
agreed upon media format
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.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
char * h_expr
height expression string
char * x_expr
width expression string
static int frame_needs_copy(PadContext *s, AVFrame *frame)
size_t size
Size of data in bytes.
#define i(width, name, range_min, range_max)
int w
agreed upon image width
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
static int query_formats(AVFilterContext *ctx)
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
uint8_t rgba_color[4]
color for the padding area
int h
agreed upon image height
A reference to a data buffer.
static const struct @386 planes[]
int in_h
width and height for the padded input video, which has to be aligned to the chroma values in order to...
#define FILTER_OUTPUTS(array)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Generated on Thu Sep 26 2024 23:15:39 for FFmpeg by
doxygen
1.8.17