aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_aspect.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-01-24 23:20:23 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-10-22 10:46:34 +0200
commitccd6def9b3dcdb97a18710e6fd13f35498589849 (patch)
tree23c74ce9cff36e9b2c7a7f27a51d7416d17d633d /libavfilter/vf_aspect.c
parentb6e36a424447413d959753f6e703f35bcfb8cd7b (diff)
downloadffmpeg-ccd6def9b3dcdb97a18710e6fd13f35498589849.tar.gz
lavfi/aspect: extend syntax for the setdar and setsar filters
Add support for named options, and deprecate old "num:den" ambiguous syntax.
Diffstat (limited to 'libavfilter/vf_aspect.c')
-rw-r--r--libavfilter/vf_aspect.c73
1 files changed, 65 insertions, 8 deletions
diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c
index 4e5ba77b39..041691a84e 100644
--- a/libavfilter/vf_aspect.c
+++ b/libavfilter/vf_aspect.c
@@ -24,6 +24,7 @@
*/
#include "libavutil/common.h"
+#include "libavutil/opt.h"
#include "libavutil/mathematics.h"
#include "libavutil/parseutils.h"
#include "avfilter.h"
@@ -31,19 +32,44 @@
#include "video.h"
typedef struct {
+ const AVClass *class;
AVRational ratio;
+ char *ratio_str;
} 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;
- aspect->ratio = (AVRational) {0, 1};
+ static const char *shorthand[] = { "ratio", NULL };
+ char c;
+ int ret;
+ AVRational q;
+
+ aspect->class = class;
+ av_opt_set_defaults(aspect);
+
+ 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 (args) {
- if (av_parse_ratio(&aspect->ratio, args, 100, 0, ctx) < 0 ||
- aspect->ratio.num < 0 || aspect->ratio.den <= 0) {
+ 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,
- "Invalid string '%s' for aspect ratio.\n", args);
+ "Invalid string '%s' for aspect ratio\n", args);
return AVERROR(EINVAL);
}
}
@@ -61,7 +87,23 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *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
+
+#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)
{
AspectContext *aspect = inlink->dst->priv;
@@ -103,17 +145,29 @@ AVFilter avfilter_vf_setdar = {
.name = "setdar",
.description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."),
- .init = init,
+ .init = setdar_init,
+ .uninit = uninit,
.priv_size = sizeof(AspectContext),
.inputs = avfilter_vf_setdar_inputs,
.outputs = avfilter_vf_setdar_outputs,
+ .priv_class = &setdar_class,
};
+
#endif /* CONFIG_SETDAR_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)
{
AspectContext *aspect = inlink->dst->priv;
@@ -147,12 +201,15 @@ AVFilter avfilter_vf_setsar = {
.name = "setsar",
.description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
- .init = init,
+ .init = setsar_init,
+ .uninit = uninit,
.priv_size = sizeof(AspectContext),
.inputs = avfilter_vf_setsar_inputs,
.outputs = avfilter_vf_setsar_outputs,
+ .priv_class = &setdar_class,
};
+
#endif /* CONFIG_SETSAR_FILTER */