{"record":{"id":"98175580dea3b4ac","repo":"affaan-m/ECC","slug":"cannot-open-src","errorCode":null,"errorMessage":"cannot open {src}","messagePattern":"cannot open (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/taste/grade.py","lineNumber":779,"sourceCode":"    half a gigabyte at no real cost in throughput.\n\n    Use this for the automated pipeline, where accuracy is what matters and\n    nobody is looking at the intermediate. Keep ``look.cube`` for Resolve,\n    where an artist wants a node they can dial back, reorder, or override -\n    and where a couple of units of chroma error is a starting point, not a\n    defect.\n    \"\"\"\n    import cv2 as _cv2\n\n    src, dst = Path(src), Path(dst)\n    from . import frames as _frames\n\n    source = analyze(_frames.sample_frames(src, n=n_measure))\n    info = _frames.probe(src)\n\n    cap = _cv2.VideoCapture(str(src))\n    if not cap.isOpened():\n        raise RuntimeError(f\"cannot open {src}\")\n\n    dst.parent.mkdir(parents=True, exist_ok=True)\n    cmd = [\n        \"ffmpeg\", \"-nostdin\", \"-loglevel\", \"error\", \"-y\",\n        \"-f\", \"rawvideo\", \"-pix_fmt\", \"rgb24\",\n        \"-s\", f\"{info.width}x{info.height}\", \"-r\", f\"{info.fps:.6f}\", \"-i\", \"-\",\n        \"-i\", str(src), \"-map\", \"0:v\", \"-map\", \"1:a?\", \"-c:a\", \"copy\",\n        \"-c:v\", \"libx264\", \"-crf\", str(crf), \"-pix_fmt\", \"yuv420p\", str(dst),\n    ]\n    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    buf: list[np.ndarray] = []\n\n    def flush() -> None:\n        if not buf:\n            return\n        arr = np.stack(buf)\n        out = transfer(arr, target=target, source=source, strength=strength,","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/taste/grade.py#L761-L797","documentation":"`grade_clip_direct()` reopens the source video with `cv2.VideoCapture` to stream raw RGB frames into a piped FFmpeg encoder, and raises a RuntimeError if OpenCV cannot open the file. Unlike the LUT path, this encoder reads frames directly, so it hard-fails before starting FFmpeg when the handle cannot be opened. Note that the earlier `sample_frames`/`probe` calls would usually catch the same problem first; this guard covers the reopened handle.","triggerScenarios":"Calling `grade_clip_direct(src, dst, ...)` where `cv2.VideoCapture(str(src)).isOpened()` is False — missing file, unreadable permissions, unsupported codec/container, or the file disappeared between measure and encode.","commonSituations":"Passing a directory or URL string OpenCV cannot treat as a local file; transient unmount of a network volume; codec unsupported by the OpenCV build while FFmpeg itself could handle it.","solutions":["Validate `Path(src).is_file()` and readability before calling grade_clip_direct().","If FFmpeg can decode it but OpenCV cannot, use `grade_clip()` (LUT via FFmpeg input) instead of the direct pipeline.","Re-encode the source to H.264 mp4 with FFmpeg to give OpenCV a decodable stream.","Confirm the file is still present/readable at encode time (network mounts, temp-file cleanup)."],"exampleFix":"// before\ngrade_clip_direct('raw/scene.mxf', 'out.mp4', lut)  # OpenCV can't open MXF\n// after\nimport cv2\nif not cv2.VideoCapture('raw/scene.mxf').isOpened():\n    subprocess.run(['ffmpeg','-i','raw/scene.mxf','-c:v','libx264','tmp.mp4'])\n    grade_clip_direct('tmp.mp4', 'out.mp4', lut)","handlingStrategy":"try-catch","validationCode":"import cv2\nfrom pathlib import Path\ncap = cv2.VideoCapture(str(src))\nok = cap.isOpened(); cap.release()\nif not ok or not Path(src).is_file():\n    raise FileNotFoundError(src)","typeGuard":"def direct_grade_possible(src: str | Path) -> bool:\n    import cv2\n    cap = cv2.VideoCapture(str(src)); ok = cap.isOpened(); cap.release()\n    return ok","tryCatchPattern":"try:\n    grade_clip_direct(src, dst, lut)\nexcept RuntimeError as e:\n    if str(e).startswith('cannot open '):\n        grade_clip(src, dst, lut)   # FFmpeg-input path decodes more formats\n    else:\n        raise","preventionTips":["Test-open the file with cv2.VideoCapture before the direct pipeline","Fall back to the FFmpeg-input grade path for exotic codecs","Keep sources on stable, mounted local storage during encode","Re-encode sources to mp4/H.264 at ingest"],"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"}