summaryrefslogtreecommitdiff
path: root/libavfilter/vf_crop.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-02-25 21:21:29 +0100
committerAnton Khirnov <anton@khirnov.net>2013-04-09 19:00:54 +0200
commitfba0156af77b11ec99edf4ee8f511b7aaa6b1891 (patch)
treef30e90694b30c9b459b018950c4e0e4aabee727a /libavfilter/vf_crop.c
parent51def31dbe5b6e857536de8fa428f263d64f3ae5 (diff)
vf_crop: switch to an AVOptions-based system.
Diffstat (limited to 'libavfilter/vf_crop.c')
-rw-r--r--libavfilter/vf_crop.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index 2b571c4f8a..ec545b3d58 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -37,6 +37,7 @@
#include "libavutil/libm.h"
#include "libavutil/imgutils.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
static const char *const var_names[] = {
"E",
@@ -70,6 +71,7 @@ enum var_name {
};
typedef struct {
+ const AVClass *class;
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
int w; ///< width of the cropped area
@@ -77,7 +79,7 @@ typedef struct {
int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes
int hsub, vsub; ///< chroma subsampling
- char x_expr[256], y_expr[256], ow_expr[256], oh_expr[256];
+ char *x_expr, *y_expr, *ow_expr, *oh_expr;
AVExpr *x_pexpr, *y_pexpr; /* parsed expressions for x and y */
double var_values[VAR_VARS_NB];
} CropContext;
@@ -115,21 +117,6 @@ static int query_formats(AVFilterContext *ctx)
return 0;
}
-static av_cold int init(AVFilterContext *ctx, const char *args)
-{
- CropContext *crop = ctx->priv;
-
- av_strlcpy(crop->ow_expr, "iw", sizeof(crop->ow_expr));
- av_strlcpy(crop->oh_expr, "ih", sizeof(crop->oh_expr));
- av_strlcpy(crop->x_expr, "(in_w-out_w)/2", sizeof(crop->x_expr));
- av_strlcpy(crop->y_expr, "(in_h-out_h)/2", sizeof(crop->y_expr));
-
- if (args)
- sscanf(args, "%255[^:]:%255[^:]:%255[^:]:%255[^:]", crop->ow_expr, crop->oh_expr, crop->x_expr, crop->y_expr);
-
- return 0;
-}
-
static av_cold void uninit(AVFilterContext *ctx)
{
CropContext *crop = ctx->priv;
@@ -294,6 +281,25 @@ 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_VIDEO_PARAM
+static const AVOption options[] = {
+ { "out_w", "Output video width", OFFSET(ow_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
+ { "out_h", "Output video height", OFFSET(oh_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
+ { "x", "Horizontal position in the input video of the left edge of the cropped output video",
+ OFFSET(x_expr), AV_OPT_TYPE_STRING, { .str = "(in_w - out_w) / 2" }, .flags = FLAGS },
+ { "y", "Vertical position in the input video of the top edge of the cropped output video",
+ OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str = "(in_h - out_h) / 2" }, .flags = FLAGS },
+ { NULL },
+};
+
+static const AVClass crop_class = {
+ .class_name = "crop",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
static const AVFilterPad avfilter_vf_crop_inputs[] = {
{
.name = "default",
@@ -319,9 +325,9 @@ AVFilter avfilter_vf_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,
- .init = init,
.uninit = uninit,
.inputs = avfilter_vf_crop_inputs,