Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params
@ 2024-02-05 18:39 Niklas Haas
  2024-02-05 18:39 ` [FFmpeg-devel] [PATCH 2/2] fftools/ffplay: constrain supported YUV color spaces Niklas Haas
  2024-02-08 10:57 ` [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params Niklas Haas
  0 siblings, 2 replies; 3+ messages in thread
From: Niklas Haas @ 2024-02-05 18:39 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

From: Niklas Haas <git@haasn.dev>

An oversight in my previous series. This omission slipped under the
radar because fftools/ffmpeg_filter.c did not use these options, instead
preferring to insert an explicit format filter.
---
 libavfilter/buffersink.c | 29 ++++++++++++++++++++++++++---
 libavfilter/buffersink.h |  2 ++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 6ba2970dd5..af7f8ab58a 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -48,6 +48,10 @@ typedef struct BufferSinkContext {
     /* only used for video */
     enum AVPixelFormat *pixel_fmts;     ///< list of accepted pixel formats
     int pixel_fmts_size;
+    enum AVColorSpace *color_spaces;    ///< list of accepted color spaces
+    int color_spaces_size;
+    enum AVColorRange *color_ranges;    ///< list of accepted color ranges
+    int color_ranges_size;
 
     /* only used for audio */
     enum AVSampleFormat *sample_fmts;   ///< list of accepted sample formats
@@ -250,19 +254,36 @@ int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out
 static int vsink_query_formats(AVFilterContext *ctx)
 {
     BufferSinkContext *buf = ctx->priv;
-    AVFilterFormats *formats = NULL;
     unsigned i;
     int ret;
 
     CHECK_LIST_SIZE(pixel_fmts)
+    CHECK_LIST_SIZE(color_spaces)
+    CHECK_LIST_SIZE(color_ranges)
     if (buf->pixel_fmts_size) {
+        AVFilterFormats *formats = NULL;
         for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
             if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
                 return ret;
         if ((ret = ff_set_common_formats(ctx, formats)) < 0)
             return ret;
-    } else {
-        if ((ret = ff_default_query_formats(ctx)) < 0)
+    }
+
+    if (buf->color_spaces_size) {
+        AVFilterFormats *formats = NULL;
+        for (i = 0; i < NB_ITEMS(buf->color_spaces); i++)
+            if ((ret = ff_add_format(&formats, buf->color_spaces[i])) < 0)
+                return ret;
+        if ((ret = ff_set_common_color_spaces(ctx, formats)) < 0)
+            return ret;
+    }
+
+    if (buf->color_ranges_size) {
+        AVFilterFormats *formats = NULL;
+        for (i = 0; i < NB_ITEMS(buf->color_ranges); i++)
+            if ((ret = ff_add_format(&formats, buf->color_ranges[i])) < 0)
+                return ret;
+        if ((ret = ff_set_common_color_ranges(ctx, formats)) < 0)
             return ret;
     }
 
@@ -365,6 +386,8 @@ static int asink_query_formats(AVFilterContext *ctx)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption buffersink_options[] = {
     { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+    { "color_spaces", "set the supported color spaces", OFFSET(color_spaces), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+    { "color_ranges", "set the supported color ranges", OFFSET(color_ranges), AV_OPT_TYPE_BINARY, .flags = FLAGS },
     { NULL },
 };
 #undef FLAGS
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index a9374b8b4f..5f7172028d 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -55,6 +55,8 @@
  * The format can be constrained by setting options, using av_opt_set() and
  * related functions with the AV_OPT_SEARCH_CHILDREN flag.
  *  - pix_fmts (int list),
+ *  - color_spaces (int list),
+ *  - color_ranges (int list),
  *  - sample_fmts (int list),
  *  - sample_rates (int list),
  *  - ch_layouts (string),
-- 
2.43.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] fftools/ffplay: constrain supported YUV color spaces
  2024-02-05 18:39 [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params Niklas Haas
@ 2024-02-05 18:39 ` Niklas Haas
  2024-02-08 10:57 ` [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params Niklas Haas
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Haas @ 2024-02-05 18:39 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

From: Niklas Haas <git@haasn.dev>

SDL supports only these three matrices. Actually, it only supports these
three combinations: BT.601+JPEG, BT.601+MPEG, BT.709+MPEG, but we have
no way to restrict the specific *combination* of YUV range and YUV
colorspace with the current filter design.

See-Also: https://trac.ffmpeg.org/ticket/10839

Instead of an incorrect conversion result, trying to play a YCgCo file
with ffplay will simply error out with a "No conversion possible" error.
---
 fftools/ffplay.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 132f50a5a1..53e6fc0514 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -940,6 +940,13 @@ static int upload_texture(SDL_Texture **tex, AVFrame *frame)
     return ret;
 }
 
+static enum AVColorSpace sdl_supported_color_spaces[] = {
+    AVCOL_SPC_BT709,
+    AVCOL_SPC_BT470BG,
+    AVCOL_SPC_SMPTE170M,
+    AVCOL_SPC_UNSPECIFIED,
+};
+
 static void set_sdl_yuv_conversion_mode(AVFrame *frame)
 {
 #if SDL_VERSION_ATLEAST(2,0,8)
@@ -1921,6 +1928,8 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
 
     if ((ret = av_opt_set_int_list(filt_out, "pix_fmts", pix_fmts,  AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)
         goto fail;
+    if ((ret = av_opt_set_int_list(filt_out, "color_spaces", sdl_supported_color_spaces,  AVCOL_SPC_UNSPECIFIED, AV_OPT_SEARCH_CHILDREN)) < 0)
+        goto fail;
 
     last_filter = filt_out;
 
-- 
2.43.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params
  2024-02-05 18:39 [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params Niklas Haas
  2024-02-05 18:39 ` [FFmpeg-devel] [PATCH 2/2] fftools/ffplay: constrain supported YUV color spaces Niklas Haas
@ 2024-02-08 10:57 ` Niklas Haas
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Haas @ 2024-02-08 10:57 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

Ping.

Will merge at the end of the week if no objections.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-08 10:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 18:39 [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params Niklas Haas
2024-02-05 18:39 ` [FFmpeg-devel] [PATCH 2/2] fftools/ffplay: constrain supported YUV color spaces Niklas Haas
2024-02-08 10:57 ` [FFmpeg-devel] [PATCH 1/2] avfilter/buffersink: add color_spaces, color_ranges params Niklas Haas

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git