Re: [FFmpeg-devel] [PATCH] avfilter: add setrange filter

2017-12-06 Thread Paul B Mahol
On 12/3/17, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi   | 31 ++
>  libavfilter/Makefile   |  1 +
>  libavfilter/allfilters.c   |  1 +
>  libavfilter/vf_setparams.c | 82
> ++
>  4 files changed, 115 insertions(+)
>  create mode 100644 libavfilter/vf_setparams.c
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index f7c371592f..718263a608 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -18496,6 +18496,37 @@ asetpts=N/SR/TB
>
>  @end itemize
>
> +@section setrange
> +
> +Force color range for the output video frame.
> +
> +The @code{setrange} filter marks the color range property for the
> +output frames. It does not change the input frame, but only sets the
> +corresponding property, which affects how the frame is treated by
> +following filters.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +
> +@item range
> +Available values are:
> +
> +@table @samp
> +@item auto
> +Keep the same color range property.
> +
> +@item unspecified, unknown
> +Set the color range as unspecified.
> +
> +@item limited, tv, mpeg
> +Set the color range as limited.
> +
> +@item full, pc, jpeg
> +Set the color range as full.
> +@end table
> +@end table
> +
>  @section settb, asettb
>
>  Set the timebase to use for the output frames timestamps.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 1c0cc1da80..6b06d57234 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -300,6 +300,7 @@ OBJS-$(CONFIG_SEPARATEFIELDS_FILTER) +=
> vf_separatefields.o
>  OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o
>  OBJS-$(CONFIG_SETFIELD_FILTER)   += vf_setfield.o
>  OBJS-$(CONFIG_SETPTS_FILTER) += setpts.o
> +OBJS-$(CONFIG_SETRANGE_FILTER)   += vf_setparams.o
>  OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o
>  OBJS-$(CONFIG_SETTB_FILTER)  += settb.o
>  OBJS-$(CONFIG_SHOWINFO_FILTER)   += vf_showinfo.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index fc212e58db..707faad777 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -309,6 +309,7 @@ static void register_all(void)
>  REGISTER_FILTER(SETDAR, setdar, vf);
>  REGISTER_FILTER(SETFIELD,   setfield,   vf);
>  REGISTER_FILTER(SETPTS, setpts, vf);
> +REGISTER_FILTER(SETRANGE,   setrange,   vf);
>  REGISTER_FILTER(SETSAR, setsar, vf);
>  REGISTER_FILTER(SETTB,  settb,  vf);
>  REGISTER_FILTER(SHOWINFO,   showinfo,   vf);
> diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c
> new file mode 100644
> index 00..7668bd4cdf
> --- /dev/null
> +++ b/libavfilter/vf_setparams.c
> @@ -0,0 +1,82 @@
> +/*
> + * 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_CO

[FFmpeg-devel] [PATCH] avfilter: add setrange filter

2017-12-03 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi   | 31 ++
 libavfilter/Makefile   |  1 +
 libavfilter/allfilters.c   |  1 +
 libavfilter/vf_setparams.c | 82 ++
 4 files changed, 115 insertions(+)
 create mode 100644 libavfilter/vf_setparams.c

diff --git a/doc/filters.texi b/doc/filters.texi
index f7c371592f..718263a608 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18496,6 +18496,37 @@ asetpts=N/SR/TB
 
 @end itemize
 
+@section setrange
+
+Force color range for the output video frame.
+
+The @code{setrange} filter marks the color range property for the
+output frames. It does not change the input frame, but only sets the
+corresponding property, which affects how the frame is treated by
+following filters.
+
+The filter accepts the following options:
+
+@table @option
+
+@item range
+Available values are:
+
+@table @samp
+@item auto
+Keep the same color range property.
+
+@item unspecified, unknown
+Set the color range as unspecified.
+
+@item limited, tv, mpeg
+Set the color range as limited.
+
+@item full, pc, jpeg
+Set the color range as full.
+@end table
+@end table
+
 @section settb, asettb
 
 Set the timebase to use for the output frames timestamps.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1c0cc1da80..6b06d57234 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -300,6 +300,7 @@ OBJS-$(CONFIG_SEPARATEFIELDS_FILTER) += 
vf_separatefields.o
 OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o
 OBJS-$(CONFIG_SETFIELD_FILTER)   += vf_setfield.o
 OBJS-$(CONFIG_SETPTS_FILTER) += setpts.o
+OBJS-$(CONFIG_SETRANGE_FILTER)   += vf_setparams.o
 OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o
 OBJS-$(CONFIG_SETTB_FILTER)  += settb.o
 OBJS-$(CONFIG_SHOWINFO_FILTER)   += vf_showinfo.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index fc212e58db..707faad777 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -309,6 +309,7 @@ static void register_all(void)
 REGISTER_FILTER(SETDAR, setdar, vf);
 REGISTER_FILTER(SETFIELD,   setfield,   vf);
 REGISTER_FILTER(SETPTS, setpts, vf);
+REGISTER_FILTER(SETRANGE,   setrange,   vf);
 REGISTER_FILTER(SETSAR, setsar, vf);
 REGISTER_FILTER(SETTB,  settb,  vf);
 REGISTER_FILTER(SHOWINFO,   showinfo,   vf);
diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c
new file mode 100644
index 00..7668bd4cdf
--- /dev/null
+++ b/libavfilter/vf_setparams.c
@@ -0,0 +1,82 @@
+/*
+ * 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}