With this all AVOptions from swscale can be set without each needing
changes to vf_scale.c
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -6403,6 +6403,23 @@ Set full range (0-255 in case of 8-bit luma). |
6403 | 6403 |
Set "MPEG" range (16-235 in case of 8-bit luma). |
6404 | 6404 |
@end table |
6405 | 6405 |
|
6406 |
+@item sws_dither |
|
6407 |
+Set the dithering algorithm |
|
6408 |
+ |
|
6409 |
+@table @samp |
|
6410 |
+@item auto |
|
6411 |
+Choose automatically. |
|
6412 |
+ |
|
6413 |
+@item none |
|
6414 |
+No dithering |
|
6415 |
+ |
|
6416 |
+@item bayer |
|
6417 |
+bayer dither |
|
6418 |
+ |
|
6419 |
+@item ed |
|
6420 |
+error diffusion dither |
|
6421 |
+@end table |
|
6422 |
+ |
|
6406 | 6423 |
@item force_original_aspect_ratio |
6407 | 6424 |
Enable decreasing or increasing output video width or height if necessary to |
6408 | 6425 |
keep the original aspect ratio. Possible values: |
... | ... |
@@ -71,6 +71,7 @@ typedef struct { |
71 | 71 |
const AVClass *class; |
72 | 72 |
struct SwsContext *sws; ///< software scaler context |
73 | 73 |
struct SwsContext *isws[2]; ///< software scaler context for interlaced material |
74 |
+ AVDictionary *opts; |
|
74 | 75 |
|
75 | 76 |
/** |
76 | 77 |
* New dimensions. Special values are: |
... | ... |
@@ -105,7 +106,7 @@ typedef struct { |
105 | 105 |
int force_original_aspect_ratio; |
106 | 106 |
} ScaleContext; |
107 | 107 |
|
108 |
-static av_cold int init(AVFilterContext *ctx) |
|
108 |
+static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts) |
|
109 | 109 |
{ |
110 | 110 |
ScaleContext *scale = ctx->priv; |
111 | 111 |
int ret; |
... | ... |
@@ -149,6 +150,8 @@ static av_cold int init(AVFilterContext *ctx) |
149 | 149 |
if (ret < 0) |
150 | 150 |
return ret; |
151 | 151 |
} |
152 |
+ scale->opts = *opts; |
|
153 |
+ *opts = NULL; |
|
152 | 154 |
|
153 | 155 |
return 0; |
154 | 156 |
} |
... | ... |
@@ -160,6 +163,7 @@ static av_cold void uninit(AVFilterContext *ctx) |
160 | 160 |
sws_freeContext(scale->isws[0]); |
161 | 161 |
sws_freeContext(scale->isws[1]); |
162 | 162 |
scale->sws = NULL; |
163 |
+ av_dict_free(&scale->opts); |
|
163 | 164 |
} |
164 | 165 |
|
165 | 166 |
static int query_formats(AVFilterContext *ctx) |
... | ... |
@@ -325,6 +329,17 @@ static int config_props(AVFilterLink *outlink) |
325 | 325 |
if (!*s) |
326 | 326 |
return AVERROR(ENOMEM); |
327 | 327 |
|
328 |
+ if (scale->opts) { |
|
329 |
+ AVDictionaryEntry *e = NULL; |
|
330 |
+ |
|
331 |
+ while ((e = av_dict_get(scale->opts, "", e, AV_DICT_IGNORE_SUFFIX))) { |
|
332 |
+ const char *token = e->key; |
|
333 |
+ const char *value = e->value; |
|
334 |
+ if ((ret = av_opt_set(*s, token, value, 0)) < 0) |
|
335 |
+ return ret; |
|
336 |
+ } |
|
337 |
+ } |
|
338 |
+ |
|
328 | 339 |
av_opt_set_int(*s, "srcw", inlink ->w, 0); |
329 | 340 |
av_opt_set_int(*s, "srch", inlink ->h >> !!i, 0); |
330 | 341 |
av_opt_set_int(*s, "src_format", inlink->format, 0); |
... | ... |
@@ -490,6 +505,11 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) |
490 | 490 |
return ff_filter_frame(outlink, out); |
491 | 491 |
} |
492 | 492 |
|
493 |
+static const AVClass *child_class_next(const AVClass *prev) |
|
494 |
+{ |
|
495 |
+ return prev ? NULL : sws_get_class(); |
|
496 |
+} |
|
497 |
+ |
|
493 | 498 |
#define OFFSET(x) offsetof(ScaleContext, x) |
494 | 499 |
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM |
495 | 500 |
|
... | ... |
@@ -523,7 +543,13 @@ static const AVOption scale_options[] = { |
523 | 523 |
{ NULL }, |
524 | 524 |
}; |
525 | 525 |
|
526 |
-AVFILTER_DEFINE_CLASS(scale); |
|
526 |
+static const AVClass scale_class = { |
|
527 |
+ .class_name = "scale", |
|
528 |
+ .item_name = av_default_item_name, |
|
529 |
+ .option = scale_options, |
|
530 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
531 |
+ .child_class_next = child_class_next, |
|
532 |
+}; |
|
527 | 533 |
|
528 | 534 |
static const AVFilterPad avfilter_vf_scale_inputs[] = { |
529 | 535 |
{ |
... | ... |
@@ -547,7 +573,7 @@ AVFilter avfilter_vf_scale = { |
547 | 547 |
.name = "scale", |
548 | 548 |
.description = NULL_IF_CONFIG_SMALL("Scale the input video to width:height size and/or convert the image format."), |
549 | 549 |
|
550 |
- .init = init, |
|
550 |
+ .init_dict = init_dict, |
|
551 | 551 |
.uninit = uninit, |
552 | 552 |
|
553 | 553 |
.query_formats = query_formats, |