opencv
runtime_error
ai_generated
partial
VIDEOIO ERROR: V4L2: Pixel format of stream 0 is not supported by OpenCV
ID: opencv/videoio-camera-format-unsupported
82%Fix Rate
83%Confidence
1Evidence
2023-06-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 4.5.5 | active | — | — | — |
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.1 | active | — | — | — |
| 4.9.0 | active | — | — | — |
Root Cause
The camera provides a pixel format (e.g., MJPG, YUYV, NV12) that OpenCV's V4L2 backend cannot decode directly without conversion.
generic中文
摄像头提供的像素格式(例如 MJPG、YUYV、NV12)OpenCV 的 V4L2 后端无法直接解码,需要转换。
Official Documentation
https://docs.opencv.org/4.x/dd/d43/tutorial_py_video_display.htmlWorkarounds
-
85% success Before opening the camera, set the desired pixel format using CAP_PROP_FOURCC: cap = cv2.VideoCapture(0); cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M','J','P','G'))
Before opening the camera, set the desired pixel format using CAP_PROP_FOURCC: cap = cv2.VideoCapture(0); cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M','J','P','G')) -
78% success Use the GStreamer backend instead: cap = cv2.VideoCapture('v4l2src ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
Use the GStreamer backend instead: cap = cv2.VideoCapture('v4l2src ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
中文步骤
Before opening the camera, set the desired pixel format using CAP_PROP_FOURCC: cap = cv2.VideoCapture(0); cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M','J','P','G'))Use the GStreamer backend instead: cap = cv2.VideoCapture('v4l2src ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
Dead Ends
Common approaches that don't work:
-
Installing v4l-utils and running v4l2-ctl to change format without restarting the app
70% fail
The format change is not picked up by an already-opened VideoCapture; need to reopen.
-
Setting CAP_PROP_FOURCC to 'MJPG' after opening camera
85% fail
The property must be set before opening the camera or on a closed capture.
-
Recompiling OpenCV with different V4L2 flags but not rebuilding the app
90% fail
The app links against the old library; a full rebuild is needed.