C program to Capture Image using V4L2 driver API from PIXCI frame grabber connected to Camera

Hi All,

I want to capture a image and save it in to memory from the camera which is interfaced to a frame grabber card in Jetson AGX Xavier device, using a sample C program.

V4L2EXAM.txt (21.3 KB)

My Frame grabber card support pixci V42L drivers which is installed.

I have attached the C program here for your reference. I am able to successfully compile the program after fixing some compile errors.
But when I run the program, I am getting time out saying “select timeout**”

Any idea, how to rectify this and successfully capture the image.

More Details:
Frame grabber card is mf2280+ from Epix
Camera is Silicon Video - SV10C-CL
My Jetpack version is 5.1.2

Please guide me further regarding this image capturing and processing.

hello nagesh_accord,

let’s examine your sensor streaming,
please check developer guide, Approaches for Validating and Testing the V4L2 Driver.
you may use V4L2 IOCTL to verify basic camera functionality.

BTW,
what’s your real use-case for capturing an image?
you may give it a try with NVIDIA Multimedia API sample applications.

Thanks a lot for the reply.
I want to inform I am bit new to these camera - V4L2 related stuff, though I am understanding them very quickly reading the information day by day.
Kindly bear with me and my queries which may sound very trivial some times.
As I want to under the things from basic root level, I would be having some basic queries some times.

We had installed the vendor’s ( Epix) tool called XCAP and had verified successfully that we were able to see video after connecting the camera so I feel the sensor streaming is working fine.

When i tried executing the below command, it said, "v4l2-ctl not found… "
do we need to install some additional v4l2 utility for this command to be executed successfully?

$ v4l2-ctl

I still did not find time to try out use case from this link. Definitely will try out and see.
Mean while, could you let me know the below sample c program v4l2exam.txt is fine enough to work.

V4L2EXAM.txt (21.3 KB)

hello nagesh_accord,

you may install v4l2 utility via APT server, i.e. $ sudo apt-get install v4l-utils

I’ve went through the code quickly, it should be okay.
anyways, this sample seems doing the same thing as standard v4l2 IOCTL, you may start with v4l2 pipeline for quick checking.

Ok fine. Thanks.
I will try installing it. Hope this does not take too much memory as we have only 2-3 GB space left in partiotioned /dev/mmbclk0p1 memory.

Thanks for the updates.

V4L2 pipeline means you running the use cases using “v4l2-ctl” command and checking if things are working fine right?

Also wanted to share you the below link which provides details of the Pixci V4L2 driver support using the there framegrabber card

https://www.epixinc.com/support/app_v4l2.htm

please let me know your thoughts on this and any changes required in the sample v4lexam.c file to make it compatible with this Pixci v4l2 driver for imaging capturing and storing.

Note:
** Currently we are having some hardware issues with the frame grabber card or camera and things are not working. I would try out all this once the camera working setup is ready.**

In the mean time, I am trying to understanding as much information as possible to that I can do things much better later.
thanks

re-cap below from https://www.epixinc.com/support/app_v4l2.htm.

Typical exceptions are: (a) A digital camera that doesn’t output pixels in the normal left-to-right and top-to-bottom order

does it meant sensor is outputting interleaved contents?

Looks like ‘Yes’ seeing the description “left-to-right” and “top-to-bottom” and which is in contrast to the "progressive scan’ which is sequential in any one particular order.

however I have mailed the vendor about this for better confirmation.

I have pixci v4l2 driver source file, let me know, if you want for better understanding of there v4l2 driver.
Thanks.

actually, it’ll be not supported since we don’t have the deinterlacing support for Xavier (and also Orin) series.

Ok. However we had tested the pixci xcap tool(which has seperate pixci driver not pixci v4l2 driver is used) that we were able to see the video and it worked fine.

Please find the below reply from vendor about this query:

Many sensors are ‘readout’ in the ‘wrong’ order.
Some cameras correct the readout before sending
data via Camera Link. Some do not.

This can occur with interleaved video formats
or non-interleaved video formats.

If they do not, then our XCLIB corrects the order.
Our V4L2 driver does not correct
the order; this is to comply with Linux guidelines
to minimize CPU usage by drivers.

Hi Jerry,

Please find my observation as shown below:

  1. I tried executing the sample V4L2exam.c program, I had shared earlier , it compiled and later I executed it.
    Please find the output as shown below:

Not sure, if it is capturing the image and where it is saving it, if at all ?

  1. I tried V4l2-ctl use case method as shown below, it is giving pixelformat invalid argument error.

please let me know, what parameter we need to pass for pixelformat. I tried different values still same issue.

I am attaching the v4l2 driver file FYI.
v4l2_drv.txt (64.0 KB)

hello nagesh_accord,

please try $ v4l2-ctl -d /dev/video0 --list-formats-ext to dump the sensor supported formats.
note, it’s actually checking the sensor driver to report the property.

I remember trying this command yesterday and it displayed just the below information:

$ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Type : Video Capture

same for the command:

$ v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Type : Video Capture

hello nagesh_accord,

so… it means there’s no sensor formats available in the driver side.
please examine your sensor driver, you should have camera_common_frmfmt struct to assign sensor formats.

you may see-also reference drivers, such as ov5693’s mode definition.
$public_sources/kernel_src/kernel/nvidia/drivers/media/i2c/ov5693_mode_tbls.h
and… it should have some contents reported as following.

$ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
        Type: Video Capture

        [0]: 'BG10' (10-bit Bayer BGBG/GRGR)
                Size: Discrete 2592x1944
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 2592x1458
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 1280x720
                        Interval: Discrete 0.008s (120.000 fps)

How to find out which sensor driver my camera Silicon Video - SV10C-CL is using?

Also as per the pixci link I shared earlier it says the below information;
Should we take care of these steps with “pixcinit” before start using v4L2 API.

yes, as it indicate… video setup must be initialized before using the V4L2 API;
please follow-up with vendor as you’re working with a customize driver instead of native Jetpack release drivers.

Will try this step and see if it works.

Yes. But vendor says he provides support only for PIXCI@V4L2 driver related queries but not general linux V4L2 API.
I modified v4l2_capture.x file to write the image buffer data to a .raw file, but still the saved .raw file does not capture correct image.
Pls see, if we are missing something which is causing issue, not writing the data in correct format.

v4l2_capture_save_img_file.c.txt (19.9 KB)

I am able to get the below details with this command:

$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: ‘GRBG’ (8-bit Bayer GRGR/BGBG)
Size: Discrete 3840x2764
Interval: Discrete 0.141s (7.078 fps)

But, when I run the below command to capture a image using the pixelformt ‘GRBG’, I still get the below error, any idea. please let me know. Thanks.

$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=3840,height=2764 pixelformat=GRBG --set-ctrl bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=ov5693_11_Mar.raw --verbose
unknown arguments: pixelformat=GRBG

However, when I remove the pixelformat parameter and bypass_mode parameter and execute the command, I can see it saved a .raw image file. But it is full dark black colour image.

Following are some more commands which are working:

$ v4l2-ctl --list-framesizes GRBG
ioctl: VIDIOC_ENUM_FRAMESIZES
Size: Discrete 3840x2764

$ v4l2-ctl --list-frameintervals width=3840,height=2764,pixelformat=GRBG
ioctl: VIDIOC_ENUM_FRAMEINTERVALS
Interval: Discrete 0.141s (7.078 fps)

$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=3840,height=2764 --stream-mmap=1 --stream-count=3 --stream-to=ov5693_11_Mar.raw --verbose
VIDIOC_QUERYCAP: ok
VIDIOC_G_FMT: ok
VIDIOC_S_FMT: ok
Format Video Capture:
Width/Height : 3840/2764
Pixel Format : ‘GRBG’ (8-bit Bayer GRGR/BGBG)
Field : None
Bytes per Line : 3840
Size Image : 10613760
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Full Range)
Flags :
VIDIOC_REQBUFS returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_STREAMON returned 0 (Success)
cap dqbuf: 0 seq: 0 bytesused: 10613760 ts: 15330.052000 (timecode, ts-monotonic, ts-src-eof)
cap dqbuf: 1 seq: 0 bytesused: 10613760 ts: 15330.196000 delta: 144.000 ms (timecode, ts-monotonic, ts-src-eof)
cap dqbuf: 2 seq: 0 bytesused: 10613760 ts: 15330.336000 delta: 140.000 ms (timecode, ts-monotonic, ts-src-eof)

hello nagesh_accord,

is the dumped file really contain pixel data? please also gather kernel layer message for reference.
for instance, $ dmesg > klogs.txt

Will try out this,
Mean while wanted to update somethings which the vendor told:

  1. He says the image getting saved is in Bayer format from the camera via the frame grabber card and we need to do the conversion to RGB format explicitly before writing the buffer data to the image file. Could you please point me to the code where this conversion of Bayer to RGB format happens.