From c633b6ba0975bd495df2479aa9a562958bb87e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Sat, 10 Aug 2024 10:45:14 +0200 Subject: [PATCH] Fallback to NV12 format in VAAPI drivers Even if the hw format is listed in the supported ImageFormats. That's because some drivers fail in vaGetImage even if requesting the transfer in a format equal to the hw format. NV12 is chosen only if the users don't specify any other particular format. gstreamer adopted a similar approach: https://bugzilla.gnome.org/show_bug.cgi?id=752958 --- libavutil/hwcontext_vaapi.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 12bc95119a..0396038017 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -720,20 +720,22 @@ static int vaapi_transfer_get_formats(AVHWFramesContext *hwfc, { VAAPIDeviceContext *ctx = hwfc->device_ctx->internal->priv; enum AVPixelFormat *pix_fmts; - int i, k, sw_format_available; + int i, k, nv12_format_available; - sw_format_available = 0; + /* Intel VAAPI drivers seem to support NV12 for vaGetImage, + * but fail for many formats announced in vaQueryImageFormats */ + nv12_format_available = 0; for (i = 0; i < ctx->nb_formats; i++) { - if (ctx->formats[i].pix_fmt == hwfc->sw_format) - sw_format_available = 1; + if (ctx->formats[i].pix_fmt == AV_PIX_FMT_NV12) + nv12_format_available = 1; } pix_fmts = av_malloc((ctx->nb_formats + 1) * sizeof(*pix_fmts)); if (!pix_fmts) return AVERROR(ENOMEM); - if (sw_format_available) { - pix_fmts[0] = hwfc->sw_format; + if (nv12_format_available) { + pix_fmts[0] = AV_PIX_FMT_NV12; k = 1; } else { k = 0; -- 2.44.1