From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id EA3884BFB5 for ; Wed, 22 Jan 2025 15:03:28 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B317268B980; Wed, 22 Jan 2025 17:03:24 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 80CEE68B8E5 for ; Wed, 22 Jan 2025 17:03:18 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with ESMTP id 3630947DBF for ; Wed, 22 Jan 2025 16:03:18 +0100 (CET) Date: Wed, 22 Jan 2025 16:03:18 +0100 Message-ID: <20250122160318.GB73815@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: <20250118013803.3018-1-jamrial@gmail.com> References: <20250118013803.3018-1-jamrial@gmail.com> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH] swscale/swscale: don't reject scaling when color parameters are not supported but conversion is not required X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, 17 Jan 2025 22:38:03 -0300 James Almer wrote: > Values in csp, prim, trc, etc, are irrelevant if there's no conversion needed. > > Signed-off-by: James Almer > --- > ./ffmpeg -i https://0x0.st/8Hr_.mp4 -vf "scale=1920:1080" -f null - > > Fails without this patch, because swscale lacks conversion for the signaled > color primaries. > > libswscale/swscale.c | 13 +++++-------- > libswscale/utils.h | 16 +++++++++++----- > 2 files changed, 16 insertions(+), 13 deletions(-) > > diff --git a/libswscale/swscale.c b/libswscale/swscale.c > index 30fbc590fd..70667ebd1c 100644 > --- a/libswscale/swscale.c > +++ b/libswscale/swscale.c > @@ -1442,6 +1442,7 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) > for (int field = 0; field < 2; field++) { > SwsFormat src_fmt = ff_fmt_from_frame(src, field); > SwsFormat dst_fmt = ff_fmt_from_frame(dst, field); > + int src_ret, dst_ret; > > if ((src->flags ^ dst->flags) & AV_FRAME_FLAG_INTERLACED) { > err_msg = "Cannot convert interlaced to progressive frames or vice versa.\n"; > @@ -1449,14 +1450,10 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) > goto fail; > } > > - if (!ff_test_fmt(&src_fmt, 0)) { > - err_msg = "Unsupported input"; > - ret = AVERROR(ENOTSUP); > - goto fail; > - } > - > - if (!ff_test_fmt(&dst_fmt, 1)) { > - err_msg = "Unsupported output"; > + src_ret = ff_test_fmt(&src_fmt, 0); > + dst_ret = ff_test_fmt(&dst_fmt, 1); > + if ((!src_ret || !dst_ret) && !ff_props_equal(&src_fmt, &dst_fmt)) { > + err_msg = src_ret ? "Unsupported output" : "Unsupported input"; Nit: Could move the style change to a separate commit. Nit: Would rename "src_ret" to "src_ok" and "dst_ret" to "dst_ok" to make it clearer that 0 indicates failure, not success. While this is an improvement, it fails to solve the root problem. I think the correct fix is to defer the check to ff_sws_graph_init(), which can fail in a more granular way when these properties are actually being needed. That said, this improves the status quo so LGTM for now. > ret = AVERROR(ENOTSUP); > goto fail; > } > diff --git a/libswscale/utils.h b/libswscale/utils.h > index d76fea1133..8e0cdf26ec 100644 > --- a/libswscale/utils.h > +++ b/libswscale/utils.h > @@ -98,12 +98,10 @@ static inline int ff_color_equal(const SwsColor *c1, const SwsColor *c2) > ff_prim_equal(&c1->gamut, &c2->gamut); > } > > -/* Tests only the static components of a colorspace, ignoring per-frame data */ > -static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2) > +/* Tests only the static components of a colorspace, ignoring dimensions and per-frame data */ > +static inline int ff_props_equal(const SwsFormat *fmt1, const SwsFormat *fmt2) > { > - return fmt1->width == fmt2->width && > - fmt1->height == fmt2->height && > - fmt1->interlaced == fmt2->interlaced && > + return fmt1->interlaced == fmt2->interlaced && > fmt1->format == fmt2->format && > fmt1->range == fmt2->range && > fmt1->csp == fmt2->csp && > @@ -111,6 +109,14 @@ static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2) > ff_color_equal(&fmt1->color, &fmt2->color); > } > > +/* Tests only the static components of a colorspace, ignoring per-frame data */ > +static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2) > +{ > + return fmt1->width == fmt2->width && > + fmt1->height == fmt2->height && > + ff_props_equal(fmt1, fmt2); > +} > + > static inline int ff_fmt_align(enum AVPixelFormat fmt) > { > const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); > -- > 2.48.1 > > _______________________________________________ > 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". _______________________________________________ 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".