{"record":{"id":"032e9ce7beb774ed","repo":"affaan-m/ECC","slug":"cannot-open-video-path","errorCode":null,"errorMessage":"cannot open video: {path}","messagePattern":"cannot open video: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/taste/frames.py","lineNumber":31,"sourceCode":"\n@dataclass\nclass VideoInfo:\n    path: Path\n    width: int\n    height: int\n    fps: float\n    frame_count: int\n\n    @property\n    def duration(self) -> float:\n        return self.frame_count / self.fps if self.fps else 0.0\n\n\ndef probe(path: str | Path) -> VideoInfo:\n    path = Path(path)\n    cap = cv2.VideoCapture(str(path))\n    if not cap.isOpened():\n        raise RuntimeError(f\"cannot open video: {path}\")\n    info = VideoInfo(\n        path=path,\n        width=int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),\n        height=int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)),\n        fps=float(cap.get(cv2.CAP_PROP_FPS)) or 24.0,\n        frame_count=int(cap.get(cv2.CAP_PROP_FRAME_COUNT)),\n    )\n    cap.release()\n    return info\n\n\ndef sample_frames(\n    path: str | Path,\n    n: int = 48,\n    max_edge: int = 512,\n    skip_edges: float = 0.02,\n) -> list[np.ndarray]:\n    \"\"\"Evenly sample ``n`` frames as float32 RGB in [0, 1].","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/taste/frames.py#L13-L49","documentation":"`probe()` opens a video with OpenCV's `cv2.VideoCapture`; if OpenCV cannot open the container or path, the cap is not marked as opened and the function raises a RuntimeError with the offending path. This is the library's guard against silently probing a nonexistent or unreadable video. It fires before any metadata (width, height, fps, frame count) is read.","triggerScenarios":"Calling `probe(path)` where the path does not exist, is a directory, has an unsupported/undecodable container or codec, or the file lacks read permissions — any case where `cap.isOpened()` returns False.","commonSituations":"Typos or wrong relative paths when passing CLI args; videos with codecs OpenCV's backend (FFmpeg build) does not support; corrupted downloads; files on unmounted network shares; OpenCV installed without FFmpeg/GStreamer video-IO support.","solutions":["Verify the path exists and is readable: `Path(path).is_file()` and `os.access(path, os.R_OK)` before calling probe().","Confirm OpenCV can decode the file's codec — check with `ffprobe <file>`; if the codec is unsupported, re-encode with FFmpeg (`ffmpeg -i in.mov -c:v libx264 out.mp4`).","Reinstall OpenCV with a FFmpeg-enabled wheel: `pip install --force-reinstall opencv-python` (avoid headless builds without video IO).","Convert exotic containers (e.g. .braw, HEVC variants) to mp4 before probing."],"exampleFix":"// before\ninfo = probe('footage/clip')          # directory, no extension\n// after\np = Path('footage/clip.mp4')\nif not p.is_file():\n    raise FileNotFoundError(p)\ninfo = probe(p)","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\np = Path(path)\nassert p.is_file(), f\"not a file: {p}\"\nassert os.access(p, os.R_OK), f\"not readable: {p}\"","typeGuard":"def is_probable_video(path: str | Path) -> bool:\n    p = Path(path)\n    return p.is_file() and p.suffix.lower() in {'.mp4', '.mov', '.mkv', '.avi', '.webm'}","tryCatchPattern":"try:\n    info = probe(p)\nexcept RuntimeError as e:\n    if str(e).startswith('cannot open video'):\n        logger.warning('unreadable video %s: %s', p, e)\n        return None\n    raise","preventionTips":["Always check is_file() and readability before video APIs","Transcode exotic codecs to H.264 mp4 as an ingest step","Install a full opencv-python build with FFmpeg video IO","Run ffprobe as a preflight sanity check on inputs"],"tags":["video","opencv","file-not-found","runtime-error"],"backgroundTag":"file-open-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}