diff mbox series

[FFmpeg-devel,2/6] avfilter/vf_setparams: allow setting chroma location

Message ID 20240704115202.1235954-2-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,1/6] swscale: document SWS_FULL_CHR_H_* flags | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas July 4, 2024, 11:51 a.m. UTC
From: Niklas Haas <git@haasn.dev>

Shockingly, there isn't currently _any_ filter for overriding this.
---
 doc/filters.texi           | 17 +++++++++++++++++
 libavfilter/vf_setparams.c | 19 ++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)

Comments

Paul B Mahol July 4, 2024, 3:09 p.m. UTC | #1
On Thu, Jul 4, 2024 at 1:54 PM Niklas Haas <ffmpeg@haasn.xyz> wrote:

> From: Niklas Haas <git@haasn.dev>
>
> Shockingly, there isn't currently _any_ filter for overriding this.
> ---
>  doc/filters.texi           | 17 +++++++++++++++++
>  libavfilter/vf_setparams.c | 19 ++++++++++++++++---
>  2 files changed, 33 insertions(+), 3 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index c9c4f7cf6b..ca8f6e461a 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -22073,6 +22073,23 @@ Keep the same colorspace property (default).
>  @item chroma-derived-c
>  @item ictcp
>  @end table
> +
> +@item chroma_location
> +Set the chroma sample location.
> +Available values are:
> +
> +@table @samp
> +@item auto
> +Keep the same chroma location (default).
> +
> +@item unspecified, unknown
> +@item left
> +@item center
> +@item topleft
> +@item top
> +@item bottomleft
> +@item bottom
> +@end table
>  @end table
>
>  @section sharpen_npp
> diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c
> index b7da8eb54b..ba32a6699c 100644
> --- a/libavfilter/vf_setparams.c
> +++ b/libavfilter/vf_setparams.c
> @@ -41,6 +41,7 @@ typedef struct SetParamsContext {
>      int color_primaries;
>      int color_trc;
>      int colorspace;
> +    int chroma_location;
>  } SetParamsContext;
>
>  #define OFFSET(x) offsetof(SetParamsContext, x)
> @@ -119,6 +120,17 @@ static const AVOption setparams_options[] = {
>      {"chroma-derived-c",           NULL,  0, AV_OPT_TYPE_CONST,
> {.i64=AVCOL_SPC_CHROMA_DERIVED_CL}, INT_MIN, INT_MAX, FLAGS, .unit =
> "colorspace"},
>      {"ictcp",                      NULL,  0, AV_OPT_TYPE_CONST,
> {.i64=AVCOL_SPC_ICTCP},             INT_MIN, INT_MAX, FLAGS, .unit =
> "colorspace"},
>      {"ipt-c2",                     NULL,  0, AV_OPT_TYPE_CONST,
> {.i64=AVCOL_SPC_IPT_C2},            INT_MIN, INT_MAX, FLAGS, .unit =
> "colorspace"},
> +
> +    {"chroma_location", "select chroma sample location",
> OFFSET(chroma_location), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCHROMA_LOC_NB-1,
> FLAGS, .unit = "chroma_location"},
> +    {"auto", "keep the same chroma location",  0, AV_OPT_TYPE_CONST,
> {.i64=-1},                       INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"unspecified",                      NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_UNSPECIFIED}, INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"unknown",                          NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_UNSPECIFIED}, INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"left",                             NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_LEFT},        INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"center",                           NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_CENTER},      INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"topleft",                          NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_TOPLEFT},     INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"top",                              NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_TOP},         INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"bottomleft",                       NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_BOTTOMLEFT},  INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
> +    {"bottom",                           NULL, 0, AV_OPT_TYPE_CONST,
> {.i64=AVCHROMA_LOC_BOTTOM},      INT_MIN, INT_MAX, FLAGS, .unit =
> "chroma_location"},
>      {NULL}
>  };
>
>
Why TYPE_CONST options have this cargo cult INT_MIN, INT_MAX propagated
again? I do not remember ever writing such nonsense, at least I remove it
whenever I see it.




> @@ -174,17 +186,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
>              frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
>      }
>
> -    /* set range */
> +    /* set straightforward parameters */
>      if (s->color_range >= 0)
>          frame->color_range = s->color_range;
> -
> -    /* set color prim, trc, space */
>      if (s->color_primaries >= 0)
>          frame->color_primaries = s->color_primaries;
>      if (s->color_trc >= 0)
>          frame->color_trc = s->color_trc;
>      if (s->colorspace >= 0)
>          frame->colorspace = s->colorspace;
> +    if (s->chroma_location >= 0)
> +        frame->chroma_location = s->chroma_location;
> +
>      return ff_filter_frame(ctx->outputs[0], frame);
>  }
>
> --
> 2.45.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index c9c4f7cf6b..ca8f6e461a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22073,6 +22073,23 @@  Keep the same colorspace property (default).
 @item chroma-derived-c
 @item ictcp
 @end table
+
+@item chroma_location
+Set the chroma sample location.
+Available values are:
+
+@table @samp
+@item auto
+Keep the same chroma location (default).
+
+@item unspecified, unknown
+@item left
+@item center
+@item topleft
+@item top
+@item bottomleft
+@item bottom
+@end table
 @end table
 
 @section sharpen_npp
diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c
index b7da8eb54b..ba32a6699c 100644
--- a/libavfilter/vf_setparams.c
+++ b/libavfilter/vf_setparams.c
@@ -41,6 +41,7 @@  typedef struct SetParamsContext {
     int color_primaries;
     int color_trc;
     int colorspace;
+    int chroma_location;
 } SetParamsContext;
 
 #define OFFSET(x) offsetof(SetParamsContext, x)
@@ -119,6 +120,17 @@  static const AVOption setparams_options[] = {
     {"chroma-derived-c",           NULL,  0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_CHROMA_DERIVED_CL}, INT_MIN, INT_MAX, FLAGS, .unit = "colorspace"},
     {"ictcp",                      NULL,  0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_ICTCP},             INT_MIN, INT_MAX, FLAGS, .unit = "colorspace"},
     {"ipt-c2",                     NULL,  0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_IPT_C2},            INT_MIN, INT_MAX, FLAGS, .unit = "colorspace"},
+
+    {"chroma_location", "select chroma sample location", OFFSET(chroma_location), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCHROMA_LOC_NB-1, FLAGS, .unit = "chroma_location"},
+    {"auto", "keep the same chroma location",  0, AV_OPT_TYPE_CONST, {.i64=-1},                       INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"unspecified",                      NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_UNSPECIFIED}, INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"unknown",                          NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_UNSPECIFIED}, INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"left",                             NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_LEFT},        INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"center",                           NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_CENTER},      INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"topleft",                          NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOPLEFT},     INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"top",                              NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOP},         INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"bottomleft",                       NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOMLEFT},  INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
+    {"bottom",                           NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOM},      INT_MIN, INT_MAX, FLAGS, .unit = "chroma_location"},
     {NULL}
 };
 
@@ -174,17 +186,18 @@  FF_ENABLE_DEPRECATION_WARNINGS
             frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
     }
 
-    /* set range */
+    /* set straightforward parameters */
     if (s->color_range >= 0)
         frame->color_range = s->color_range;
-
-    /* set color prim, trc, space */
     if (s->color_primaries >= 0)
         frame->color_primaries = s->color_primaries;
     if (s->color_trc >= 0)
         frame->color_trc = s->color_trc;
     if (s->colorspace >= 0)
         frame->colorspace = s->colorspace;
+    if (s->chroma_location >= 0)
+        frame->chroma_location = s->chroma_location;
+
     return ff_filter_frame(ctx->outputs[0], frame);
 }