{"record":{"id":"b9ef1def90c92782","repo":"affaan-m/ECC","slug":"cannot-open-src-grade","errorCode":null,"errorMessage":"cannot open {src}","messagePattern":"cannot open (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/taste-distillation/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-distillation/scripts/taste/grade.py#L761-L797","documentation":"grade_clip_direct reads frames itself and pipes raw RGB into ffmpeg. It uses OpenCV's VideoCapture to read the source, and if cap.isOpened() is False it raises RuntimeError('cannot open <src>'). OpenCV reports open failure for missing files and, more commonly, for files its backend cannot demux/decode. This check runs after sample_frames/probe, so the file usually exists and the failure is codec/backend related.","triggerScenarios":"VideoCapture(str(src)) fails on: a file with a codec OpenCV's backend cannot decode (e.g. HEVC/H.265 or ProRes with a plain ffmpeg-less OpenCV build), a container OpenCV cannot demux, a zero-byte or truncated download, or a valid file whose extension confuses backend selection.","commonSituations":"OpenCV (opencv-python-headless) built without FFMPEG/GStreamer support so almost no video opens; phone-recorded HEVC clips on a machine without HEVC support; files streamed/downloaded and still incomplete; NAS/network mount not mounted so path exists check passed but read fails.","solutions":["Confirm the file plays with ffplay src / decodes with ffmpeg -i src; if ffmpeg fails too, the file itself is bad - re-copy or re-export it.","Re-encode to a universally decodable intermediate first: ffmpeg -i src -c:v libx264 -pix_fmt yuv420p -c:a aac h264.mp4, then grade the intermediate.","Reinstall OpenCV with video backends: pip install opencv-python (not headless), or an OPENCV_FFMPEG-enabled build; set OPENCV_VIDEOIO_PRIORITY list if needed.","Try opening it yourself before calling to see the backend error: cap = cv2.VideoCapture(src); print(cap.isOpened(), cap.get(cv2.CAP_PROP_FOURCC)).","Verify the path is reachable and complete: check file size > 0 and that network volumes are mounted."],"exampleFix":"// before\ngrade_clip_direct('clip_h265.mov', 'out.mp4')  # RuntimeError: cannot open clip_h265.mov\n// after\nsubprocess.run(['ffmpeg','-y','-i','clip_h265.mov','-c:v','libx264','-pix_fmt','yuv420p','clip_h264.mp4'], check=True)\ngrade_clip_direct('clip_h264.mp4', 'out.mp4')","handlingStrategy":"fallback","validationCode":"import cv2\ncap = cv2.VideoCapture(str(src))\nok = cap.isOpened()\ncap.release()\nif not ok:\n    raise SystemExit(f'OpenCV cannot open {src}; re-encode to H.264 first')","typeGuard":null,"tryCatchPattern":"try:\n    grade_clip_direct(src, dst)\nexcept RuntimeError as e:\n    if 'cannot open' in str(e):\n        fixed = Path(src).with_suffix('.h264.mp4')\n        subprocess.run(['ffmpeg','-y','-i',str(src),'-c:v','libx264','-pix_fmt','yuv420p',str(fixed)], check=True)\n        grade_clip_direct(fixed, dst)\n    else:\n        raise","preventionTips":["Standardize all inputs to H.264/yuv420p MP4 before any OpenCV processing.","Use full opencv-python (not headless) when you need video I/O backends.","Check downloaded/incomplete files for zero size before processing.","Verify network mounts are present when sources live on shared storage."],"tags":["opencv","video","file-io","codec"],"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"}