avutil/hwcontext_cuda: fix YUV420P cuda_get_buffer
authorMarton Balint <cus@passwd.hu>
Mon, 14 May 2018 21:24:43 +0000 (23:24 +0200)
committerMarton Balint <cus@passwd.hu>
Tue, 15 May 2018 20:18:58 +0000 (22:18 +0200)
Regression since ece068a771ac3f725e854c681ecbef08e792addc.

Signed-off-by: Marton Balint <cus@passwd.hu>
libavutil/hwcontext_cuda.c

index cb5d15c..3b1d53e 100644 (file)
@@ -159,10 +159,11 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
         return res;
 
     // YUV420P is a special case.
-    // Nvenc expects the U/V planes in swapped order from how ffmpeg expects them.
+    // Nvenc expects the U/V planes in swapped order from how ffmpeg expects them, also chroma is half-aligned
     if (ctx->sw_format == AV_PIX_FMT_YUV420P) {
-        FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
-        FFSWAP(int, frame->linesize[1], frame->linesize[2]);
+        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->format = AV_PIX_FMT_CUDA;