avutil/hwcontext_cuda: fix yuv420p V/U plane overlap in cuda_get_buffer() release/8.1
authornyanmisaka <nst799610810@gmail.com>
Mon, 29 Jun 2026 07:32:00 +0000 (15:32 +0800)
committerMarvin Scholz <epirat07@gmail.com>
Mon, 29 Jun 2026 15:41:14 +0000 (17:41 +0200)
Odd-height yuv420p result in incorrect calculations of the U-plane
address offset. The last row of the V-plane overlapped with and was
overwritten by the first row of the U-plane, leading to chroma artifacts.

```
ffmpeg -init_hw_device cuda=cu -filter_hw_device cu -f lavfi -i \
testsrc=s=1920x1081,format=yuv420p -vf hwupload -c:v hevc_nvenc \
-vframes 1 -y <OUTPUT>
```

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
(cherry picked from commit 3f6bf150cb018334809bec029325b28cff8a5a9a)
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
libavutil/hwcontext_cuda.c

index b0b65b24462ae5fd5e798b38798f17ae02294beb..46f8297168ad413933096a6a2af4c8eca1cdae48 100644 (file)
@@ -207,7 +207,7 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
     if (ctx->sw_format == AV_PIX_FMT_YUV420P) {
         frame->linesize[1] = frame->linesize[2] = frame->linesize[0] / 2;
         frame->data[2]     = frame->data[1];
-        frame->data[1]     = frame->data[2] + frame->linesize[2] * (ctx->height / 2);
+        frame->data[1]     = frame->data[2] + frame->linesize[2] * AV_CEIL_RSHIFT(ctx->height, 1);
     }
 
     frame->format = AV_PIX_FMT_CUDA;