V4l2 - How can I find all formats supported by my web camera?

When running GStreamer pipelines the caps for the components including the camera are automatically negotiated. This will often result in a working pipeline but sometimes it is not exactly what you may want. You may want to chose a different video format provided by your camera.
So, how can we find out what formats are supported by the camera?

The TAPPAS application use the v4l2 / Video4Linux driver to support many cameras.

There is a tool available that can list all formats supported by v4l2 devices. You may need to install the following package.

sudo apt install v4l-utils

You can list all v4l2 devices with:

v4l2-ctl --list-devices

Example output

Logitech BRIO (usb-0000:00:14.0-2):
	/dev/video0
	/dev/video1
	/dev/video2
	/dev/video3

Note, not all of these devices are video outputs.

The following command will list all formats supported by a v4l2 device.

v4l2-ctl -d /dev/video0 --list-formats

Example output

ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'YUYV' (YUYV 4:2:2)
	[1]: 'MJPG' (Motion-JPEG, compressed)
	[2]: 'NV12' (Y/CbCr 4:2:0)

The extended list will provide more detailed information about a v4l2 device.

v4l2-ctl -d /dev/video0 --list-formats-ext

Example output

ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'MJPG' (Motion-JPEG, compressed)
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 960x540
			Interval: Discrete 0.033s (30.000 fps)
...
	[1]: 'YUYV' (YUYV 4:2:2)
		Size: Discrete 1280x720
			Interval: Discrete 0.100s (10.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
...

Note that in this example the YUYV format runs only at 10 fps compared to the MJPG format 30 fps at the maximum resolution.

2 Likes