-215
opencv
runtime_error
ai_generated
partial
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' 中
cv2.error: OpenCV(4.6.0) /tmp/opencv-4.6.0/modules/videoio/src/cap.cpp:293: error: (-215:Assertion failed) frame_size.width > 0 && frame_size.height > 0 in function 'CvCapture_FFMPEG::open'
ID: opencv/video-capture-frame-size-mismatch
75%修复率
85%置信度
1证据数
2023-03-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.5.5 | active | — | — | — |
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
根因分析
视频文件无法打开,因为帧尺寸为零或负数,通常是由于文件损坏、不支持的编解码器或缺少编解码器库。
English
Video file cannot be opened because the frame dimensions are zero or negative, often due to a corrupted file, unsupported codec, or missing codec library.
官方文档
https://docs.opencv.org/4.x/d8/dfe/classcv_1_1VideoCapture.html#a57c0e81e83e60f36c83027dc2a188e80解决方案
-
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`
-
Install FFmpeg with full codec support: `sudo apt-get install ffmpeg libavcodec-extra` or `brew install ffmpeg` on macOS.
-
Try a different video backend: `cap = cv2.VideoCapture('video.mp4', cv2.CAP_FFMPEG)` or `cap = cv2.VideoCapture('video.mp4', cv2.CAP_GSTREAMER)`
无效尝试
常见但无效的做法:
-
90% 失败
Changing the video file extension doesn't fix the underlying codec or corruption issue.
-
70% 失败
Setting CAP_PROP_FRAME_WIDTH/HEIGHT before opening won't help if the file itself has zero dimensions.
-
50% 失败
Reinstalling opencv-python doesn't add missing system codec libraries like libavcodec.