Merge commit 'c334c113d4d9e9a41bc38a3e4458d7ab21010401'

* commit 'c334c113d4d9e9a41bc38a3e4458d7ab21010401':
  vf_scale: switch to an AVOptions-based system.

Conflicts:
	doc/filters.texi
	libavfilter/avfilter.c
	libavfilter/vf_scale.c

scale keeps using our shorthand system due to the alternative not
supporting the more complex syntactical things like 1 parameter
dimensions

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-04-10 20:29:25 +02:00
commit 85f115b5d8
3 changed files with 67 additions and 34 deletions

View File

@ -4833,11 +4833,13 @@ A description of the accepted options follows.
@table @option
@item width, w
Set the video width expression, default value is @code{iw}. See below
Output video width.
default value is @code{iw}. See below
for the list of accepted constants.
@item height, h
Set the video heiht expression, default value is @code{ih}.
Output video height.
default value is @code{ih}.
See below for the list of accepted constants.
@item interl
@ -4900,12 +4902,12 @@ If the input image format is different from the format requested by
the next filter, the scale filter will convert the input to the
requested format.
If the value for @var{width} or @var{height} is 0, the respective input
If the value for @var{w} or @var{h} is 0, the respective input
size is used for the output.
If the value for @var{width} or @var{height} is -1, the scale filter will
use, for the respective output size, a value that maintains the aspect
ratio of the input image.
If the value for @var{w} or @var{h} is -1, the scale filter will use, for the
respective output size, a value that maintains the aspect ratio of the input
image.
@subsection Examples
@ -4913,7 +4915,7 @@ ratio of the input image.
@item
Scale the input video to a size of 200x100:
@example
scale=200:100
scale=w=200:h=100
@end example
This is equivalent to:
@ -4940,7 +4942,7 @@ scale=size=qcif
@item
Scale the input to 2x:
@example
scale=2*iw:2*ih
scale=w=2*iw:h=2*ih
@end example
@item
@ -4958,7 +4960,7 @@ scale=2*iw:2*ih:interl=1
@item
Scale the input to half size:
@example
scale=iw/2:ih/2
scale=w=iw/2:h=ih/2
@end example
@item
@ -4977,7 +4979,7 @@ scale=ih*PHI:ih
@item
Increase the height, and set the width to 3/2 of the height:
@example
scale=3/2*oh:3/5*ih
scale=w=3/2*oh:h=3/5*ih
@end example
@item
@ -4991,7 +4993,7 @@ scale="trunc(3/2*iw/hsub)*hsub:trunc(3/2*ih/vsub)*vsub"
Increase the width to a maximum of 500 pixels, keep the same input
aspect ratio:
@example
scale='min(500\, iw*3/2):-1'
scale=w='min(500\, iw*3/2):h=-1'
@end example
@end itemize

View File

@ -671,7 +671,9 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
!strcmp(filter->filter->name, "frei0r_src") ||
!strcmp(filter->filter->name, "format") ||
!strcmp(filter->filter->name, "noformat") ||
!strcmp(filter->filter->name, "resample")
!strcmp(filter->filter->name, "resample") ||
// !strcmp(filter->filter->name, "scale" ) ||
0
;
if (filter->filter->shorthand) {
@ -687,6 +689,36 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
}
if (anton_options && 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);

View File

@ -78,7 +78,6 @@ typedef struct {
* -1 = keep original aspect
*/
int w, h;
char *flags_str; ///sws flags string
char *size_str;
unsigned int flags; ///sws flags
@ -90,35 +89,17 @@ typedef struct {
char *w_expr; ///< width expression string
char *h_expr; ///< height expression string
char *flags_str;
} ScaleContext;
#define OFFSET(x) offsetof(ScaleContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption scale_options[] = {
{ "w", "set width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "width", "set width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "h", "set height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "height", "set height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "flags", "set libswscale flags", OFFSET(flags_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, INT_MAX, FLAGS },
{ "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_INT, {.i64 = 0 }, -1, 1, FLAGS },
{ "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
{ "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
{ NULL },
};
AVFILTER_DEFINE_CLASS(scale);
static av_cold int init(AVFilterContext *ctx, const char *args)
{
ScaleContext *scale = ctx->priv;
#if 1
static const char *shorthand[] = { "w", "h", NULL };
int ret;
const char *args0 = args;
scale->class = &scale_class;
av_opt_set_defaults(scale);
if (args && (scale->size_str = av_get_token(&args, ":"))) {
if (av_parse_video_size(&scale->w, &scale->h, scale->size_str) < 0) {
av_freep(&scale->size_str);
@ -157,6 +138,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
scale->w_expr, scale->h_expr, (char *)av_x_if_null(scale->flags_str, ""), scale->interlaced);
scale->flags = SWS_BILINEAR;
#endif
if (scale->flags_str) {
const AVClass *class = sws_get_class();
const AVOption *o = av_opt_find(&class, "sws_flags", NULL, 0,
@ -413,6 +395,23 @@ 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|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption scale_options[] = {
{ "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
{ "width", "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 },
{ "height","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 },
{ "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_INT, {.i64 = 0 }, -1, 1, FLAGS },
{ "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
{ "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
{ NULL },
};
AVFILTER_DEFINE_CLASS(scale);
static const AVFilterPad avfilter_vf_scale_inputs[] = {
{
.name = "default",
@ -441,8 +440,8 @@ 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,
.priv_class = &scale_class,
};