diff mbox series

[FFmpeg-devel,02/11] avfilter/buffersrc: allow promoting color range to MPEG

Message ID 20240112082950.41637-3-ffmpeg@haasn.xyz
State New
Headers show
Series YUVJ removal | expand

Checks

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

Commit Message

Niklas Haas Jan. 12, 2024, 8:25 a.m. UTC
From: Niklas Haas <git@haasn.dev>

Otherwise, passing an UNSPECIFIED frame to am MPEG-only filter graph
would trigger insertion of an unnecessary vf_scale filter, which would
perform a memcpy to convert between the two.

This is safe to do because unspecified YUV frames are already
universally assumed to be MPEG range, in particular by swscale.
---
 libavfilter/buffersrc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index e10653c866..ee0c89ef05 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -492,8 +492,14 @@  static int query_formats(AVFilterContext *ctx)
             if ((ret = ff_add_format(&color_spaces, c->color_space)) < 0 ||
                 (ret = ff_set_common_color_spaces(ctx, color_spaces)) < 0)
                 return ret;
-            if ((ret = ff_add_format(&color_ranges, c->color_range)) < 0 ||
-                (ret = ff_set_common_color_ranges(ctx, color_ranges)) < 0)
+            if ((ret = ff_add_format(&color_ranges, c->color_range)) < 0)
+                return ret;
+            if (c->color_range == AVCOL_RANGE_UNSPECIFIED) {
+                /* allow implicitly promoting unspecified to mpeg */
+                if ((ret = ff_add_format(&color_ranges, AVCOL_RANGE_MPEG)) < 0)
+                    return ret;
+            }
+            if ((ret = ff_set_common_color_ranges(ctx, color_ranges)) < 0)
                 return ret;
         }
         break;