From patchwork Thu Aug 1 13:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Arzumanyan X-Patchwork-Id: 50858 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:12d6:0:b0:489:2eb3:e4c4 with SMTP id 205csp1163892vqs; Thu, 1 Aug 2024 06:54:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVzK9YzpptmMI4d4WtWIYYkpyihB1PGiDmjI3CkX4vEUsXNXGZQ9BXGVsaL873Fob0Er7cxx1q1+n+E4gEpFOVRAmLLdoazoZnwSQ== X-Google-Smtp-Source: AGHT+IFRcS4xzkHtEBith1atVhT8z5ogB5pizdr0GhPUG28yGlkcsxnjSNq0YngQwimkGsw4qxjF X-Received: by 2002:a17:907:724b:b0:a77:eb34:3b4b with SMTP id a640c23a62f3a-a7dc4dc02a3mr24745466b.11.1722520498882; Thu, 01 Aug 2024 06:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722520498; cv=none; d=google.com; s=arc-20160816; b=xpkwv58HadE9OJJGVRkVRBqLuUwa6cUKokyJjHz2VEo/h8M/zY/Gs1UlNXS5brsJdi Y2yPA/fjPKvCzLkmy+7Z4pk4qHnq2ygpEsNx64zUv5gCN0cKg4urlqRaGAkLpo4vyEIk vQM5IxEWX6ALVVvgpGE8SIbJfqtcSFhbEngcBJb2eDZqi8ghXurZPx4826eleEA7w8c4 URNm5iynV9YQGsfprSMBKvqdbLA+0oVbwVf2GePLrgi4IF+saAdZcO2/vXtzRUu+QASY arU4fD2t3hRkFNytPje8539+glknGP8izhLATZ5UgTGgQKD6mo4Fk/fitp573mFxjYFf IsYA== 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:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=vDSHW7ksgpHZzhpPDhQUD4metviuXq587nuMwteWFPY=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=yEI1+VfhWE8S5kC4LhyrS5Z9//f0HjUwJ4WSzZ2hl6Y9rUHys35WmjteXiDtBEqXCd Msm5daacen4+Wq8h6DoiyChLMLqA5p7uJqw34X3BYaZB+RreBLHXdVTHcU6KySAgZNXI byMVGy3lLdFC82gxeDsnnM1iIFwRE394VWk4an2YQmcRO6yTqAeft68gpmwMBUCFlZGz gKy1xweRFdKjxFPC0Qu9ripI7If2BCzQ1t/I09UEvWSq/OWeBxHhcKVKMWyDvtI9o+/H qzLGsmkQq7yf+HjTQZBr+Df+EtT3pC1K77qBaRbEYlM49JIqn5n2YF2IxGbhxPJ00j+V ZB7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@visionlabs-ai.20230601.gappssmtp.com header.s=20230601 header.b=iUxyZqoN; 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=visionlabs.ai; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a7acab3e376si1097939666b.486.2024.08.01.06.54.58; Thu, 01 Aug 2024 06:54:58 -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=@visionlabs-ai.20230601.gappssmtp.com header.s=20230601 header.b=iUxyZqoN; 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=visionlabs.ai; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A8A4A68D5E6; Thu, 1 Aug 2024 16:54:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AEF268D5E6 for ; Thu, 1 Aug 2024 16:54:47 +0300 (EEST) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-66a048806e6so56553927b3.3 for ; Thu, 01 Aug 2024 06:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=visionlabs-ai.20230601.gappssmtp.com; s=20230601; t=1722520485; x=1723125285; darn=ffmpeg.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=0vg+WNwVCA3A2BFrgpE8dxqSZk7p9l8QHVOu1AjyST8=; b=iUxyZqoNejdWZUunu38zR01YoV4hUpObz/G2X1rWq0AP4XmDwC4IISQV9IAi01QoFL dn+JUS8LudNbv8buobx9cSvSf21TB+KES+ZC5s24g0ofygDBd0ebm3K1VuCzmq5zATUq s5l1U69z94+bNIZpXFBsin7XOJN1nOUuT7uANnZBlw5fLp18nOP2N4mqP2uFG2AvWEVl cCqWOuPsh9excBtyGKgWjPF7YBFcbnCfSAmCK0xRhckm3lMVC6tdKkHiGAvBHhMurgVz JKoKxslla0yyD5Dg2WfrfeKBA9G0fgddAddt3UJA+dZUuSaIxN0c1FFWPecJ9rSOIS2p IKaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722520485; x=1723125285; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0vg+WNwVCA3A2BFrgpE8dxqSZk7p9l8QHVOu1AjyST8=; b=vPdWRHImsE6RR8WlfQqJKoni+zs5sR46JiwVX7weLqn6rHdSB8KIkWpri940Fzxi1E 3EijtXFFRJFI96gAVyLfmHaG7BVxQLFkVlnAW2Nh3Hocw5qV+UM6J9evC659SqdOUXUo sCwamcnGdGKKKj2LQK0IcvYFEaw80bu72JO3AAY9TXVt38Oq2PmldeyMk72gm8fZXKos KLHheu+ooMb5cUQ7FcLHoog6sGAidb+0W/eU1ygoD6izQshO2hwYM9TUXozTb/FiGSBD v36eYEkmvrBQmtCbUIDURktOOD+7heCtXBJ9brFufTqn7UGN14qPW/XWgjjV9LAi1s37 VVTw== X-Gm-Message-State: AOJu0YyyYplqXWaRk4K+L1iKhsG6zcbtmJpnF3lj/B7Iwvptd6k8UVAZ V/Dkt6hZEjgSbihxZSivJcVezwC7D6jMH02twOnxavg8Ktz7StNMjbnpLAtFFqUpekmeTFNZD+Q LCEADJidPdvwOahB2QDALnyKgx/1L88fRW/tqLTbVUIC91INSFx4= X-Received: by 2002:a0d:ed86:0:b0:649:8f00:525d with SMTP id 00721157ae682-689638f3970mr373747b3.35.1722520485317; Thu, 01 Aug 2024 06:54:45 -0700 (PDT) MIME-Version: 1.0 From: Roman Arzumanyan Date: Thu, 1 Aug 2024 16:54:34 +0300 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] avcodec/cuvidddec: Guess pixel format based on probed bit depth 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: oml0EFuFGI6e Hello world, This patch adds a pixel format guess based on probed bit depth. With current FFMpeg ToT, when the cuvid codec is opened, input sw_pix_fmt is AV_PIX_FMT_NV12 until the first frame is decoded. Even if input has 10 or 12 bit depth, the format will be NV12 for some time. What's the need for this patch ? Applications that rely on libavcodec will have a chance to calculate the proper amount of vRAM required to store a reconstructed video frame before decoding begins. From ae80b12d10a4de4aa96a4670b72accbfc5a87631 Mon Sep 17 00:00:00 2001 From: Roman Arzumanyan Date: Thu, 1 Aug 2024 16:35:22 +0300 Subject: [PATCH] Guess pixel format based on bit depth --- libavcodec/cuviddec.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c index f88ad75e88..2205b1536a 100644 --- a/libavcodec/cuviddec.c +++ b/libavcodec/cuviddec.c @@ -834,7 +834,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) int ret = 0; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, - AV_PIX_FMT_NV12, + AV_PIX_FMT_NONE, AV_PIX_FMT_NONE }; int probed_width = avctx->coded_width ? avctx->coded_width : 1280; @@ -845,11 +845,26 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (probe_desc && probe_desc->nb_components) probed_bit_depth = probe_desc->comp[0].depth; + // Arbitrarily pick pixel format based on bit depth. + switch (probed_bit_depth) { + case 8: + pix_fmts[1] = AV_PIX_FMT_NV12; + break; + case 10: + pix_fmts[1] = AV_PIX_FMT_P010; + break; + case 12: + pix_fmts[1] = AV_PIX_FMT_P012; + break; + default: + break; + } + ctx->pkt = avctx->internal->in_pkt; // Accelerated transcoding scenarios with 'ffmpeg' require that the // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the // pix_fmt for non-accelerated transcoding, do not need to be correct - // but need to be set to something. We arbitrarily pick NV12. + // but need to be set to something. ret = ff_get_format(avctx, pix_fmts); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret); -- 2.34.1