32 #include "libavutil/eval.h"
33 #include "libavutil/avstring.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/opt.h"
88 char *x_expr, *
y_expr, *w_expr, *h_expr;
125 }
else if (d > INT_MAX || d < INT_MIN) {
126 *n = d > INT_MAX ? INT_MAX : INT_MIN;
164 NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
169 NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
175 NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
182 "Too big value or invalid expression for out_w/ow or out_h/oh. "
183 "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
187 s->
w &= ~((1 << s->
hsub) - 1);
188 s->
h &= ~((1 << s->
vsub) - 1);
194 NULL, NULL, NULL, NULL, 0, ctx)) < 0 ||
196 NULL, NULL, NULL, NULL, 0, ctx)) < 0)
203 dar.num * s->
h, dar.den * s->
w, INT_MAX);
205 s->out_sar = link->sample_aspect_ratio;
208 link->w, link->h, link->sample_aspect_ratio.num, link->sample_aspect_ratio.den,
209 s->w,
s->h,
s->out_sar.num,
s->out_sar.den);
211 if (
s->w <= 0 ||
s->h <= 0 ||
212 s->w > link->w ||
s->h > link->h) {
214 "Invalid too big or non positive size for width '%d' or height '%d'\n",
220 s->x = (link->w -
s->w) / 2;
221 s->y = (link->h -
s->h) / 2;
222 s->x &= ~((1 <<
s->hsub) - 1);
223 s->y &= ~((1 <<
s->vsub) - 1);
268 if ((
unsigned)s->
x + (
unsigned)s->
w > link->
w)
269 s->
x = link->
w - s->
w;
270 if ((
unsigned)s->
y + (
unsigned)s->
h > link->
h)
271 s->
y = link->
h - s->
h;
272 s->
x &= ~((1 << s->
hsub) - 1);
273 s->
y &= ~((1 << s->
vsub) - 1);
275 av_dlog(ctx,
"n:%d t:%f pos:%f x:%d y:%d x+w:%d y+h:%d\n",
277 s->
x, s->
y, s->
x+s->
w, s->
y+s->
h);
283 for (i = 1; i < 3; i ++) {
284 if (frame->
data[i]) {
292 if (frame->
data[3]) {
300 #define OFFSET(x) offsetof(CropContext, x)
301 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
339 .priv_class = &crop_class,
342 .
inputs = avfilter_vf_crop_inputs,
343 .
outputs = avfilter_vf_crop_outputs,
This structure describes decoded (raw) audio or video data.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
const char * name
Filter name.
static int config_input(AVFilterLink *link)
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
int h
agreed upon image height
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...
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.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static enum AVSampleFormat formats[]
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
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.
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int x
x offset of the non-cropped area with respect to the input area
int y
y offset of the non-cropped area with respect to the input area
static av_always_inline av_const int isnan(float x)
int max_step[4]
max pixel step for each plane, expressed as a number of bytes
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
static const AVFilterPad avfilter_vf_crop_outputs[]
static double av_q2d(AVRational a)
Convert rational to double.
AVFilter avfilter_vf_crop
AVRational av_mul_q(AVRational b, AVRational c) av_const
Multiply two rationals.
#define AV_LOG_VERBOSE
Detailed information.
static const AVFilterPad avfilter_vf_crop_inputs[]
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
A filter pad used for either input or output.
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
double var_values[VAR_VARS_NB]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
static av_always_inline av_const double round(double x)
int w
agreed upon image width
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
common internal API header
AVRational out_sar
output sample aspect ratio
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.
static int query_formats(AVFilterContext *ctx)
int format
agreed upon media format
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int h
height of the cropped area
int vsub
chroma subsampling
AVFilterLink ** outputs
array of pointers to output links
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static av_cold void uninit(AVFilterContext *ctx)
Replacements for frequently missing libm functions.
Describe the class of an AVClass context structure.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
static const AVOption crop_options[]
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
static const char *const var_names[]
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
static int normalize_double(int *n, double d)
static int config_output(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
int keep_aspect
keep display aspect ratio when cropping
int w
width of the cropped area
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
int64_t frame_count
Number of past frames sent through the link.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int filter_frame(AVFilterLink *link, AVFrame *frame)