{"record":{"id":"727558edd4c373c2","repo":"affaan-m/ECC","slug":"cannot-open-video-path-frames","errorCode":null,"errorMessage":"cannot open video: {path}","messagePattern":"cannot open video: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/taste-distillation/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-distillation/scripts/taste/frames.py#L13-L49","documentation":"probe() opens the video with OpenCV's VideoCapture and raises immediately if the backend cannot open the file. It means the file path does not exist, is unreadable, or is in a format/codec OpenCV's backend cannot decode.","triggerScenarios":"Calling probe() with a nonexistent path, a path without read permission, a corrupted file, or a codec/container (e.g. some HEVC/AV1 variants) unsupported by the installed OpenCV build.","commonSituations":"Typo'd relative path; downloading failed earlier so the file is missing/zero bytes; OpenCV built without FFmpeg support for the codec; trying to probe a URL or a directory instead of a file.","solutions":["Verify the path exists and is a readable file: Path(path).is_file() and size > 0","Check the file plays with ffprobe/ffplay to rule out corruption or exotic codecs","Install an OpenCV build with FFmpeg (pip install opencv-python) or re-encode the video to H.264 MP4","Confirm you are passing a local file path, not a URL (download it first)"],"exampleFix":"// before\nprobe(\"out/video.mp4\")  # FileNotFoundError -> RuntimeError: cannot open video\n// after\npath = Path(\"out/video.mp4\")\nif not path.is_file() or path.stat().st_size == 0:\n    raise FileNotFoundError(path)\ninfo = probe(path)","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(path)\nassert p.is_file() and p.stat().st_size > 0, f\"bad video input: {p}\"","typeGuard":null,"tryCatchPattern":"try:\n    info = probe(path)\nexcept RuntimeError as e:\n    if str(e).startswith(\"cannot open video\"):\n        reencode_with_ffmpeg(path); info = probe(path)\n    else: raise","preventionTips":["Check file existence and size before probing","Run ffprobe on files from untrusted pipelines","Use opencv-python (FFmpeg-enabled) builds","Re-encode exotic codecs to H.264 MP4"],"tags":["video","opencv","file-io"],"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"}