{"record":{"id":"28b5b755bea56c01","repo":"microsoft/autogen","slug":"cannot-open-video-file-video-path","errorCode":null,"errorMessage":"Cannot open video file {video_path}","messagePattern":"Cannot open video file (.+?)","errorType":"exception","errorClass":"IOError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/tools.py","lineNumber":75,"sourceCode":"    for segment in segments:\n        start: float = segment[\"start\"]\n        end: float = segment[\"end\"]\n        text: str = segment[\"text\"]\n        transcription_with_timestamps += f\"[{start:.2f} - {end:.2f}] {text}\\n\"\n\n    return transcription_with_timestamps\n\n\ndef get_video_length(video_path: str) -> str:\n    \"\"\"\n    Returns the length of the video in seconds.\n\n    :param video_path: Path to the video file.\n    :return: Duration of the video in seconds.\n    \"\"\"\n    cap = cv2.VideoCapture(video_path)\n    if not cap.isOpened():\n        raise IOError(f\"Cannot open video file {video_path}\")\n    fps = cap.get(cv2.CAP_PROP_FPS)\n    frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)\n    duration = frame_count / fps\n    cap.release()\n\n    return f\"The video is {duration:.2f} seconds long.\"\n\n\ndef save_screenshot(video_path: str, timestamp: float, output_path: str) -> None:\n    \"\"\"\n    Captures a screenshot at the specified timestamp and saves it to the output path.\n\n    :param video_path: Path to the video file.\n    :param timestamp: Timestamp in seconds.\n    :param output_path: Path to save the screenshot. The file format is determined by the extension in the path.\n    \"\"\"\n    cap = cv2.VideoCapture(video_path)\n    if not cap.isOpened():","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/tools.py#L57-L93","documentation":"get_video_length() creates a cv2.VideoCapture for video_path and raises IOError when cap.isOpened() returns False, meaning OpenCV could not open the file at all. Typical root causes are a nonexistent/unreadable path, an unsupported container/codec, or an OpenCV build without the required video I/O backend (e.g. opencv-python-headless installed without ffmpeg support).","triggerScenarios":"Calling get_video_length('missing.mp4'), passing a directory or URL instead of a local file, a video encoded with a codec the installed OpenCV build cannot decode, or running in a slim container where libffmpeg/gstreamer backend libraries are absent.","commonSituations":"Agent workflows where the LLM hallucinates a video filename, downloading a video to a path different from the one passed in, Docker images based on python:*-slim without ffmpeg/codec system libraries, or corrupted/incomplete downloads.","solutions":["Verify the file exists and is readable before calling: os.path.isfile(video_path)","Confirm the path is a local file, not a URL; download it first if needed","Install full OpenCV with video support: pip install opencv-python (not a build stripped of ffmpeg)","On Linux containers install system ffmpeg/libsm6/libxext6 and gstreamer plugins, or verify the codec with ffprobe video.mp4"],"exampleFix":"// before\nlength = get_video_length('/downloads/clip.mp4')  # may not exist yet\n\n// after\nimport os\nif not os.path.isfile(path):\n    raise FileNotFoundError(path)\nlength = get_video_length(path)","handlingStrategy":"validation","validationCode":"import os, cv2\ndef can_open_video(p: str) -> bool:\n    if not os.path.isfile(p):\n        return False\n    cap = cv2.VideoCapture(p)\n    ok = cap.isOpened()\n    cap.release()\n    return ok","typeGuard":null,"tryCatchPattern":"try:\n    length = get_video_length(path)\nexcept IOError as e:\n    if not os.path.isfile(path):\n        raise FileNotFoundError(path) from e\n    raise RuntimeError(f'OpenCV cannot decode {path}; check codecs/backend: {e}') from e","preventionTips":["Verify os.path.isfile before any video tool call","Test one representative file with cv2.VideoCapture in your target container at build time","Prefer H.264/MP4 sources for cross-platform OpenCV support"],"tags":["opencv","video","file-io","codec","video-surfer"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}