summaryrefslogtreecommitdiff
path: root/libavfilter/vf_setparams.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2017-12-03 11:59:58 +0100
committerPaul B Mahol <onemda@gmail.com>2017-12-06 15:42:23 +0100
commit53855e3c040a4a7315f137682a6285729ceddc8e (patch)
tree1d3c1a2119a794c479ee4765894767dbc3b649d4 /libavfilter/vf_setparams.c
parentc8bd2c7d09bfc71795e91f0a9aeb4b8a6833eff2 (diff)
avfilter: add setrange filter
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vf_setparams.c')
-rw-r--r--libavfilter/vf_setparams.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c
new file mode 100644
index 0000000000..8427f98ba8
--- /dev/null
+++ b/libavfilter/vf_setparams.c
@@ -0,0 +1,83 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/pixfmt.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct SetParamsContext {
+ const AVClass *class;
+ int color_range;
+} SetParamsContext;
+
+#define OFFSET(x) offsetof(SetParamsContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption setrange_options[] = {
+ {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1},-1, AVCOL_RANGE_NB-1, FLAGS, "range"},
+ {"auto", "keep the same color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, "range"},
+ {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
+ {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
+ {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
+ {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
+ {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
+ {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
+ {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
+ {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
+ {NULL}
+};
+
+AVFILTER_DEFINE_CLASS(setrange);
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
+{
+ AVFilterContext *ctx = inlink->dst;
+ SetParamsContext *s = ctx->priv;
+
+ if (s->color_range >= 0)
+ frame->color_range = s->color_range;
+ return ff_filter_frame(ctx->outputs[0], frame);
+}
+
+static const AVFilterPad inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .filter_frame = filter_frame,
+ },
+ { NULL }
+};
+
+static const AVFilterPad outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ },
+ { NULL }
+};
+
+AVFilter ff_vf_setrange = {
+ .name = "setrange",
+ .description = NULL_IF_CONFIG_SMALL("Force color range for the output video frame."),
+ .priv_size = sizeof(SetParamsContext),
+ .priv_class = &setrange_class,
+ .inputs = inputs,
+ .outputs = outputs,
+};