FFmpeg
vf_crop.c
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 
28 #include "avfilter.h"
29 #include "filters.h"
30 #include "formats.h"
31 #include "video.h"
32 #include "libavutil/eval.h"
33 #include "libavutil/avstring.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/libm.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/opt.h"
39 
40 static const char *const var_names[] = {
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
57  NULL
58 };
59 
60 enum var_name {
73 #if FF_API_FRAME_PKT
74  VAR_POS,
75 #endif
78 };
79 
80 typedef struct CropContext {
81  const AVClass *class;
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 
87  AVRational out_sar; ///< output sample aspect ratio
88  int keep_aspect; ///< keep display aspect ratio when cropping
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
92  int hsub, vsub; ///< chroma subsampling
93  char *x_expr, *y_expr, *w_expr, *h_expr;
94  AVExpr *x_pexpr, *y_pexpr; /* parsed expressions for x and y */
96 } CropContext;
97 
98 static int query_formats(const AVFilterContext *ctx,
99  AVFilterFormatsConfig **cfg_in,
100  AVFilterFormatsConfig **cfg_out)
101 {
103 
104  return ff_set_common_formats2(ctx, cfg_in, cfg_out,
105  ff_formats_pixdesc_filter(0, reject_flags));
106 }
107 
109 {
110  CropContext *s = ctx->priv;
111 
112  av_expr_free(s->x_pexpr);
113  s->x_pexpr = NULL;
114  av_expr_free(s->y_pexpr);
115  s->y_pexpr = NULL;
116 }
117 
118 static inline int normalize_double(int *n, double d)
119 {
120  int ret = 0;
121 
122  if (isnan(d)) {
123  ret = AVERROR(EINVAL);
124  } else if (d > INT_MAX || d < INT_MIN) {
125  *n = d > INT_MAX ? INT_MAX : INT_MIN;
126  ret = AVERROR(EINVAL);
127  } else
128  *n = lrint(d);
129 
130  return ret;
131 }
132 
134 {
135  AVFilterContext *ctx = link->dst;
136  CropContext *s = ctx->priv;
138  int ret;
139  const char *expr;
140  double res;
141 
142  s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = ctx->inputs[0]->w;
143  s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = ctx->inputs[0]->h;
144  s->var_values[VAR_A] = (float) link->w / link->h;
146  s->var_values[VAR_DAR] = s->var_values[VAR_A] * s->var_values[VAR_SAR];
147  s->var_values[VAR_HSUB] = 1<<pix_desc->log2_chroma_w;
148  s->var_values[VAR_VSUB] = 1<<pix_desc->log2_chroma_h;
149  s->var_values[VAR_X] = NAN;
150  s->var_values[VAR_Y] = NAN;
151  s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = NAN;
152  s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = NAN;
153  s->var_values[VAR_N] = 0;
154  s->var_values[VAR_T] = NAN;
155 #if FF_API_FRAME_PKT
156  s->var_values[VAR_POS] = NAN;
157 #endif
158 
159  av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc);
160 
161  if (pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
162  s->hsub = 1;
163  s->vsub = 1;
164  } else {
165  s->hsub = pix_desc->log2_chroma_w;
166  s->vsub = pix_desc->log2_chroma_h;
167  }
168 
169  av_expr_parse_and_eval(&res, (expr = s->w_expr),
170  var_names, s->var_values,
171  NULL, NULL, NULL, NULL, NULL, 0, ctx);
172  s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = res;
173  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
174  var_names, s->var_values,
175  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
176  goto fail_expr;
177  s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = res;
178  /* evaluate again ow as it may depend on oh */
179  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
180  var_names, s->var_values,
181  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
182  goto fail_expr;
183 
184  s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = res;
185  if (normalize_double(&s->w, s->var_values[VAR_OUT_W]) < 0 ||
186  normalize_double(&s->h, s->var_values[VAR_OUT_H]) < 0) {
188  "Too big value or invalid expression for out_w/ow or out_h/oh. "
189  "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
190  s->w_expr, s->h_expr);
191  return AVERROR(EINVAL);
192  }
193 
194  if (!s->exact) {
195  s->w &= ~((1 << s->hsub) - 1);
196  s->h &= ~((1 << s->vsub) - 1);
197  }
198 
199  av_expr_free(s->x_pexpr);
200  av_expr_free(s->y_pexpr);
201  s->x_pexpr = s->y_pexpr = NULL;
202  if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names,
203  NULL, NULL, NULL, NULL, 0, ctx)) < 0 ||
204  (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names,
205  NULL, NULL, NULL, NULL, 0, ctx)) < 0)
206  return AVERROR(EINVAL);
207 
208  if (s->keep_aspect) {
210  (AVRational){ link->w, link->h });
211  av_reduce(&s->out_sar.num, &s->out_sar.den,
212  (int64_t)dar.num * s->h, (int64_t)dar.den * s->w, INT_MAX);
213  } else
214  s->out_sar = link->sample_aspect_ratio;
215 
216  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d sar:%d/%d -> w:%d h:%d sar:%d/%d\n",
218  s->w, s->h, s->out_sar.num, s->out_sar.den);
219 
220  if (s->w <= 0 || s->h <= 0 ||
221  s->w > link->w || s->h > link->h) {
223  "Invalid too big or non positive size for width '%d' or height '%d'\n",
224  s->w, s->h);
225  return AVERROR(EINVAL);
226  }
227 
228  /* set default, required in the case the first computed value for x/y is NAN */
229  s->x = (link->w - s->w) / 2;
230  s->y = (link->h - s->h) / 2;
231  if (!s->exact) {
232  s->x &= ~((1 << s->hsub) - 1);
233  s->y &= ~((1 << s->vsub) - 1);
234  }
235  return 0;
236 
237 fail_expr:
238  av_log(ctx, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr);
239  return ret;
240 }
241 
243 {
244  CropContext *s = link->src->priv;
246 
247  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
248  // Hardware frames adjust the cropping regions rather than
249  // changing the frame size.
250  } else {
251  link->w = s->w;
252  link->h = s->h;
253  }
254  link->sample_aspect_ratio = s->out_sar;
255 
256  return 0;
257 }
258 
260 {
262  AVFilterContext *ctx = link->dst;
263  CropContext *s = ctx->priv;
265  int i;
266 
267  s->var_values[VAR_N] = l->frame_count_out;
268  s->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ?
269  NAN : frame->pts * av_q2d(link->time_base);
270 #if FF_API_FRAME_PKT
272  s->var_values[VAR_POS] = frame->pkt_pos == -1 ?
273  NAN : frame->pkt_pos;
275 #endif
276  s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
277  s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
278  /* It is necessary if x is expressed from y */
279  s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
280 
281  normalize_double(&s->x, s->var_values[VAR_X]);
282  normalize_double(&s->y, s->var_values[VAR_Y]);
283 
284  if (s->x < 0)
285  s->x = 0;
286  if (s->y < 0)
287  s->y = 0;
288  if ((unsigned)s->x + (unsigned)s->w > link->w)
289  s->x = link->w - s->w;
290  if ((unsigned)s->y + (unsigned)s->h > link->h)
291  s->y = link->h - s->h;
292  if (!s->exact) {
293  s->x &= ~((1 << s->hsub) - 1);
294  s->y &= ~((1 << s->vsub) - 1);
295  }
296 
297  av_log(ctx, AV_LOG_TRACE, "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n",
298  (int)s->var_values[VAR_N], s->var_values[VAR_T],
299  s->x, s->y, s->x+s->w, s->y+s->h);
300 
301  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
302  frame->crop_top += s->y;
303  frame->crop_left += s->x;
304  frame->crop_bottom = frame->height - frame->crop_top - frame->crop_bottom - s->h;
305  frame->crop_right = frame->width - frame->crop_left - frame->crop_right - s->w;
306  } else {
307  frame->width = s->w;
308  frame->height = s->h;
309 
310  frame->data[0] += s->y * frame->linesize[0];
311  frame->data[0] += s->x * s->max_step[0];
312 
313  if (!(desc->flags & AV_PIX_FMT_FLAG_PAL)) {
314  for (i = 1; i < 3; i ++) {
315  if (frame->data[i]) {
316  frame->data[i] += (s->y >> s->vsub) * frame->linesize[i];
317  frame->data[i] += (s->x * s->max_step[i]) >> s->hsub;
318  }
319  }
320  }
321 
322  /* alpha plane */
323  if (frame->data[3]) {
324  frame->data[3] += s->y * frame->linesize[3];
325  frame->data[3] += s->x * s->max_step[3];
326  }
327  }
328 
329  return ff_filter_frame(link->dst->outputs[0], frame);
330 }
331 
332 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
333  char *res, int res_len, int flags)
334 {
335  CropContext *s = ctx->priv;
336  int ret;
337 
338  if ( !strcmp(cmd, "out_w") || !strcmp(cmd, "w")
339  || !strcmp(cmd, "out_h") || !strcmp(cmd, "h")
340  || !strcmp(cmd, "x") || !strcmp(cmd, "y")) {
341 
342  int old_x = s->x;
343  int old_y = s->y;
344  int old_w = s->w;
345  int old_h = s->h;
346 
347  AVFilterLink *outlink = ctx->outputs[0];
348  AVFilterLink *inlink = ctx->inputs[0];
349 
350  av_opt_set(s, cmd, args, 0);
351 
352  if ((ret = config_input(inlink)) < 0) {
353  s->x = old_x;
354  s->y = old_y;
355  s->w = old_w;
356  s->h = old_h;
357  return ret;
358  }
359 
360  ret = config_output(outlink);
361 
362  } else
363  ret = AVERROR(ENOSYS);
364 
365  return ret;
366 }
367 
368 #define OFFSET(x) offsetof(CropContext, x)
369 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
370 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
371 
372 static const AVOption crop_options[] = {
373  { "out_w", "set the width crop area expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, 0, 0, TFLAGS },
374  { "w", "set the width crop area expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, 0, 0, TFLAGS },
375  { "out_h", "set the height crop area expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, 0, 0, TFLAGS },
376  { "h", "set the height crop area expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, 0, 0, TFLAGS },
377  { "x", "set the x crop area expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "(in_w-out_w)/2"}, 0, 0, TFLAGS },
378  { "y", "set the y crop area expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "(in_h-out_h)/2"}, 0, 0, TFLAGS },
379  { "keep_aspect", "keep aspect ratio", OFFSET(keep_aspect), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
380  { "exact", "do exact cropping", OFFSET(exact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
381  { NULL }
382 };
383 
385 
387  {
388  .name = "default",
389  .type = AVMEDIA_TYPE_VIDEO,
390  .filter_frame = filter_frame,
391  .config_props = config_input,
392  },
393 };
394 
396  {
397  .name = "default",
398  .type = AVMEDIA_TYPE_VIDEO,
399  .config_props = config_output,
400  },
401 };
402 
404  .name = "crop",
405  .description = NULL_IF_CONFIG_SMALL("Crop the input video."),
406  .priv_size = sizeof(CropContext),
407  .priv_class = &crop_class,
408  .uninit = uninit,
412  .process_command = process_command,
413 };
OFFSET
#define OFFSET(x)
Definition: vf_crop.c:368
VAR_VSUB
@ VAR_VSUB
Definition: vf_crop.c:69
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
VAR_SAR
@ VAR_SAR
Definition: vf_crop.c:66
CropContext::var_values
double var_values[VAR_VARS_NB]
Definition: vf_crop.c:95
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_crop.c:108
AVERROR
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
opt.h
CropContext::x
int x
x offset of the non-cropped area with respect to the input area
Definition: vf_crop.c:82
var_name
var_name
Definition: noise.c:47
libm.h
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1007
VAR_T
@ VAR_T
Definition: vf_crop.c:76
int64_t
long long int64_t
Definition: coverity.c:34
CropContext::x_pexpr
AVExpr * x_pexpr
Definition: vf_crop.c:94
inlink
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
Definition: filter_design.txt:212
CropContext::y
int y
y offset of the non-cropped area with respect to the input area
Definition: vf_crop.c:83
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
CropContext::keep_aspect
int keep_aspect
keep display aspect ratio when cropping
Definition: vf_crop.c:88
crop_options
static const AVOption crop_options[]
Definition: vf_crop.c:372
AVOption
AVOption.
Definition: opt.h:429
CropContext::y_expr
char * y_expr
Definition: vf_crop.c:93
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
mathematics.h
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
VAR_HSUB
@ VAR_HSUB
Definition: vf_crop.c:68
video.h
normalize_double
static int normalize_double(int *n, double d)
Definition: vf_crop.c:118
CropContext::w
int w
width of the cropped area
Definition: vf_crop.c:84
VAR_A
@ VAR_A
Definition: vf_crop.c:65
formats.h
av_expr_parse
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.
Definition: eval.c:710
VAR_IN_W
@ VAR_IN_W
Definition: vf_crop.c:61
CropContext::vsub
int vsub
chroma subsampling
Definition: vf_crop.c:92
VAR_OUT_W
@ VAR_OUT_W
Definition: vf_crop.c:63
config_output
static int config_output(AVFilterLink *link)
Definition: vf_crop.c:242
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
CropContext::w_expr
char * w_expr
Definition: vf_crop.c:93
TFLAGS
#define TFLAGS
Definition: vf_crop.c:370
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:827
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:358
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
VAR_X
@ VAR_X
Definition: vf_crop.c:70
lrint
#define lrint
Definition: tablegen.h:53
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
ff_vf_crop
const AVFilter ff_vf_crop
Definition: vf_crop.c:403
float
float
Definition: af_crystalizer.c:122
VAR_IW
@ VAR_IW
Definition: vf_crop.c:61
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
var_names
static const char *const var_names[]
Definition: vf_crop.c:40
VAR_IN_H
@ VAR_IN_H
Definition: vf_crop.c:62
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:792
AVExpr
Definition: eval.c:158
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
NAN
#define NAN
Definition: mathematics.h:115
link
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
Definition: filter_design.txt:23
CropContext
Definition: vf_crop.c:80
FLAGS
#define FLAGS
Definition: vf_crop.c:369
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(crop)
VAR_POS
@ VAR_POS
Definition: noise.c:56
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
isnan
#define isnan(x)
Definition: libm.h:340
VAR_Y
@ VAR_Y
Definition: vf_crop.c:71
CropContext::h
int h
height of the cropped area
Definition: vf_crop.c:85
VAR_OH
@ VAR_OH
Definition: vf_crop.c:64
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:111
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
VAR_DAR
@ VAR_DAR
Definition: vf_crop.c:67
VAR_OUT_H
@ VAR_OUT_H
Definition: vf_crop.c:64
eval.h
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: vf_crop.c:259
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
av_expr_parse_and_eval
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:803
FF_PIX_FMT_FLAG_SW_FLAT_SUB
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition: formats.h:379
CropContext::y_pexpr
AVExpr * y_pexpr
Definition: vf_crop.c:94
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:516
AV_PIX_FMT_FLAG_BITSTREAM
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:124
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:476
CropContext::max_step
int max_step[4]
max pixel step for each plane, expressed as a number of bytes
Definition: vf_crop.c:91
VAR_N
@ VAR_N
Definition: vf_crop.c:72
ff_formats_pixdesc_filter
AVFilterFormats * ff_formats_pixdesc_filter(unsigned want, unsigned rej)
Construct a formats list containing all pixel formats with certain properties.
Definition: formats.c:553
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
config_input
static int config_input(AVFilterLink *link)
Definition: vf_crop.c:133
internal.h
avfilter_vf_crop_inputs
static const AVFilterPad avfilter_vf_crop_inputs[]
Definition: vf_crop.c:386
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
CropContext::out_sar
AVRational out_sar
output sample aspect ratio
Definition: vf_crop.c:87
AVFilter
Filter definition.
Definition: avfilter.h:201
ret
ret
Definition: filter_design.txt:187
frame
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:496
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_crop.c:98
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_crop.c:77
AVRational::den
int den
Denominator.
Definition: rational.h:60
avfilter.h
CropContext::exact
int exact
exact cropping, for subsampled formats
Definition: vf_crop.c:89
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
av_image_fill_max_pixsteps
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.
Definition: imgutils.c:35
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
CropContext::h_expr
char * h_expr
Definition: vf_crop.c:93
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
CropContext::x_expr
char * x_expr
Definition: vf_crop.c:93
CropContext::hsub
int hsub
Definition: vf_crop.c:92
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
avfilter_vf_crop_outputs
static const AVFilterPad avfilter_vf_crop_outputs[]
Definition: vf_crop.c:395
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_crop.c:332
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_PIX_FMT_FLAG_PAL
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:120
VAR_OW
@ VAR_OW
Definition: vf_crop.c:63
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
VAR_IH
@ VAR_IH
Definition: vf_crop.c:62