-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:Assertion failed) frame_size.width > 0 && frame_size.height > 0 in function 'CvCapture_FFMPEG::open'

ID: opencv/video-capture-frame-size-mismatch

Also available as: JSON · Markdown · 中文
75%Fix Rate
85%Confidence
1Evidence
2023-03-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.5 active — — —
4.6.0 active — — —
4.7.0 active — — —
4.8.0 active — — —

Root Cause

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.

generic

中文

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

Official Documentation

https://docs.opencv.org/4.x/d8/dfe/classcv_1_1VideoCapture.html#a57c0e81e83e60f36c83027dc2a188e80

Workarounds

  1. 80% success 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`
    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. 75% success Install FFmpeg with full codec support: `sudo apt-get install ffmpeg libavcodec-extra` or `brew install ffmpeg` on macOS.
    Install FFmpeg with full codec support: `sudo apt-get install ffmpeg libavcodec-extra` or `brew install ffmpeg` on macOS.
  3. 70% success Try a different video backend: `cap = cv2.VideoCapture('video.mp4', cv2.CAP_FFMPEG)` or `cap = cv2.VideoCapture('video.mp4', cv2.CAP_GSTREAMER)`
    Try a different video backend: `cap = cv2.VideoCapture('video.mp4', cv2.CAP_FFMPEG)` or `cap = cv2.VideoCapture('video.mp4', cv2.CAP_GSTREAMER)`

中文步骤

  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)`

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Changing the video file extension doesn't fix the underlying codec or corruption issue.

  2. 70% fail

    Setting CAP_PROP_FRAME_WIDTH/HEIGHT before opening won't help if the file itself has zero dimensions.

  3. 50% fail

    Reinstalling opencv-python doesn't add missing system codec libraries like libavcodec.