summaryrefslogtreecommitdiff
path: root/libavfilter
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:04:45 +0200
commitc334c113d4d9e9a41bc38a3e4458d7ab21010401 (patch)
treeef17c5c25e3760fc8f6ce00acd981ab19d7540e4 /libavfilter
parent5aa1a668cfae7f617e1a06efad20f87283badd8a (diff)
vf_scale: switch to an AVOptions-based system.
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/avfilter.c30
-rw-r--r--libavfilter/vf_scale.c50
2 files changed, 60 insertions, 20 deletions
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 29b0583023..a92c4acf98 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -481,6 +481,36 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
int ret=0;
if (args && *args && filter->filter->priv_class) {
+#if FF_API_OLD_FILTER_OPTS
+ if (!strcmp(filter->filter->name, "scale") &&
+ strchr(args, ':') < strchr(args, '=')) {
+ /* old w:h:flags=<flags> syntax */
+ char *copy = av_strdup(args);
+ char *p;
+
+ av_log(filter, AV_LOG_WARNING, "The <w>:<h>:flags=<flags> option "
+ "syntax is deprecated. Use either <w>:<h>:<flags> or "
+ "w=<w>:h=<h>:flags=<flags>.\n");
+
+ if (!copy) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ p = strrchr(copy, ':');
+ if (p) {
+ *p++ = 0;
+ ret = av_dict_parse_string(&options, p, "=", ":", 0);
+ }
+ if (ret >= 0)
+ ret = process_unnamed_options(filter, &options, copy);
+ av_freep(&copy);
+
+ if (ret < 0)
+ goto fail;
+ } else
+#endif
+
if (strchr(args, '=')) {
/* assume a list of key1=value1:key2=value2:... */
ret = av_dict_parse_string(&options, args, "=", ":", 0);
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index cb2b0a3654..db2762e086 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -69,6 +69,7 @@ enum var_name {
};
typedef struct {
+ const AVClass *class;
struct SwsContext *sws; ///< software scaler context
/**
@@ -83,31 +84,23 @@ typedef struct {
int slice_y; ///< top of current output slice
int input_is_pal; ///< set to 1 if the input format is paletted
- char w_expr[256]; ///< width expression string
- char h_expr[256]; ///< height expression string
+ char *w_expr; ///< width expression string
+ char *h_expr; ///< height expression string
+ char *flags_str;
} ScaleContext;
static av_cold int init(AVFilterContext *ctx, const char *args)
{
ScaleContext *scale = ctx->priv;
- const char *p;
-
- av_strlcpy(scale->w_expr, "iw", sizeof(scale->w_expr));
- av_strlcpy(scale->h_expr, "ih", sizeof(scale->h_expr));
-
- scale->flags = SWS_BILINEAR;
- if (args) {
- sscanf(args, "%255[^:]:%255[^:]", scale->w_expr, scale->h_expr);
- p = strstr(args,"flags=");
- if (p) {
- const AVClass *class = sws_get_class();
- const AVOption *o = av_opt_find(&class, "sws_flags", NULL, 0,
- AV_OPT_SEARCH_FAKE_OBJ);
- int ret = av_opt_eval_flags(&class, o, p + 6, &scale->flags);
-
- if (ret < 0)
- return ret;
- }
+
+ if (scale->flags_str) {
+ const AVClass *class = sws_get_class();
+ const AVOption *o = av_opt_find(&class, "sws_flags", NULL, 0,
+ AV_OPT_SEARCH_FAKE_OBJ);
+ int ret = av_opt_eval_flags(&class, o, scale->flags_str, &scale->flags);
+
+ if (ret < 0)
+ return ret;
}
return 0;
@@ -292,6 +285,22 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
return ff_filter_frame(outlink, out);
}
+#define OFFSET(x) offsetof(ScaleContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption options[] = {
+ { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
+ { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
+ { "flags", "Flags to pass to libswscale", OFFSET(flags_str), AV_OPT_TYPE_STRING, { .str = "bilinear" }, .flags = FLAGS },
+ { NULL },
+};
+
+static const AVClass scale_class = {
+ .class_name = "scale",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
static const AVFilterPad avfilter_vf_scale_inputs[] = {
{
.name = "default",
@@ -320,6 +329,7 @@ AVFilter avfilter_vf_scale = {
.query_formats = query_formats,
.priv_size = sizeof(ScaleContext),
+ .priv_class = &scale_class,
.inputs = avfilter_vf_scale_inputs,
.outputs = avfilter_vf_scale_outputs,