# VIDEOIO ERROR: V4L2: Pixel format of stream 0 is not supported by OpenCV

- **ID:** `opencv/videoio-camera-format-unsupported`
- **Domain:** opencv
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The camera provides a pixel format (e.g., MJPG, YUYV, NV12) that OpenCV's V4L2 backend cannot decode directly without conversion.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.5 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.1 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

1. **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'))** (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'))
   ```
2. **Use the GStreamer backend instead: cap = cv2.VideoCapture('v4l2src ! videoconvert ! appsink', cv2.CAP_GSTREAMER)** (78% success)
   ```
   Use the GStreamer backend instead: cap = cv2.VideoCapture('v4l2src ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
   ```

## Dead Ends

- **Installing v4l-utils and running v4l2-ctl to change format without restarting the app** — The format change is not picked up by an already-opened VideoCapture; need to reopen. (70% fail)
- **Setting CAP_PROP_FOURCC to 'MJPG' after opening camera** — The property must be set before opening the camera or on a closed capture. (85% fail)
- **Recompiling OpenCV with different V4L2 flags but not rebuilding the app** — The app links against the old library; a full rebuild is needed. (90% fail)
