roboflow/supervision · critical · Exception
Could not open video at {video_path}
Error message
Could not open video at {video_path} What it means
Raised by VideoInfo.from_video_path() in supervision.utils.video when cv2.VideoCapture fails to open the given video_path (isOpened() is False). VideoInfo needs width, height, fps, and frame count metadata from the capture object, so an unopenable file aborts immediately. Unlike the generator path, this typically surfaces in setup/monitoring code that inspects videos before processing.
Source
Thrown at src/supervision/utils/video.py:76
"""Read video metadata from a file path.
Args:
video_path: Path to the video file.
Returns:
A `VideoInfo` instance with width, height, fps, and total_frames.
Examples:
```python
import supervision as sv
video_info = sv.VideoInfo.from_video_path(video_path="<SOURCE_VIDEO_FILE>")
# VideoInfo(width=3840, height=2160, fps=25.0, total_frames=538)
```
"""
video = cv2.VideoCapture(video_path)
if not video.isOpened():
raise Exception(f"Could not open video at {video_path}")
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = float(video.get(cv2.CAP_PROP_FPS))
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
video.release()
return VideoInfo(width, height, fps, total_frames)
@property
def resolution_wh(self) -> tuple[int, int]:
return self.width, self.height
class VideoSink:
"""
Context manager that saves video frames to a file using OpenCV.
Attributes:View on GitHub (pinned to 7f254d9784)
Solutions
- Check the file before calling: os.path.isfile(video_path) and print the absolute path.
- Replace template placeholders from docs with real paths.
- Reinstall/verify an ffmpeg-enabled OpenCV build and test with a known-good mp4 (H.264).
- For corrupt recordings, remux with ffmpeg -err_detect ignore_err -i in.mp4 -c copy fixed.mp4.
Example fix
// before
info = sv.VideoInfo.from_video_path('<SOURCE_VIDEO_FILE>')
// after
video_path = '/data/videos/source.mp4'
assert os.path.isfile(video_path), video_path
info = sv.VideoInfo.from_video_path(video_path) Defensive patterns
Strategy: validation
Validate before calling
video_path = os.path.abspath(video_path)
if not os.path.isfile(video_path):
raise FileNotFoundError(video_path)
info = sv.VideoInfo.from_video_path(video_path) Try / catch
try:
info = sv.VideoInfo.from_video_path(p)
except Exception as e:
if 'Could not open video' in str(e):
log.warning('skipping unreadable video: %s', p)
continue
raise Prevention
- Replace doc placeholders like <SOURCE_VIDEO_FILE> with real paths before running.
- Check existence and permissions of video assets in CI before tests that read them.
When it happens
Trigger: Calling sv.VideoInfo.from_video_path('<SOURCE_VIDEO_FILE>') with the placeholder unreplaced; a nonexistent or relative path; a remote stream URL unsupported by the installed OpenCV build; a corrupt or half-written file.
Common situations: Copy-pasted tutorial snippets with template placeholders; scripts run under a different cwd; CI environments where the video asset is missing from the checkout; ffmpeg-less opencv builds failing on some containers.
Related errors
- Could not open video at {source_path}
- Could not open video writer for {self.target_path}
- Could not read image from path: {image_path}
- Requested frames are outbound
- Reader thread raised: {item}
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/b34abfaa6de6e96f.
Report an issue: GitHub.