vaige
Posts: 2
Joined: Thu Sep 21, 2023 2:02 pm

v4l2 supported formats

Thu Sep 21, 2023 2:58 pm

There seems to be some problems with the v4l2 driver on my raspberry pi 4b with rpi camera module v2. I'm running raspbian version: 6.1.21-v8+.

When I run v4l2-ctl --list-formats-ext I get following output:

ioctl: VIDIOC_ENUM_FMT
Type: Video Capture

[0]: 'YUYV' (YUYV 4:2:2)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[1]: 'UYVY' (UYVY 4:2:2)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[2]: 'YVYU' (YVYU 4:2:2)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[3]: 'VYUY' (VYUY 4:2:2)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[4]: 'RGBP' (16-bit RGB 5-6-5)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[5]: 'RGBR' (16-bit RGB 5-6-5 BE)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[6]: 'RGBO' (16-bit A/XRGB 1-5-5-5)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[7]: 'RGBQ' (16-bit A/XRGB 1-5-5-5 BE)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[8]: 'RGB3' (24-bit RGB 8-8-8)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[9]: 'BGR3' (24-bit BGR 8-8-8)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[10]: 'RGB4' (32-bit A/XRGB 8-8-8-8)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[11]: 'BA81' (8-bit Bayer BGBG/GRGR)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[12]: 'GBRG' (8-bit Bayer GBGB/RGRG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[13]: 'GRBG' (8-bit Bayer GRGR/BGBG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[14]: 'RGGB' (8-bit Bayer RGRG/GBGB)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[15]: 'pBAA' (10-bit Bayer BGBG/GRGR Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[16]: 'BG10' (10-bit Bayer BGBG/GRGR)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[17]: 'pGAA' (10-bit Bayer GBGB/RGRG Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[18]: 'GB10' (10-bit Bayer GBGB/RGRG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[19]: 'pgAA' (10-bit Bayer GRGR/BGBG Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[20]: 'BA10' (10-bit Bayer GRGR/BGBG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[21]: 'pRAA' (10-bit Bayer RGRG/GBGB Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[22]: 'RG10' (10-bit Bayer RGRG/GBGB)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[23]: 'pBCC' (12-bit Bayer BGBG/GRGR Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[24]: 'BG12' (12-bit Bayer BGBG/GRGR)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[25]: 'pGCC' (12-bit Bayer GBGB/RGRG Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[26]: 'GB12' (12-bit Bayer GBGB/RGRG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[27]: 'pgCC' (12-bit Bayer GRGR/BGBG Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[28]: 'BA12' (12-bit Bayer GRGR/BGBG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[29]: 'pRCC' (12-bit Bayer RGRG/GBGB Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[30]: 'RG12' (12-bit Bayer RGRG/GBGB)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[31]: 'pBEE' (14-bit Bayer BGBG/GRGR Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[32]: 'BG14' (14-bit Bayer BGBG/GRGR)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[33]: 'pGEE' (14-bit Bayer GBGB/RGRG Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[34]: 'GB14' (14-bit Bayer GBGB/RGRG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[35]: 'pgEE' (14-bit Bayer GRGR/BGBG Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[36]: 'GR14' (14-bit Bayer GRGR/BGBG)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[37]: 'pREE' (14-bit Bayer RGRG/GBGB Packed)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[38]: 'RG14' (14-bit Bayer RGRG/GBGB)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[39]: 'GREY' (8-bit Greyscale)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[40]: 'Y10P' (10-bit Greyscale (MIPI Packed))
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[41]: 'Y10 ' (10-bit Greyscale)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[42]: 'Y12P' (12-bit Greyscale (MIPI Packed))
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[43]: 'Y12 ' (12-bit Greyscale)
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[44]: 'Y14P' (14-bit Greyscale (MIPI Packed))
Size: Stepwise 16x16 - 16376x16376 with step 1/1
[45]: 'Y14 ' (14-bit Greyscale)
Size: Stepwise 16x16 - 16376x16376 with step 1/1


Those resolutions seem weird and there's no formats like MPEG or H264, that I've see others having.

Other problem is when I try to view supported formats in my c++ code, I get zero output (code works on my laptop).
Here is part of my code:
Camera(const std::string& name)
{
// Open camera device
if ((m_fd = open(name.c_str(), O_RDWR)) == -1)
{
perror(("Failed to open " + name).c_str());
}

// Query device capabilities
struct v4l2_capability cap;
if (ioctl(m_fd, VIDIOC_QUERYCAP, &cap) < 0)
{
perror("VIDIOC_QUERYCAP");
}

std::cout << "Driver: " << cap.driver << "\n";
std::cout << "Card: " << cap.card << "\n";
std::cout << "Bus info: " << cap.bus_info << "\n";
std::cout << "Version: " << cap.version << "\n";
std::cout << "Capabilities: " << cap.capabilities << "\n";

// Query available formats
struct v4l2_fmtdesc fmt;
fmt.index = 0;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
std::cout << "Supported formats:\n";
while (ioctl(m_fd, VIDIOC_ENUM_FMT, &fmt) != -1)
{
std::cout << '[' << fmt.index << "] " << fmt.description << std::endl;
fmt.index++;
}



Code output:

Driver: unicam
Card: unicam
Bus info: platform:fe801000.csi
Version: 393493
Capabilities: 2778726401
Supported formats:



When I run libcamera-still --list-cameras I get following output:

Available cameras
-----------------
0 : imx219 [3280x2464 10-bit RGGB] (/base/soc/i2c0mux/i2c@1/imx219@10)
Modes: 'SRGGB10_CSI2P' : 640x480 [103.33 fps - (1000, 752)/1280x960 crop]
1640x1232 [41.85 fps - (0, 0)/3280x2464 crop]
1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]
'SRGGB8' : 640x480 [103.33 fps - (1000, 752)/1280x960 crop]
1640x1232 [41.85 fps - (0, 0)/3280x2464 crop]
1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]

I'm able to record video using libcamera-apps, and v4l2-ctl --stream-mmap seems to work, until I try to use some of the 'supported' pixel formats v4l2-ctl --stream-mmap responds with: VIDIOC_STREAMON returned -1.

My raspberry pi is at a remote location so I can't just reinstall the OS.
Here is some thing I have already tried:
apt update && apt upgrade
I did run sudo rpi-update.
I have rebooted multiple times.

Any of those had zero effects on my issues.

Do you have any Ideas what could be the problem and what should I do?
I think I should reinstall all camera related drivers, but I tough rpi-update did just that?
I get to see my rpi live in a few weeks, so I can just do the os reinstall (like i allways do when these kind of problems occurs:D), but I would like to be able to run my code on it before that.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 15312
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: v4l2 supported formats

Thu Sep 21, 2023 5:50 pm

The deprecated legacy camera stack would expose processed formats such as YUV420, RGB (of various flavours), or having passed it through either H264 or MJPEG encoders.

Bullseye has switched to libcamera where /dev/video0 presents the raw typically Bayer frames from the image sensor, and libcamera then passes those through the ISP to create YUV or RGB images.
Also note that /dev/video0 is expecting all the subdevices to be configured through the Media Controller API, so just configuring the format is not enough. Again libcamera deals with all of this for you.

If you want to use the V4L2 API to obtain processed images with libcamera, then you need to look at the V4L2 emulation layer which is called libcamerify.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

vaige
Posts: 2
Joined: Thu Sep 21, 2023 2:02 pm

Re: v4l2 supported formats

Wed Sep 27, 2023 2:40 pm

Thank you, libcamera seems to work well. Although the camera code in libcamera-apps looks quite complicated for such a "simple" camera.

Return to “Troubleshooting”