How to display grayscale camera

I am debugging a grayscale camera,Some problems have arisen:

Currently the camera can capture a raw image through v4l-ctl and nvgstcapture capture video stream , but

Capture video stream through nvgstcapture is purple, how to modify it to grayscale?

help me

hello linchengy,

please note that, we did not support grayscale sensors by default.
I think you already done some implementation to extend support formats. please have a try to access camera sensor via v4l2src.
you may also check similar discussion thread, Topic 1036708 for reference.

hello JerryChang:

My modifications are as follows:
diff --git a/kernel/nvidia/drivers/media/platform/tegra/camera/camera_common.c b/kernel/nvidia/drivers/media/platform/tegra/camera/camera_common.c
index a37495c8..d3e95e28 100644
--- a/kernel/nvidia/drivers/media/platform/tegra/camera/camera_common.c
+++ b/kernel/nvidia/drivers/media/platform/tegra/camera/camera_common.c
@@ -85,6 +85,13 @@ static const struct camera_common_colorfmt camera_common_color_fmts[] = {
+       /* GRAY */
+       {
+               MEDIA_BUS_FMT_Y10_1X10, // Gray 10-bit
+               V4L2_COLORSPACE_RAW,
+               V4L2_PIX_FMT_Y10,
+       },

 struct camera_common_csi_io_pad_ctx {
diff --git a/kernel/nvidia/drivers/media/platform/tegra/camera/sensor_common.c b/kernel/nvidia/drivers/media/platform/tegra/camera/sensor_common.c
index 42864af7..e24922cb 100644
--- a/kernel/nvidia/drivers/media/platform/tegra/camera/sensor_common.c
+++ b/kernel/nvidia/drivers/media/platform/tegra/camera/sensor_common.c
@@ -214,6 +214,10 @@ static int extract_pixel_format(
                *format = V4L2_PIX_FMT_XBGGR10P;
        else if (strncmp(pixel_t, "bayer_xrggb10p", size) == 0)
                *format = V4L2_PIX_FMT_XRGGB10P;
+       else if (strncmp(pixel_t, "gray_y10", size) == 0) {
+               *format = V4L2_PIX_FMT_Y10;
+       }
        else {
                pr_err("%s: Need to extend format%s\n", __func__, pixel_t);
                return -EINVAL;
diff --git a/kernel/nvidia/drivers/media/platform/tegra/camera/vi/vi2_formats.h b/kernel/nvidia/drivers/media/platform/tegra/camera/vi/vi2_formats.h
index 31817030..98665566 100644
--- a/kernel/nvidia/drivers/media/platform/tegra/camera/vi/vi2_formats.h
+++ b/kernel/nvidia/drivers/media/platform/tegra/camera/vi/vi2_formats.h
@@ -127,5 +127,9 @@ static const struct tegra_video_format vi2_video_formats[] = {
                                YUV422_8, YUYV, "YUV 4:2:2 YUYV"),
        TEGRA_VIDEO_FORMAT(YUV422, 16, YVYU8_2X8, 2, 1, T_Y8_V8__Y8_U8,
                                YUV422_8, YVYU, "YUV 4:2:2 YVYU"),
+       /* GRAY */
+       TEGRA_VIDEO_FORMAT(RAW10, 10, Y10_1X10, 2, 1, T_R16_I,
+                               RAW10, Y10, "GRAY10"),

in .dts file:

csi_pixel_bit_depth = "10";
mode_type = "gray";
pixel_phase = "y";

v4l2-ctl --list-formats-ext Output is as follows:

nvidia@nvidia-desktop:~$ v4l2-ctl --list-formats-ext
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'Y10 '
        Name        : 10-bit Greyscale
                Size: Discrete 1456x1080
                        Interval: Discrete 0.017s (60.000 fps)

Applications Using GStreamer with V4L2 Source Plugin

Render the preview to a screen as follows:

nvidia@nvidia-desktop:~/workplace$ export DISPLAY=:0
nvidia@nvidia-desktop:~/workplace$ gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw, format=(string)Y10, width=(int)1440, height=(int)1080, framerate=(fraction)60/1' ! xvimagesink  -ev
WARNING: erroneous pipeline: could not link v4l2src0 to xvimagesink0, v4l2src0 can't handle caps video/x-raw, format=(string)Y10, width=(int)1440, height=(int)1080, framerate=(fraction)60/1

The following is successful through v4l-ctl

nvidia@nvidia-desktop:~/workplace$ v4l2-ctl --set-fmt-video=width=1440,height=1080,pixelformat=Y10 --stream-mmap --stream-count=1 -d /dev/video0 --stream-to=test.raw
< 9523809.52 fps

Accessing the camera sensor via v4l2src is a failure

If you look at v4l2src SRC (output) capabilities, you’ll see it only supports byte-aligned formats:

gst-inspect-1.0 v4l2src
Pad Templates:
   SRC template: 'src'
                 format: { RGB16, BGR, RGB, <b>GRAY8, GRAY16_LE, GRAY16_BE</b>, YVU9, YV12, YUY2, YVYU, UYVY, Y42B, Y41B, YUV9, NV12_64Z32, NV24, NV61, NV16, NV21, NV12, I420, BGRA, BGRx, ARGB, xRGB, BGR15, RGB15 }

So 10 bits format is not an option by default for gstreamer.
Does your camera provide other formats?
If not and you really want to use gstreamer with Y10, you would have to patch v4l2src plugin or patch your driver so it provides GRAY16_LE.

Ok, thank you for your answer