Commit 6d246f44 authored by Michael Niedermayer's avatar Michael Niedermayer

avfilter/vf_scale: generic swscale option support

With this all AVOptions from swscale can be set without each needing
changes to vf_scale.c
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 1e0e1932
...@@ -6403,6 +6403,23 @@ Set full range (0-255 in case of 8-bit luma). ...@@ -6403,6 +6403,23 @@ Set full range (0-255 in case of 8-bit luma).
Set "MPEG" range (16-235 in case of 8-bit luma). Set "MPEG" range (16-235 in case of 8-bit luma).
@end table @end table
@item sws_dither
Set the dithering algorithm
@table @samp
@item auto
Choose automatically.
@item none
No dithering
@item bayer
bayer dither
@item ed
error diffusion dither
@end table
@item force_original_aspect_ratio @item force_original_aspect_ratio
Enable decreasing or increasing output video width or height if necessary to Enable decreasing or increasing output video width or height if necessary to
keep the original aspect ratio. Possible values: keep the original aspect ratio. Possible values:
......
...@@ -71,6 +71,7 @@ typedef struct { ...@@ -71,6 +71,7 @@ typedef struct {
const AVClass *class; const AVClass *class;
struct SwsContext *sws; ///< software scaler context struct SwsContext *sws; ///< software scaler context
struct SwsContext *isws[2]; ///< software scaler context for interlaced material struct SwsContext *isws[2]; ///< software scaler context for interlaced material
AVDictionary *opts;
/** /**
* New dimensions. Special values are: * New dimensions. Special values are:
...@@ -105,7 +106,7 @@ typedef struct { ...@@ -105,7 +106,7 @@ typedef struct {
int force_original_aspect_ratio; int force_original_aspect_ratio;
} ScaleContext; } ScaleContext;
static av_cold int init(AVFilterContext *ctx) static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
{ {
ScaleContext *scale = ctx->priv; ScaleContext *scale = ctx->priv;
int ret; int ret;
...@@ -149,6 +150,8 @@ static av_cold int init(AVFilterContext *ctx) ...@@ -149,6 +150,8 @@ static av_cold int init(AVFilterContext *ctx)
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
scale->opts = *opts;
*opts = NULL;
return 0; return 0;
} }
...@@ -160,6 +163,7 @@ static av_cold void uninit(AVFilterContext *ctx) ...@@ -160,6 +163,7 @@ static av_cold void uninit(AVFilterContext *ctx)
sws_freeContext(scale->isws[0]); sws_freeContext(scale->isws[0]);
sws_freeContext(scale->isws[1]); sws_freeContext(scale->isws[1]);
scale->sws = NULL; scale->sws = NULL;
av_dict_free(&scale->opts);
} }
static int query_formats(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx)
...@@ -325,6 +329,17 @@ static int config_props(AVFilterLink *outlink) ...@@ -325,6 +329,17 @@ static int config_props(AVFilterLink *outlink)
if (!*s) if (!*s)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if (scale->opts) {
AVDictionaryEntry *e = NULL;
while ((e = av_dict_get(scale->opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
const char *token = e->key;
const char *value = e->value;
if ((ret = av_opt_set(*s, token, value, 0)) < 0)
return ret;
}
}
av_opt_set_int(*s, "srcw", inlink ->w, 0); av_opt_set_int(*s, "srcw", inlink ->w, 0);
av_opt_set_int(*s, "srch", inlink ->h >> !!i, 0); av_opt_set_int(*s, "srch", inlink ->h >> !!i, 0);
av_opt_set_int(*s, "src_format", inlink->format, 0); av_opt_set_int(*s, "src_format", inlink->format, 0);
...@@ -490,6 +505,11 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) ...@@ -490,6 +505,11 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
return ff_filter_frame(outlink, out); return ff_filter_frame(outlink, out);
} }
static const AVClass *child_class_next(const AVClass *prev)
{
return prev ? NULL : sws_get_class();
}
#define OFFSET(x) offsetof(ScaleContext, x) #define OFFSET(x) offsetof(ScaleContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
...@@ -523,7 +543,13 @@ static const AVOption scale_options[] = { ...@@ -523,7 +543,13 @@ static const AVOption scale_options[] = {
{ NULL }, { NULL },
}; };
AVFILTER_DEFINE_CLASS(scale); static const AVClass scale_class = {
.class_name = "scale",
.item_name = av_default_item_name,
.option = scale_options,
.version = LIBAVUTIL_VERSION_INT,
.child_class_next = child_class_next,
};
static const AVFilterPad avfilter_vf_scale_inputs[] = { static const AVFilterPad avfilter_vf_scale_inputs[] = {
{ {
...@@ -547,7 +573,7 @@ AVFilter avfilter_vf_scale = { ...@@ -547,7 +573,7 @@ AVFilter avfilter_vf_scale = {
.name = "scale", .name = "scale",
.description = NULL_IF_CONFIG_SMALL("Scale the input video to width:height size and/or convert the image format."), .description = NULL_IF_CONFIG_SMALL("Scale the input video to width:height size and/or convert the image format."),
.init = init, .init_dict = init_dict,
.uninit = uninit, .uninit = uninit,
.query_formats = query_formats, .query_formats = query_formats,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment