avcodec/nvdec: fix dimension rounding for monochrome/444 formats

frames_ctx->width/height were unconditionally rounded to even, causing
odd-dimension monochrome/444 clips to be reported with incorrect
surface pool dimensions. Round only for 4:2:0 and 4:2:2; for
monochrome/444 use avctx->coded_width/coded_height unchanged,
matching the dimensions set by the software codec layer.

Patch by: Aniket Dhok <adhok@nvidia.com>
Signed-off-by: Diego de Souza <ddesouza@nvidia.com>
This commit is contained in:
Diego de Souza
2026-05-18 20:47:15 +00:00
committed by Timo Rothenpieler
co-authored by Timo Rothenpieler
parent fa1ba61775
commit 7ac3d83e7a
+12 -2
View File
@@ -732,8 +732,18 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
chroma_444 = supports_444 && cuvid_chroma_format == cudaVideoChromaFormat_444;
frames_ctx->format = AV_PIX_FMT_CUDA;
frames_ctx->width = (avctx->coded_width + 1) & ~1;
frames_ctx->height = (avctx->coded_height + 1) & ~1;
// NVDEC target dimensions must be even-aligned for internal surface allocation.
// For chroma-subsampled formats (420/422), the output dimensions must also be
// even. For monochrome/444, keep the original output dimensions and only
// even-align the NVDEC target — the frame copy will crop to avctx dimensions.
if (cuvid_chroma_format == cudaVideoChromaFormat_420 ||
cuvid_chroma_format == cudaVideoChromaFormat_422) {
frames_ctx->width = (avctx->coded_width + 1) & ~1;
frames_ctx->height = (avctx->coded_height + 1) & ~1;
} else {
frames_ctx->width = avctx->coded_width;
frames_ctx->height = avctx->coded_height;
}
/*
* We add two extra frames to the pool to account for deinterlacing filters
* holding onto their frames.