Failing to save I420 raw image with gstreamer

I am trying to save an I420 image (after it gets nvconverted from UYVY) using a gstreamer pipeline.

I have tried the below pipelines:

gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! 'video/x-raw, format=(string)UYVY, width=(int)3840, height=(int)2160' ! nvvidconv ! 'video/x-raw(memory:NVMM), format=(string)I420' ! filesink location=test.I420

It resulted in a 1kb file being saved.

Then after reading https://devtalk.nvidia.com/default/topic/916204/jetson-tx1/saving-csi-nvcamera-raw-frames-to-file-using-gstreamer-/
I tried

gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! 'video/x-raw(memory:NVMM), format=(string)UYVY, width=(int)3840, height=(int)2160' ! nvvidconv ! 'video/x-raw, format=(string)I420' ! filesink location=test.I420

But I got the following error:

WARNING: erroneous pipeline: could not link v4l2src0 to nvvconv0, v4l2src0 can't handle caps video/x-raw(memory:NVMM), format=(string)I420, width=(int)3840, height=(int)2160

I would like to know what would be a correct pipeline for saving an x-raw I420 image using nvvidconv.

Thanks for any help!

The problem with your first pipeline is that filesink cannot correctly handle NVMM memory. In the second case, the problem is that v4l2src can only output into CPU memory, not NVMM. Try this:

gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! 'video/x-raw, format=(string)UYVY, width=(int)3840, height=(int)2160' ! nvvidconv ! 'video/x-raw(memory:NVMM), format=(string)I420' ! nvvidconv ! 'video/x-raw, format=(string)I420' ! filesink location=test.I420