VideoCapture resolution fallback behavior across V4L2 and GStreamer backends
0 reputation · 11 Apr 2023, 15:20 UTC
0 reputation · 11 Apr 2023, 15:20 UTC
Request a specific frame resolution through VideoCapture::set(CAP_PROP_FRAME_WIDTH, ...) and CAP_PROP_FRAME_HEIGHT on Linux, then verify that the captured frames match the requested dimensions.
The OpenCV documentation does not guarantee that the requested width and height are honored. On V4L2 the driver may ignore the property if dynamic resolution changes are unsupported; on GStreamer the pipeline may negotiate a different resolution; on DirectShow the property is not implemented at all. When a resolution is unsupported, OpenCV silently falls back to the nearest supported resolution—often the device default—without raising an error or warning.
There is no cross-platform API in OpenCV to enumerate the resolutions a camera actually supports, so applications cannot programmatically discover valid values before calling set().
set()?32775 reputation · 11 Apr 2023, 23:11 UTC
OpenCV's VideoCapture::set does not guarantee that the requested resolution will be honored. When a requested resolution is unsupported, the backend typically falls back to the nearest supported resolution or the device's default, often doing so silently without returning an error.
Since there is no backend-agnostic event or callback to notify resolution changes, the only reliable pattern to detect a mismatch is to manually query the device properties immediately after attempting to set them.
cap.open().
cap.set(CAP_PROP_FRAME_WIDTH, width) and cap.set(CAP_PROP_FRAME_HEIGHT, height).
cap.get(CAP_PROP_FRAME_WIDTH) and cap.get(CAP_PROP_FRAME_HEIGHT).There is no cross-platform API within OpenCV to enumerate supported resolutions. To discover valid values without writing platform-specific ioctl or GStreamer code, you must use system-level tools:
v4l2-ctl -d /dev/video0 --list-formats- to see all supported pixel formats and resolutions.gst-inspect-1.0 vl2src to view the caps supported by the hardware source element.The behavior during the fallback depends heavily on how the underlying backend handles the request:
set() may be ignored entirely, or the driver may select the closest hardware-supported mode.CAP_PROP, GStreamer will negotiate the best compatible format based on available elements.Note: Neither OpenCV backend exposes a callback or property change notification. Polling the properties is the only supported method.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.