How to copy the decoded YUV data to the buffer

I am developing a program that uses decoded YUV data.

With reference to the sample 06_jpeg_decode, I succeeded in writing yuv data to a file, then reading it and putting it into a char buffer to use.

However, I don’t know how to copy the buffer right away without using the file.

After getting NvBuffer through getNthBuffer, I thought I could copy the data in NvBuffer, but it failed.

Is there any way or sample I can refer to?

Why just handle the buffer output from the decodor?

Use YUV output from the source code already developed.

It is difficult to modify the source code.

You can allocate NvBuffer and use NVBufferTransform() to copy the data to another buffer. Similar code can be seen in 12_camera_v4l2_cuda. Please take a look.