FFmpeg: libavfilter/vf_crop.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2007 Bobby Bingham
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * video crop filter
24 */
25
26 #include <stdio.h>
27
39
41 "in_w", "iw", ///< width of the input video
42 "in_h", "ih", ///< height of the input video
43 "out_w", "ow", ///< width of the cropped video
44 "out_h", "oh", ///< height of the cropped video
45 "a",
46 "sar",
47 "dar",
48 "hsub",
49 "vsub",
50 "x",
51 "y",
52 "n", ///< number of frame
53 #if FF_API_FRAME_PKT
54 "pos", ///< position in the file
55 #endif
56 "t", ///< timestamp expressed in seconds
58 };
59
73 #if FF_API_FRAME_PKT
75 #endif
78 };
79
82 int x;
///< x offset of the non-cropped area with respect to the input area
83 int y;
///< y offset of the non-cropped area with respect to the input area
84 int w;
///< width of the cropped area
85 int h;
///< height of the cropped area
86
89 int exact;
///< exact cropping, for subsampled formats
90
91 int max_step[4];
///< max pixel step for each plane, expressed as a number of bytes
97
99 {
101
103 }
104
106 {
108
113 }
114
116 {
118
121 }
else if (
d > INT_MAX ||
d < INT_MIN) {
122 *n =
d > INT_MAX ? INT_MAX : INT_MIN;
124 } else
126
128 }
129
131 {
136 const char *expr;
137 double res;
138
152 #if FF_API_FRAME_PKT
154 #endif
155
157
161 } else {
164 }
165
173 goto fail_expr;
175 /* evaluate again ow as it may depend on oh */
179 goto fail_expr;
180
185 "Too big value or invalid expression for out_w/ow or out_h/oh. "
186 "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
187 s->w_expr,
s->h_expr);
189 }
190
192 s->w &= ~((1 <<
s->hsub) - 1);
193 s->h &= ~((1 <<
s->vsub) - 1);
194 }
195
198 s->x_pexpr =
s->y_pexpr =
NULL;
204
205 if (
s->keep_aspect) {
209 dar.
num *
s->h, dar.
den *
s->w, INT_MAX);
210 } else
212
215 s->w,
s->h,
s->out_sar.num,
s->out_sar.den);
216
217 if (
s->w <= 0 ||
s->h <= 0 ||
220 "Invalid too big or non positive size for width '%d' or height '%d'\n",
223 }
224
225 /* set default, required in the case the first computed value for x/y is NAN */
226 s->x = (
link->w -
s->w) / 2;
227 s->y = (
link->h -
s->h) / 2;
229 s->x &= ~((1 <<
s->hsub) - 1);
230 s->y &= ~((1 <<
s->vsub) - 1);
231 }
232 return 0;
233
234 fail_expr:
237 }
238
240 {
243
245 // Hardware frames adjust the cropping regions rather than
246 // changing the frame size.
247 } else {
250 }
252
253 return 0;
254 }
255
257 {
262
266 #if FF_API_FRAME_PKT
271 #endif
274 /* It is necessary if x is expressed from y */
276
279
284 if ((
unsigned)
s->x + (
unsigned)
s->w >
link->w)
286 if ((
unsigned)
s->y + (
unsigned)
s->h >
link->h)
289 s->x &= ~((1 <<
s->hsub) - 1);
290 s->y &= ~((1 <<
s->vsub) - 1);
291 }
292
295 s->x,
s->y,
s->x+
s->w,
s->y+
s->h);
296
302 } else {
305
308
310 for (
i = 1;
i < 3;
i ++) {
314 }
315 }
316 }
317
318 /* alpha plane */
322 }
323 }
324
326 }
327
329 char *res,
int res_len,
int flags)
330 {
333
334 if ( !strcmp(cmd, "out_w") || !strcmp(cmd, "w")
335 || !strcmp(cmd, "out_h") || !strcmp(cmd, "h")
336 || !strcmp(cmd, "x") || !strcmp(cmd, "y")) {
337
342
345
347
354 }
355
357
358 } else
360
362 }
363
364 #define OFFSET(x) offsetof(CropContext, x)
365 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
366 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
367
378 };
379
381
383 {
388 },
389 };
390
392 {
396 },
397 };
398
403 .priv_class = &crop_class,
409 };
static int query_formats(AVFilterContext *ctx)
#define FF_ENABLE_DEPRECATION_WARNINGS
double var_values[VAR_VARS_NB]
static av_cold void uninit(AVFilterContext *ctx)
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
int x
x offset of the non-cropped area with respect to the input area
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
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
int y
y offset of the non-cropped area with respect to the input area
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int keep_aspect
keep display aspect ratio when cropping
static const AVOption crop_options[]
#define FILTER_QUERY_FUNC(func)
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
A link between two filters.
static int normalize_double(int *n, double d)
int w
width of the cropped area
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
int vsub
chroma subsampling
static int config_output(AVFilterLink *link)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const AVFilter ff_vf_crop
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static const char *const var_names[]
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define FILTER_INPUTS(array)
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 link
Describe the class of an AVClass context structure.
AVFILTER_DEFINE_CLASS(crop)
Rational number (pair of numerator and denominator).
int h
height of the cropped area
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
static int filter_frame(AVFilterLink *link, AVFrame *frame)
#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.
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVRational time_base
Time base for the timestamps in this frame.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
int max_step[4]
max pixel step for each plane, expressed as a number of bytes
#define i(width, name, range_min, range_max)
static int config_input(AVFilterLink *link)
static const AVFilterPad avfilter_vf_crop_inputs[]
const char * name
Pad name.
AVRational out_sar
output sample aspect ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int exact
exact cropping, for subsampled formats
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
#define FF_DISABLE_DEPRECATION_WARNINGS
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
static const AVFilterPad avfilter_vf_crop_outputs[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Generated on Thu Sep 26 2024 23:15:35 for FFmpeg by
doxygen
1.8.17