PR #24437 opened by nyanmisaka URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24437 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24437.patch
# Summary of changes The `hw_frames_ctx` of a frame obtained via HW-mapping through `hwmap` holds a reference to the original hardware frame, yet the frame itself is a software frame. There is no reason to refuse converting it to another software frame using swscale. ``` ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi <INPUT> -an -sn -dn \ -vf "hwmap=mode=read,format=nv12,format=yuv420p" -vframes 1 -f null - ``` Fixes 362414afbaaf2174d695bea8b40eb4e60598bad9 Signed-off-by: nyanmisaka <[email protected]> >From bcb35df890337054e3a1ed1aa7a67c06edb93d8a Mon Sep 17 00:00:00 2001 From: nyanmisaka <[email protected]> Date: Thu, 10 Sep 2026 13:26:58 +0800 Subject: [PATCH] swscale: fix conversion between HW-mapped frames and SW frames The `hw_frames_ctx` of a frame obtained via HW-mapping through `hwmap` holds a reference to the original hardware frame, yet the frame itself is a software frame. There is no reason to refuse converting it to another software frame using swscale. ``` ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi <INPUT> -an -sn -dn \ -vf "hwmap=mode=read,format=nv12,format=yuv420p" -vframes 1 -f null - ``` Fixes 362414afbaaf2174d695bea8b40eb4e60598bad9 Signed-off-by: nyanmisaka <[email protected]> --- libswscale/swscale.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index bdaf17d9b1..207a346e4f 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1510,7 +1510,12 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) /* For now, if a single frame has a context, then both need a context */ if (!!src->hw_frames_ctx != !!dst->hw_frames_ctx) { - return AVERROR(ENOTSUP); + const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src->format); + const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst->format); + const int is_mapped_hwframe_to_sw = !(src_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) && + !(dst_desc->flags & AV_PIX_FMT_FLAG_HWACCEL); + if (!is_mapped_hwframe_to_sw) + return AVERROR(ENOTSUP); } else if (!!src->hw_frames_ctx) { /* Both hardware frames must already be allocated */ if (!src->data[0] || !dst->data[0]) -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
