From patchwork Sat Aug 10 08:51:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Batlle_i_Rossell?= X-Patchwork-Id: 50963 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:1ff2:b0:489:2eb3:e4c4 with SMTP id ks18csp322006vqb; Sat, 10 Aug 2024 01:51:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU4C6U0XHgZd8ueww13bQvlg7Aj0j0qEq3sOnE+O8/KjIjKc4MMHpmgu1XsGwyEE5DRQLIU9nIcaRcDU9vtrSBM0r9RQUtO2oNbeQ== X-Google-Smtp-Source: AGHT+IH0o8lLbFmC+cOO5qYp+kxeuR7koKiMDp2O/feQN6SUPAR2rJR4kiHyBuhGN4mPRiLRFaY/ X-Received: by 2002:a05:6402:5216:b0:5bb:9ae0:4a48 with SMTP id 4fb4d7f45d1cf-5bd0a509e51mr3117042a12.5.1723279917678; Sat, 10 Aug 2024 01:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723279917; cv=none; d=google.com; s=arc-20160816; b=LjI7+ajo4vb07lUpMk5KX58xY2Os4tVEqW9ns4be9vRI3BdIM8YiCnVW8PSAUGPJy/ Q61JszLrQwPcdoUR6+3CpHILbBi+5cihu1uznwlN+ITb3GhHO1ZE7XOenmrHcWFjtmuL vmCzKIpt4I00eTFvZ2HTiGp2XlLReSV2guhn1UR4Ozn9Zh8eVBqmXODFHA+F/whaUDJc el0MNIXxVq85n3zzxX25IrUYZgU/H2tPEB0SLXCYmAYpGZriqANpvoAI3XyZQaULOA7U xXUS5d4vx5eE79Jn6dDsLMvqJETZRnGPPCRIFTGdDR4DBNzsJao1v/5p8uHGAZPqVE00 byQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:to:from:date:dkim-signature :delivered-to; bh=L8AogbL1b7a+PtctEJHZXz6dlPLW9N0L4LCVS5K9occ=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=eOgsf1+sCASq/f53+I+zQfD4WjJ6t7b5GWV+nMGY93JEckd2vc4dtBmfuDiESMoyRX LkSQrFgguW9vOzXMyaxqhhKdLVUGFp0JzeXdf5hb5Pv2UEe9/gpl5nhLs+R2tCBVvKpu fvq58dwvenpAs2FzGdh90+4oRoijlNCe/NPjrXae+dIGebpJpjKiSohzmWTCWXt8MNTp ya1SItocZDMPO0i3Fie9VnvV+QWLOLGO04FJdmP1Dv8UIYn2H4Ex9SIUBQRk/Qtvje3+ 8AyURQeLlEIU0kzUX3mBx7QlrHCY2a4J60MpDxCvZUoxAjcT4SoTiNCNnpQmkIcN49g8 HlwQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@viric.name header.s=dkim1 header.b="ofnQAT/7"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=viric.name Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5bd1a63a6f0si676487a12.640.2024.08.10.01.51.52; Sat, 10 Aug 2024 01:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@viric.name header.s=dkim1 header.b="ofnQAT/7"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=viric.name Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A14A168D9D8; Sat, 10 Aug 2024 11:51:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.viric.name (mail.viric.name [37.18.133.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE3CB68D910 for ; Sat, 10 Aug 2024 11:51:41 +0300 (EEST) Received: by mail.viric.name (Postfix, from userid 1000) id 7C3C512BFE50; Sat, 10 Aug 2024 10:51:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=viric.name; s=dkim1; t=1723279900; bh=/Yu6Xlhl0heE3f1wyXVqZukmVolLiaWEbwLmW0Vu9vE=; h=Date:From:To:Subject:References:In-Reply-To; b=ofnQAT/7KbyIGjtSI5LNBVffX/LH10RVO/eYcPLMWPGR5FNMN75MwjdSRm4jR1qbi a1s0tQapNt0CL+MId1NNsoGLJo0FHSq993Hi6Y5x1o/RS98fJwPTKx3OEr7OsHvizX 1nLUj9OnL5Vs1j83QMsUQpH5zjnqGgEQfcUzEVrM= Date: Sat, 10 Aug 2024 10:51:40 +0200 From: =?iso-8859-1?q?Llu=EDs?= Batlle i Rossell To: FFmpeg development discussions and patches Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Accept-Language: ca, es, eo, ru, en, jbo, tokipona Subject: [FFmpeg-devel] PATCH: Fallback to NV12 format in VAAPI drivers 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oKcYLxxJszLd On Fri, Aug 09, 2024 at 09:43:53AM +0200, Lluís Batlle i Rossell wrote: > On Fri, Aug 09, 2024 at 11:49:54AM +0800, Zhao Zhili wrote: > > > vaapi drivers often lack proper image converesions and not all > > > situations allow vagetimage or vaputimage with the image formats > > > reported by the api. nv12 seems allowed in all circumstances. > > > > > > with this change now one can use the hwaccel directly without > > > explicit conversions to nv12 for frame downloading to work. > > > > > > gstreamer adopted a similar approach: > > > https://bugzilla.gnome.org/show_bug.cgi?id=752958 > > > > Isn’t it break all pixel formats with bit depth > 8? > > I think we already have hwcontext API to select sw_format, this isn’t a bug > > inside ffmpeg. > > Correct... I didn't think of the need beyond NV12. > > What if I redo the patch so I keep all formats, but I simply move NV12 to > the first place? That will make ffmpeg pick NV12 as default if NONE > specified. I attach a different patch, so NV12 is only picked in case the dst format is NONE. 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;