|
|
|
@ -91,30 +91,6 @@ typedef struct { |
|
|
|
|
double var_values[VAR_VARS_NB]; |
|
|
|
|
} CropContext; |
|
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(CropContext, x) |
|
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM |
|
|
|
|
|
|
|
|
|
static const AVOption crop_options[] = { |
|
|
|
|
{ "x", "set the x crop area expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "(in_w-out_w)/2"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "y", "set the y crop area expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "(in_h-out_h)/2"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "out_w", "set the width crop area expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "w", "set the width crop area expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "out_h", "set the height crop area expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "h", "set the height crop area expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "keep_aspect", "keep aspect ratio", OFFSET(keep_aspect), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS }, |
|
|
|
|
{NULL} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(crop); |
|
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx) |
|
|
|
|
{ |
|
|
|
|
CropContext *crop = ctx->priv; |
|
|
|
|
|
|
|
|
|
av_expr_free(crop->x_pexpr); crop->x_pexpr = NULL; |
|
|
|
|
av_expr_free(crop->y_pexpr); crop->y_pexpr = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx) |
|
|
|
|
{ |
|
|
|
|
static const enum AVPixelFormat pix_fmts[] = { |
|
|
|
@ -148,6 +124,14 @@ static int query_formats(AVFilterContext *ctx) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx) |
|
|
|
|
{ |
|
|
|
|
CropContext *crop = ctx->priv; |
|
|
|
|
|
|
|
|
|
av_expr_free(crop->x_pexpr); crop->x_pexpr = NULL; |
|
|
|
|
av_expr_free(crop->y_pexpr); crop->y_pexpr = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline int normalize_double(int *n, double d) |
|
|
|
|
{ |
|
|
|
|
int ret = 0; |
|
|
|
@ -316,6 +300,22 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) |
|
|
|
|
return ff_filter_frame(link->dst->outputs[0], frame); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(CropContext, x) |
|
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM |
|
|
|
|
|
|
|
|
|
static const AVOption crop_options[] = { |
|
|
|
|
{ "out_w", "set the width crop area expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "w", "set the width crop area expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "out_h", "set the height crop area expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "h", "set the height crop area expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "x", "set the x crop area expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "(in_w-out_w)/2"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "y", "set the y crop area expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "(in_h-out_h)/2"}, CHAR_MIN, CHAR_MAX, FLAGS }, |
|
|
|
|
{ "keep_aspect", "keep aspect ratio", OFFSET(keep_aspect), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS }, |
|
|
|
|
{NULL} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(crop); |
|
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_crop_inputs[] = { |
|
|
|
|
{ |
|
|
|
|
.name = "default", |
|
|
|
@ -336,13 +336,12 @@ static const AVFilterPad avfilter_vf_crop_outputs[] = { |
|
|
|
|
{ NULL } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static const char *const shorthand[] = { "w", "h", "x", "y", "keep_aspect", NULL }; |
|
|
|
|
|
|
|
|
|
AVFilter avfilter_vf_crop = { |
|
|
|
|
.name = "crop", |
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Crop the input video to width:height:x:y."), |
|
|
|
|
|
|
|
|
|
.priv_size = sizeof(CropContext), |
|
|
|
|
.priv_class = &crop_class, |
|
|
|
|
|
|
|
|
|
.query_formats = query_formats, |
|
|
|
|
.uninit = uninit, |
|
|
|
@ -350,5 +349,4 @@ AVFilter avfilter_vf_crop = { |
|
|
|
|
.inputs = avfilter_vf_crop_inputs, |
|
|
|
|
.outputs = avfilter_vf_crop_outputs, |
|
|
|
|
.priv_class = &crop_class, |
|
|
|
|
.shorthand = shorthand, |
|
|
|
|
}; |
|
|
|
|