This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit fa1ba61775fe0ce4d7c67ef3a3626e7688be5898
Author:     Diego de Souza <[email protected]>
AuthorDate: Tue Apr 21 17:31:49 2026 +0200
Commit:     Timo Rothenpieler <[email protected]>
CommitDate: Mon May 18 20:47:15 2026 +0000

    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 <[email protected]>
    Signed-off-by: Diego de Souza <[email protected]>
---
 libavcodec/cuviddec.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index a1d7cc17a9..10e4cb3e21 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -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;

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to