{"record":{"id":"b34abfaa6de6e96f","repo":"roboflow/supervision","slug":"could-not-open-video-at-video-path","errorCode":null,"errorMessage":"Could not open video at {video_path}","messagePattern":"Could not open video at (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/supervision/utils/video.py","lineNumber":76,"sourceCode":"        \"\"\"Read video metadata from a file path.\n\n        Args:\n            video_path: Path to the video file.\n\n        Returns:\n            A `VideoInfo` instance with width, height, fps, and total_frames.\n\n        Examples:\n            ```python\n            import supervision as sv\n\n            video_info = sv.VideoInfo.from_video_path(video_path=\"<SOURCE_VIDEO_FILE>\")\n            # VideoInfo(width=3840, height=2160, fps=25.0, total_frames=538)\n            ```\n        \"\"\"\n        video = cv2.VideoCapture(video_path)\n        if not video.isOpened():\n            raise Exception(f\"Could not open video at {video_path}\")\n\n        width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))\n        height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))\n        fps = float(video.get(cv2.CAP_PROP_FPS))\n        total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))\n        video.release()\n        return VideoInfo(width, height, fps, total_frames)\n\n    @property\n    def resolution_wh(self) -> tuple[int, int]:\n        return self.width, self.height\n\n\nclass VideoSink:\n    \"\"\"\n    Context manager that saves video frames to a file using OpenCV.\n\n    Attributes:","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/utils/video.py#L58-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ninfo = sv.VideoInfo.from_video_path('<SOURCE_VIDEO_FILE>')\n\n// after\nvideo_path = '/data/videos/source.mp4'\nassert os.path.isfile(video_path), video_path\ninfo = sv.VideoInfo.from_video_path(video_path)","handlingStrategy":"validation","validationCode":"video_path = os.path.abspath(video_path)\nif not os.path.isfile(video_path):\n    raise FileNotFoundError(video_path)\ninfo = sv.VideoInfo.from_video_path(video_path)","typeGuard":null,"tryCatchPattern":"try:\n    info = sv.VideoInfo.from_video_path(p)\nexcept Exception as e:\n    if 'Could not open video' in str(e):\n        log.warning('skipping unreadable video: %s', p)\n        continue\n    raise","preventionTips":["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."],"tags":["video","opencv","file-io","path"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}