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

Both paths unconditionally rounded display dimensions to even via
(dim + 1) & ~1. This is required for 4:2:0 and 4:2:2 (chroma
subsampling requires even-aligned surfaces) but incorrect for
monochrome and 4:4:4. AV1 monochrome clips with odd dimensions
(e.g. 1273x713) were output as 1274x714.

cuinfo.ulTargetWidth/Height still receives the even-aligned value
for internal NVDEC surface allocation. avctx->width/height are only
updated to the rounded value for 420/422; for monochrome/444 the
original display dimensions are preserved and the cuMemcpy2D copy
crops naturally.

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 1356714d11
commit fa1ba61775
+11 -3
View File
@@ -164,9 +164,17 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
avctx->height = cuinfo.display_area.bottom - cuinfo.display_area.top;
}
// target width/height need to be multiples of two
cuinfo.ulTargetWidth = avctx->width = (avctx->width + 1) & ~1;
cuinfo.ulTargetHeight = avctx->height = (avctx->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.
cuinfo.ulTargetWidth = (avctx->width + 1) & ~1;
cuinfo.ulTargetHeight = (avctx->height + 1) & ~1;
if (format->chroma_format == cudaVideoChromaFormat_420 ||
format->chroma_format == cudaVideoChromaFormat_422) {
avctx->width = cuinfo.ulTargetWidth;
avctx->height = cuinfo.ulTargetHeight;
}
// aspect ratio conversion, 1:1, depends on scaled resolution
cuinfo.target_rect.left = 0;