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 530094B864 for ; Thu, 30 Jan 2025 19:42:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F16868C14E; Thu, 30 Jan 2025 21:41:48 +0200 (EET) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BA1A68C0C5 for ; Thu, 30 Jan 2025 21:41:37 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 9E44F296C10AF; Thu, 30 Jan 2025 20:41:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1738266096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vKhyuK5HdFrP07cVaRIvT1AsNhNVc4JO/QbIy7AKdac=; b=FJRLZYcoeQPQXAYihOQ+OuMLEsbv5O7CIPwoGOuoeaG6S8P7NKz0UPXdT0DM3xLlIZTDFv F5Y+sAlP0Qy3QQjjJ4xW50R3lXPpXL6HoDTvmHYRvaSSBDS0VD+Eokb0cUNhQJtFWzAyqI 2nj1gPZ5fxbhQVi8S2JzIePKLUvv+anV0FgdvE4ypjLTkg7brsuUz0GwSCPxk5+cUWRdkU cVQy4GPeOBV4IVHg1ouZPzA1w+cbfCbpjvVf+qum2Sz8bAYPi5WgaoXqOcNg++jTrxT4O6 6YLCKHXjcR9pErEoVr+BRAcIouw4QHkYZKa9MQkhXrFXi0X4Nbse1dqUxXeZ+Q== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jan 2025 20:40:40 +0100 Message-ID: <20250130194124.21836-4-timo@rothenpieler.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250130194124.21836-1-timo@rothenpieler.org> References: <20250130194124.21836-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/9] avcodec/cuviddec: add HEVC/H.264 4:2:2 and H.264 10-bit support 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 Cc: Diego de Souza 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: From: Diego de Souza This commit adds support for 4:2:2 decoding for HEVC and H.264 on NVIDIA Blackwell GPUs for cuviddec. Moreover, it supports 10-bit decoding for H.264 on Blackwell GPUs. Signed-off-by: Diego de Souza --- libavcodec/cuviddec.c | 83 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 11 deletions(-) diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c index 502bcc7fc2..67076a1752 100644 --- a/libavcodec/cuviddec.c +++ b/libavcodec/cuviddec.c @@ -178,15 +178,39 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form switch (format->bit_depth_luma_minus8) { case 0: // 8-bit - pix_fmts[1] = chroma_444 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_NV12; + if (chroma_444) { + pix_fmts[1] = AV_PIX_FMT_YUV444P; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (format->chroma_format == cudaVideoChromaFormat_422) { + pix_fmts[1] = AV_PIX_FMT_NV16; +#endif + } else { + pix_fmts[1] = AV_PIX_FMT_NV12; + } caps = &ctx->caps8; break; case 2: // 10-bit - pix_fmts[1] = chroma_444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P010; + if (chroma_444) { + pix_fmts[1] = AV_PIX_FMT_YUV444P16; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (format->chroma_format == cudaVideoChromaFormat_422) { + pix_fmts[1] = AV_PIX_FMT_P216LE; +#endif + } else { + pix_fmts[1] = AV_PIX_FMT_P016; + } caps = &ctx->caps10; break; case 4: // 12-bit - pix_fmts[1] = chroma_444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P016; + if (chroma_444) { + pix_fmts[1] = AV_PIX_FMT_YUV444P16; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (format->chroma_format == cudaVideoChromaFormat_422) { + pix_fmts[1] = AV_PIX_FMT_P216LE; +#endif + } else { + pix_fmts[1] = AV_PIX_FMT_P016; + } caps = &ctx->caps12; break; default: @@ -304,6 +328,14 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form case AV_PIX_FMT_P016: cuinfo.OutputFormat = cudaVideoSurfaceFormat_P016; break; +#ifdef NVDEC_HAVE_422_SUPPORT + case AV_PIX_FMT_NV16: + cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV16; + break; + case AV_PIX_FMT_P216: + cuinfo.OutputFormat = cudaVideoSurfaceFormat_P216; + break; +#endif case AV_PIX_FMT_YUV444P: cuinfo.OutputFormat = cudaVideoSurfaceFormat_YUV444; break; @@ -578,6 +610,10 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame) } else if (avctx->pix_fmt == AV_PIX_FMT_NV12 || avctx->pix_fmt == AV_PIX_FMT_P010 || avctx->pix_fmt == AV_PIX_FMT_P016 || +#ifdef NVDEC_HAVE_422_SUPPORT + avctx->pix_fmt == AV_PIX_FMT_NV16 || + avctx->pix_fmt == AV_PIX_FMT_P216 || +#endif avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUV444P16) { unsigned int offset = 0; @@ -734,6 +770,7 @@ static int cuvid_test_capabilities(AVCodecContext *avctx, { CuvidContext *ctx = avctx->priv_data; CUVIDDECODECAPS *caps; + cudaVideoChromaFormat chroma_format; int res8 = 0, res10 = 0, res12 = 0; if (!ctx->cvdl->cuvidGetDecoderCaps) { @@ -753,8 +790,28 @@ static int cuvid_test_capabilities(AVCodecContext *avctx, ctx->caps8.eCodecType = ctx->caps10.eCodecType = ctx->caps12.eCodecType = cuparseinfo->CodecType; + switch (avctx->pix_fmt) { + case AV_PIX_FMT_YUV444P16: + case AV_PIX_FMT_YUV444P: + chroma_format = cudaVideoChromaFormat_444; + break; +#ifdef NVDEC_HAVE_422_SUPPORT + case AV_PIX_FMT_P216: + case AV_PIX_FMT_P210: + case AV_PIX_FMT_NV16: + chroma_format = cudaVideoChromaFormat_422; + break; +#endif + case AV_PIX_FMT_P016: + case AV_PIX_FMT_P010: + case AV_PIX_FMT_NV12: + chroma_format = cudaVideoChromaFormat_420; + break; + default: + chroma_format = cudaVideoChromaFormat_Monochrome; + } ctx->caps8.eChromaFormat = ctx->caps10.eChromaFormat = ctx->caps12.eChromaFormat - = cudaVideoChromaFormat_420; + = chroma_format; ctx->caps8.nBitDepthMinus8 = 0; ctx->caps10.nBitDepthMinus8 = 2; @@ -790,12 +847,12 @@ static int cuvid_test_capabilities(AVCodecContext *avctx, } if (!ctx->caps8.bIsSupported) { - av_log(avctx, AV_LOG_ERROR, "Codec %s is not supported.\n", avctx->codec->name); + av_log(avctx, AV_LOG_ERROR, "Codec %s is not supported with this chroma format.\n", avctx->codec->name); return AVERROR(EINVAL); } if (!caps->bIsSupported) { - av_log(avctx, AV_LOG_ERROR, "Bit depth %d is not supported.\n", bit_depth); + av_log(avctx, AV_LOG_ERROR, "Bit depth %d with this chroma format is not supported.\n", bit_depth); return AVERROR(EINVAL); } @@ -839,7 +896,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) int probed_width = avctx->coded_width ? avctx->coded_width : 1280; int probed_height = avctx->coded_height ? avctx->coded_height : 720; - int probed_bit_depth = 8, is_yuv444 = 0; + int probed_bit_depth = 8, is_yuv444 = 0, is_yuv422 = 0; const AVPixFmtDescriptor *probe_desc = av_pix_fmt_desc_get(avctx->pix_fmt); if (probe_desc && probe_desc->nb_components) @@ -848,17 +905,21 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (probe_desc && !probe_desc->log2_chroma_w && !probe_desc->log2_chroma_h) is_yuv444 = 1; +#ifdef NVDEC_HAVE_422_SUPPORT + if (probe_desc && probe_desc->log2_chroma_w && !probe_desc->log2_chroma_h) + is_yuv422 = 1; +#endif + // Pick pixel format based on bit depth and chroma sampling. - // Only 420 and 444 sampling are supported by HW so far, no need to check for 422. switch (probed_bit_depth) { case 10: - pix_fmts[1] = is_yuv444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P010; + pix_fmts[1] = is_yuv444 ? AV_PIX_FMT_YUV444P16 : (is_yuv422 ? AV_PIX_FMT_P216 : AV_PIX_FMT_P010); break; case 12: - pix_fmts[1] = is_yuv444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P016; + pix_fmts[1] = is_yuv444 ? AV_PIX_FMT_YUV444P16 : (is_yuv422 ? AV_PIX_FMT_P216 : AV_PIX_FMT_P016); break; default: - pix_fmts[1] = is_yuv444 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_NV12; + pix_fmts[1] = is_yuv444 ? AV_PIX_FMT_YUV444P : (is_yuv422 ? AV_PIX_FMT_NV16 : AV_PIX_FMT_NV12); break; } -- 2.45.2 _______________________________________________ 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".