lavfi/aspect: extend syntax for the setdar and setsar filters
Add support for named options, and deprecate old "num:den" ambiguous syntax.
This commit is contained in:
parent
b6e36a4244
commit
ccd6def9b3
@ -3250,16 +3250,27 @@ Keep in mind that the sample aspect ratio set by the @code{setsar}
|
|||||||
filter may be changed by later filters in the filterchain, e.g. if
|
filter may be changed by later filters in the filterchain, e.g. if
|
||||||
another "setsar" or a "setdar" filter is applied.
|
another "setsar" or a "setdar" filter is applied.
|
||||||
|
|
||||||
The @code{setdar} and @code{setsar} filters accept a parameter string
|
The @code{setdar} and @code{setsar} filters accept a string in the
|
||||||
which represents the wanted aspect ratio. The parameter can
|
form @var{num}:@var{den} expressing an aspect ratio, or the following
|
||||||
be a floating point number string, an expression, or a string of the form
|
named options, expressed as a sequence of @var{key}=@var{value} pairs,
|
||||||
@var{num}:@var{den}, where @var{num} and @var{den} are the numerator
|
separated by ":".
|
||||||
and denominator of the aspect ratio. If the parameter is not
|
|
||||||
specified, it is assumed the value "0:1".
|
@table @option
|
||||||
|
|
||||||
|
@item r, ratio:
|
||||||
|
Set the aspect ratio used by the filter.
|
||||||
|
|
||||||
|
The parameter can be a floating point number string, an expression, or
|
||||||
|
a string of the form @var{num}:@var{den}, where @var{num} and
|
||||||
|
@var{den} are the numerator and denominator of the aspect ratio. If
|
||||||
|
the parameter is not specified, it is assumed the value "0".
|
||||||
|
In case the form "@var{num}:@var{den}" the @code{:} character should
|
||||||
|
be escaped.
|
||||||
|
@end table
|
||||||
|
|
||||||
For example to change the display aspect ratio to 16:9, specify:
|
For example to change the display aspect ratio to 16:9, specify:
|
||||||
@example
|
@example
|
||||||
setdar=16:9
|
setdar='16:9'
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
The example above is equivalent to:
|
The example above is equivalent to:
|
||||||
@ -3269,7 +3280,7 @@ setdar=1.77777
|
|||||||
|
|
||||||
To change the sample aspect ratio to 10:11, specify:
|
To change the sample aspect ratio to 10:11, specify:
|
||||||
@example
|
@example
|
||||||
setsar=10:11
|
setsar='10:11'
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@section setfield
|
@section setfield
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#define LIBAVFILTER_VERSION_MAJOR 3
|
#define LIBAVFILTER_VERSION_MAJOR 3
|
||||||
#define LIBAVFILTER_VERSION_MINOR 20
|
#define LIBAVFILTER_VERSION_MINOR 20
|
||||||
#define LIBAVFILTER_VERSION_MICRO 102
|
#define LIBAVFILTER_VERSION_MICRO 103
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
||||||
LIBAVFILTER_VERSION_MINOR, \
|
LIBAVFILTER_VERSION_MINOR, \
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libavutil/common.h"
|
#include "libavutil/common.h"
|
||||||
|
#include "libavutil/opt.h"
|
||||||
#include "libavutil/mathematics.h"
|
#include "libavutil/mathematics.h"
|
||||||
#include "libavutil/parseutils.h"
|
#include "libavutil/parseutils.h"
|
||||||
#include "avfilter.h"
|
#include "avfilter.h"
|
||||||
@ -31,19 +32,44 @@
|
|||||||
#include "video.h"
|
#include "video.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
const AVClass *class;
|
||||||
AVRational ratio;
|
AVRational ratio;
|
||||||
|
char *ratio_str;
|
||||||
} AspectContext;
|
} AspectContext;
|
||||||
|
|
||||||
static av_cold int init(AVFilterContext *ctx, const char *args)
|
#define OFFSET(x) offsetof(AspectContext, x)
|
||||||
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
||||||
|
|
||||||
|
static const AVOption options[] = {
|
||||||
|
{"ratio", "set ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
|
||||||
|
{"r", "set ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
|
||||||
|
{NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static av_cold int init(AVFilterContext *ctx, const char *args, const AVClass *class)
|
||||||
{
|
{
|
||||||
AspectContext *aspect = ctx->priv;
|
AspectContext *aspect = ctx->priv;
|
||||||
aspect->ratio = (AVRational) {0, 1};
|
static const char *shorthand[] = { "ratio", NULL };
|
||||||
|
char c;
|
||||||
|
int ret;
|
||||||
|
AVRational q;
|
||||||
|
|
||||||
if (args) {
|
aspect->class = class;
|
||||||
if (av_parse_ratio(&aspect->ratio, args, 100, 0, ctx) < 0 ||
|
av_opt_set_defaults(aspect);
|
||||||
aspect->ratio.num < 0 || aspect->ratio.den <= 0) {
|
|
||||||
|
if (sscanf(args, "%d:%d%c", &q.num, &q.den, &c) == 2) {
|
||||||
|
aspect->ratio_str = av_strdup(args);
|
||||||
|
av_log(ctx, AV_LOG_WARNING,
|
||||||
|
"num:den syntax is deprecated, please use num/den or named options instead\n");
|
||||||
|
} else if ((ret = av_opt_set_from_string(aspect, args, shorthand, "=", ":")) < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aspect->ratio_str) {
|
||||||
|
ret = av_parse_ratio(&aspect->ratio, aspect->ratio_str, 100, 0, ctx);
|
||||||
|
if (ret < 0 || aspect->ratio.num < 0 || aspect->ratio.den <= 0) {
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"Invalid string '%s' for aspect ratio.\n", args);
|
"Invalid string '%s' for aspect ratio\n", args);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +87,23 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
|
|||||||
return ff_start_frame(link->dst->outputs[0], picref);
|
return ff_start_frame(link->dst->outputs[0], picref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static av_cold void uninit(AVFilterContext *ctx)
|
||||||
|
{
|
||||||
|
AspectContext *aspect = ctx->priv;
|
||||||
|
|
||||||
|
av_opt_free(aspect);
|
||||||
|
}
|
||||||
|
|
||||||
#if CONFIG_SETDAR_FILTER
|
#if CONFIG_SETDAR_FILTER
|
||||||
|
|
||||||
|
#define setdar_options options
|
||||||
|
AVFILTER_DEFINE_CLASS(setdar);
|
||||||
|
|
||||||
|
static av_cold int setdar_init(AVFilterContext *ctx, const char *args)
|
||||||
|
{
|
||||||
|
return init(ctx, args, &setdar_class);
|
||||||
|
}
|
||||||
|
|
||||||
static int setdar_config_props(AVFilterLink *inlink)
|
static int setdar_config_props(AVFilterLink *inlink)
|
||||||
{
|
{
|
||||||
AspectContext *aspect = inlink->dst->priv;
|
AspectContext *aspect = inlink->dst->priv;
|
||||||
@ -103,17 +145,29 @@ AVFilter avfilter_vf_setdar = {
|
|||||||
.name = "setdar",
|
.name = "setdar",
|
||||||
.description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."),
|
.description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."),
|
||||||
|
|
||||||
.init = init,
|
.init = setdar_init,
|
||||||
|
.uninit = uninit,
|
||||||
|
|
||||||
.priv_size = sizeof(AspectContext),
|
.priv_size = sizeof(AspectContext),
|
||||||
|
|
||||||
.inputs = avfilter_vf_setdar_inputs,
|
.inputs = avfilter_vf_setdar_inputs,
|
||||||
|
|
||||||
.outputs = avfilter_vf_setdar_outputs,
|
.outputs = avfilter_vf_setdar_outputs,
|
||||||
|
.priv_class = &setdar_class,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_SETDAR_FILTER */
|
#endif /* CONFIG_SETDAR_FILTER */
|
||||||
|
|
||||||
#if CONFIG_SETSAR_FILTER
|
#if CONFIG_SETSAR_FILTER
|
||||||
|
|
||||||
|
#define setsar_options options
|
||||||
|
AVFILTER_DEFINE_CLASS(setsar);
|
||||||
|
|
||||||
|
static av_cold int setsar_init(AVFilterContext *ctx, const char *args)
|
||||||
|
{
|
||||||
|
return init(ctx, args, &setsar_class);
|
||||||
|
}
|
||||||
|
|
||||||
static int setsar_config_props(AVFilterLink *inlink)
|
static int setsar_config_props(AVFilterLink *inlink)
|
||||||
{
|
{
|
||||||
AspectContext *aspect = inlink->dst->priv;
|
AspectContext *aspect = inlink->dst->priv;
|
||||||
@ -147,12 +201,15 @@ AVFilter avfilter_vf_setsar = {
|
|||||||
.name = "setsar",
|
.name = "setsar",
|
||||||
.description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
|
.description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
|
||||||
|
|
||||||
.init = init,
|
.init = setsar_init,
|
||||||
|
.uninit = uninit,
|
||||||
|
|
||||||
.priv_size = sizeof(AspectContext),
|
.priv_size = sizeof(AspectContext),
|
||||||
|
|
||||||
.inputs = avfilter_vf_setsar_inputs,
|
.inputs = avfilter_vf_setsar_inputs,
|
||||||
|
|
||||||
.outputs = avfilter_vf_setsar_outputs,
|
.outputs = avfilter_vf_setsar_outputs,
|
||||||
|
.priv_class = &setdar_class,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_SETSAR_FILTER */
|
#endif /* CONFIG_SETSAR_FILTER */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user