# cv2.error: OpenCV(4.6.0) /tmp/opencv-4.6.0/modules/videoio/src/cap.cpp:293: error: (-215:断言失败) frame_size.width > 0 && frame_size.height > 0 在函数 'CvCapture_FFMPEG::open' 中

- **ID:** `opencv/video-capture-frame-size-mismatch`
- **领域:** opencv
- **类别:** runtime_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

视频文件无法打开，因为帧尺寸为零或负数，通常是由于文件损坏、不支持的编解码器或缺少编解码器库。

## 版本兼容性

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

## 解决方案

1. ```
   Verify the video file with ffprobe: `ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 input.mp4`. If dimensions are 0x0, re-encode the video: `ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4`
   ```
2. ```
   Install FFmpeg with full codec support: `sudo apt-get install ffmpeg libavcodec-extra` or `brew install ffmpeg` on macOS.
   ```
3. ```
   Try a different video backend: `cap = cv2.VideoCapture('video.mp4', cv2.CAP_FFMPEG)` or `cap = cv2.VideoCapture('video.mp4', cv2.CAP_GSTREAMER)`
   ```

## 无效尝试

- **** — Changing the video file extension doesn't fix the underlying codec or corruption issue. (90% 失败率)
- **** — Setting CAP_PROP_FRAME_WIDTH/HEIGHT before opening won't help if the file itself has zero dimensions. (70% 失败率)
- **** — Reinstalling opencv-python doesn't add missing system codec libraries like libavcodec. (50% 失败率)
