why the video is colorful?

Hi,Nvidia:
Base on tegra_multimedia_API example 12_camera_v4l2_cuda,I change the ctx->vic_pixfmt value
from V4L2_PIX_FMT_YUV420M to V4L2_PIX_FMT_GREY, copile and run,the result is video displayed
is colorful. The expected result is video is grey.
your reply is expexted. Thank you!

Hi feng.baoying,
Please try tegra_multimedia_api\samples\07_video_convert and check the saved output data.

Hi DaneLLL.
The saved output data you mentioned may be grey, but I want to know why examaple 12_camera_v4l2_cuda after I changed displays is colorful? is my change can reach my aim to get grey video? if it is,where the colorful video data comes from?
If it is not, how to change video grey from camera directly?

expected your reply. Thanks!

Hi DaneLLL.
How to check the saved output data use the example tegra_multimedia_api\samples\07_video_convert?
In fuction conv_capture_dqbuf_thread_callback, I record the data in NvBuffer buffer to file named camera_cuda_greay.yuv.copy this file to folder 07_video_convert,run the command:
./video_convert camera_cuda_grey.yuv 640 480 GREY camera_cuda_yuv420.yuv 640 480 YUV420M

process printf message is:
Failed to query video capbilities: Inappropriate ioctl for device
libv4l2_nvvidconv (0):(774) (INFO): Allocating (10) OUTPUT PLANE BUFFERS layout=0
libv4l2_nvvidconv (0):(790) (INFO): Allocating (10) CAPTURE PLANE BUFFERS layout=0
Could not read complete frame from input file
File read complete.
App run was successful

NOTE: camera_cuda_yuv420.yuv size is 821.8 MB
camera_cuda_yuv420.yuv size is 723 MB

what can these infomation demonstrated? is there any connection to my question pre comment mentioned?

Hi feng.baoying,
You can check via 7yuv http://datahammer.de/

Hi feng.baoying,
Please apply the following to 12_camera_v4l2_cuda

ctx->vic_pixfmt = V4L2_PIX_FMT_NV12M;
+// clean UV plane
+    void *data;
+    NvBuffer::NvBufferPlane &plane = buffer->planes[1];
+    data = (void *) plane.data;
+    memset(data, 128, v4l2_buf->m.planes[1].bytesused);

    // Render the frame into display
    if (v4l2_buf->m.planes[0].bytesused)
        ctx->renderer->render(buffer->planes[0].fd);

grey is actually Y plane of NV12M/YUV420M. If you clean UV plane, you can see grey output.

Hi DaneLLL.
Aplly the code above to 12_camera_v4l2_cuda, the video displayed is grey. Thanak you.
But I still have problems:
1、when ctx->vic_pixfmt = V4L2_PIX_FMT_YUV420M, add the other code, why the video displayed is colorful(grey is actually Y plane of NV12M/YUV420M)?
2、when ctx->vic_pixfmt = V4L2_PIX_FMT_YUV420M or other value such as V4L2_PIX_FMT_NV12M,V4L2_PIX_FMT_NV12M and so on,what is the data in buffer->planes[0] and buffer->planes[1]? Is there data in buffer->planes[2] and what is the data in buffer->planes[2]?
expected your reply. Thanks!

Hi feng.baoying,
You can keep vic_pixfmt = V4L2_PIX_FMT_YUV420M and do

+// clean UV plane
+    void *data;
+    NvBuffer::NvBufferPlane &plane1 = buffer->planes[1];
+    data = (void *) plane1.data;
+    memset(data, 128, v4l2_buf->m.planes[1].bytesused);
+    NvBuffer::NvBufferPlane &plane2 = buffer->planes[2];
+    data = (void *) plane2.data;
+    memset(data, 128, v4l2_buf->m.planes[2].bytesused);

buffer->planes[0] is Y plane(grey plane).

Below link is about NV12 and YUV420
https://wiki.videolan.org/YUV/

Hi DaneLLL.
The test result as follow:

when ctx->vic_pixfmt = V4L2_PIX_FMT_YUV420M, do:
+// clean UV plane

  • void *data;
  • NvBuffer::NvBufferPlane &plane1 = buffer->planes[1];
  • data = (void *) plane1.data;
  • memset(data, 128, v4l2_buf->m.planes[1].bytesused);
  • NvBuffer::NvBufferPlane &plane2 = buffer->planes[2];
  • data = (void *) plane2.data;
  • memset(data, 128, v4l2_buf->m.planes[2].bytesused);
    the video displayed is grey.

but when ctx->vic_pixfmt = V4L2_PIX_FMT_GREY, do:
+// clean UV plane

  • void *data;
  • NvBuffer::NvBufferPlane &plane1 = buffer->planes[1];
  • data = (void *) plane1.data;
  • memset(data, 128, v4l2_buf->m.planes[1].bytesused);
  • NvBuffer::NvBufferPlane &plane2 = buffer->planes[2];
  • data = (void *) plane2.data;
  • memset(data, 128, v4l2_buf->m.planes[2].bytesused);
    the video displayed is colorful.

buffer->planes[0] is not Y plane(grey plane) when ctx->vic_pixfmt = V4L2_PIX_FMT_GREY?
expected your reply. Thanks!

Hi feng.baoying,
By setting ctx->vic_pixfmt = V4L2_PIX_FMT_GREY, buffer->planes[0] is Y plane(grey plane) and you cannot touch UV plane. UV plane is with valid data so that it is rendered out with color.