# VIDEOIO 错误：V4L2：流 0 的像素格式不受 OpenCV 支持

- **ID:** `opencv/videoio-camera-format-unsupported`
- **领域:** opencv
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

摄像头提供的像素格式（例如 MJPG、YUYV、NV12）OpenCV 的 V4L2 后端无法直接解码，需要转换。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.5.5 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.1 | active | — | — |
| 4.9.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **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% 失败率)
- **Setting CAP_PROP_FOURCC to 'MJPG' after opening camera** — The property must be set before opening the camera or on a closed capture. (85% 失败率)
- **Recompiling OpenCV with different V4L2 flags but not rebuilding the app** — The app links against the old library; a full rebuild is needed. (90% 失败率)
