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 23C9F4B84C for ; Thu, 30 Jan 2025 19:42:11 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DB55068C110; Thu, 30 Jan 2025 21:41:46 +0200 (EET) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E2F6468BECE for ; Thu, 30 Jan 2025 21:41:36 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 56B5E296C10AC; 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=lBUvjZK3b+llhnhKzKVAoVqYrhkgJzFhoo35vfORSSY=; b=rnPLud2gt0VJkzsfVuLlp8imJdVXMg0BgOtPTNwJ1xYbwcNV2R32c6rRFGdAUVuPACIJs9 gOKATr3LLKlnd0sbTw9h8z7JVTdQwms4nreC9HRsZ/H/SRnU6o15BHJ5DMHlgTc5flQwah I+nYqpqyVcxapidhK8Gdcv2XlPOqQTYxkv36L1VoNKDFpdrGwiOz+zylHCowjk+abYO2/M CvxlKCrzEWjNIhPPSorm5fA9ilb2q0yJamqyTZLk4r0LkDdceASbY6VyxkWhJexCcZ4AAs pCYuJ04moQhGvHRiWtA11mlFgAYm8xZzuclXuzYq+fvKrFXk8UJMejLag+JCdw== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jan 2025 20:40:39 +0100 Message-ID: <20250130194124.21836-3-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 2/9] avcodec/nvdec: add 4:2:2 decoding and 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. Additionally, it supports 10-bit decoding for H.264 on Blackwell GPUs. Signed-off-by: Diego de Souza --- libavcodec/h264_slice.c | 3 +++ libavcodec/hevc/hevcdec.c | 6 ++++++ libavcodec/nvdec.c | 44 ++++++++++++++++++++++++++++++++------- libavcodec/nvdec.h | 5 +++++ libavcodec/nvdec_h264.c | 2 +- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 5108fa0921..cb22b76730 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -807,6 +807,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) #endif #if CONFIG_H264_VULKAN_HWACCEL *fmt++ = AV_PIX_FMT_VULKAN; +#endif +#if CONFIG_H264_NVDEC_HWACCEL + *fmt++ = AV_PIX_FMT_CUDA; #endif if (CHROMA444(h)) { if (h->avctx->colorspace == AVCOL_SPC_RGB) { diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 7d3e844945..e9c045f7a1 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -626,6 +626,9 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) #endif #if CONFIG_HEVC_VULKAN_HWACCEL *fmt++ = AV_PIX_FMT_VULKAN; +#endif +#if CONFIG_HEVC_NVDEC_HWACCEL + *fmt++ = AV_PIX_FMT_CUDA; #endif break; case AV_PIX_FMT_YUV444P10: @@ -654,6 +657,9 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) #endif #if CONFIG_HEVC_VULKAN_HWACCEL *fmt++ = AV_PIX_FMT_VULKAN; +#endif +#if CONFIG_HEVC_NVDEC_HWACCEL + *fmt++ = AV_PIX_FMT_CUDA; #endif break; } diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index db9d353c61..99351661ea 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -375,13 +375,27 @@ int ff_nvdec_decode_init(AVCodecContext *avctx) switch (sw_desc->comp[0].depth) { case 8: - output_format = chroma_444 ? cudaVideoSurfaceFormat_YUV444 : - cudaVideoSurfaceFormat_NV12; + if (chroma_444) { + output_format = cudaVideoSurfaceFormat_YUV444; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { + output_format = cudaVideoSurfaceFormat_NV16; +#endif + } else { + output_format = cudaVideoSurfaceFormat_NV12; + } break; case 10: case 12: - output_format = chroma_444 ? cudaVideoSurfaceFormat_YUV444_16Bit : - cudaVideoSurfaceFormat_P016; + if (chroma_444) { + output_format = cudaVideoSurfaceFormat_YUV444_16Bit; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { + output_format = cudaVideoSurfaceFormat_P216; +#endif + } else { + output_format = cudaVideoSurfaceFormat_P016; + } break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth\n"); @@ -729,13 +743,27 @@ int ff_nvdec_frame_params(AVCodecContext *avctx, switch (sw_desc->comp[0].depth) { case 8: - frames_ctx->sw_format = chroma_444 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_NV12; + if (chroma_444) { + frames_ctx->sw_format = AV_PIX_FMT_YUV444P; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { + frames_ctx->sw_format = AV_PIX_FMT_NV16; +#endif + } else { + frames_ctx->sw_format = AV_PIX_FMT_NV12; + } break; case 10: - frames_ctx->sw_format = chroma_444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P010; - break; case 12: - frames_ctx->sw_format = chroma_444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P016; + if (chroma_444) { + frames_ctx->sw_format = AV_PIX_FMT_YUV444P16; +#ifdef NVDEC_HAVE_422_SUPPORT + } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { + frames_ctx->sw_format = AV_PIX_FMT_P216LE; +#endif + } else { + frames_ctx->sw_format = AV_PIX_FMT_P016LE; + } break; default: return AVERROR(EINVAL); diff --git a/libavcodec/nvdec.h b/libavcodec/nvdec.h index 5e22f672d1..2e80c0dc1e 100644 --- a/libavcodec/nvdec.h +++ b/libavcodec/nvdec.h @@ -41,6 +41,11 @@ ((major) < 8 || ((major) == 8 && (minor) <= 0)) #endif +// SDK 13.0 compile time feature checks +#if NVDECAPI_CHECK_VERSION(13, 0) +#define NVDEC_HAVE_422_SUPPORT +#endif + typedef struct NVDECFrame { unsigned int idx; unsigned int ref_idx; diff --git a/libavcodec/nvdec_h264.c b/libavcodec/nvdec_h264.c index 9adbc521ec..1ae3dfd032 100644 --- a/libavcodec/nvdec_h264.c +++ b/libavcodec/nvdec_h264.c @@ -97,7 +97,7 @@ static int nvdec_h264_start_frame(AVCodecContext *avctx, .num_ref_idx_l1_active_minus1 = pps->ref_count[1] - 1, .weighted_pred_flag = pps->weighted_pred, .weighted_bipred_idc = pps->weighted_bipred_idc, - .pic_init_qp_minus26 = pps->init_qp - 26, + .pic_init_qp_minus26 = pps->init_qp - 26 - 6 * (sps->bit_depth_luma - 8), .deblocking_filter_control_present_flag = pps->deblocking_filter_parameters_present, .redundant_pic_cnt_present_flag = pps->redundant_pic_cnt_present, .transform_8x8_mode_flag = pps->transform_8x8_mode, -- 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".