affaan-m/ECC · error · RuntimeError

cannot open

Error message

cannot open {src}

What it means

`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.

Solutions

  1. Validate `Path(src).is_file()` and readability before calling grade_clip_direct().
  2. If FFmpeg can decode it but OpenCV cannot, use `grade_clip()` (LUT via FFmpeg input) instead of the direct pipeline.
  3. Re-encode the source to H.264 mp4 with FFmpeg to give OpenCV a decodable stream.
  4. Confirm the file is still present/readable at encode time (network mounts, temp-file cleanup).

Example fix

// before
grade_clip_direct('raw/scene.mxf', 'out.mp4', lut)  # OpenCV can't open MXF
// after
import cv2
if not cv2.VideoCapture('raw/scene.mxf').isOpened():
    subprocess.run(['ffmpeg','-i','raw/scene.mxf','-c:v','libx264','tmp.mp4'])
    grade_clip_direct('tmp.mp4', 'out.mp4', lut)
Defensive patterns

Strategy: try-catch

Validate before calling

import cv2
from pathlib import Path
cap = cv2.VideoCapture(str(src))
ok = cap.isOpened(); cap.release()
if not ok or not Path(src).is_file():
    raise FileNotFoundError(src)

Type guard

def direct_grade_possible(src: str | Path) -> bool:
    import cv2
    cap = cv2.VideoCapture(str(src)); ok = cap.isOpened(); cap.release()
    return ok

Try / catch

try:
    grade_clip_direct(src, dst, lut)
except RuntimeError as e:
    if str(e).startswith('cannot open '):
        grade_clip(src, dst, lut)   # FFmpeg-input path decodes more formats
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/98175580dea3b4ac. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-application/scripts/taste/grade.py:779

    half a gigabyte at no real cost in throughput.

    Use this for the automated pipeline, where accuracy is what matters and
    nobody is looking at the intermediate. Keep ``look.cube`` for Resolve,
    where an artist wants a node they can dial back, reorder, or override -
    and where a couple of units of chroma error is a starting point, not a
    defect.
    """
    import cv2 as _cv2

    src, dst = Path(src), Path(dst)
    from . import frames as _frames

    source = analyze(_frames.sample_frames(src, n=n_measure))
    info = _frames.probe(src)

    cap = _cv2.VideoCapture(str(src))
    if not cap.isOpened():
        raise RuntimeError(f"cannot open {src}")

    dst.parent.mkdir(parents=True, exist_ok=True)
    cmd = [
        "ffmpeg", "-nostdin", "-loglevel", "error", "-y",
        "-f", "rawvideo", "-pix_fmt", "rgb24",
        "-s", f"{info.width}x{info.height}", "-r", f"{info.fps:.6f}", "-i", "-",
        "-i", str(src), "-map", "0:v", "-map", "1:a?", "-c:a", "copy",
        "-c:v", "libx264", "-crf", str(crf), "-pix_fmt", "yuv420p", str(dst),
    ]
    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

    buf: list[np.ndarray] = []

    def flush() -> None:
        if not buf:
            return
        arr = np.stack(buf)
        out = transfer(arr, target=target, source=source, strength=strength,

View on GitHub (pinned to 8321021c54)