{"record":{"id":"46f957bd16076f6e","repo":"langchain-ai/deepagents","slug":"failed-to-open-video-payload-exc","errorCode":null,"errorMessage":"Failed to open video payload: {exc}","messagePattern":"Failed to open video payload: (.+?)","errorType":"exception","errorClass":"VideoExtractionError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/_video.py","lineNumber":227,"sourceCode":"        raise ValueError(msg)\n    if duration_seconds <= 0:\n        msg = f\"duration_seconds must be > 0, got {duration_seconds!r}\"\n        raise ValueError(msg)\n\n\ndef _open_video_container(av: Any, content: bytes) -> Any:  # noqa: ANN401  # PyAV types are unavailable without the [video] extra\n    \"\"\"Open a video byte payload, normalizing PyAV's failure modes.\n\n    PyAV typically raises `av.error.InvalidDataError` for malformed inputs,\n    but it falls back to `OSError` when the system ffmpeg library is missing\n    or incompatible. Both surface to callers as `VideoExtractionError` so\n    the middleware does not have to distinguish between them.\n    \"\"\"\n    try:\n        return av.open(io.BytesIO(content))\n    except _video_backend_error_types(av) as exc:  # pragma: no cover - depends on host/input\n        msg = f\"Failed to open video payload: {exc}\"\n        raise VideoExtractionError(msg) from exc\n\n\ndef _video_backend_error_types(av: Any) -> tuple[type[BaseException], ...]:  # noqa: ANN401  # PyAV types are unavailable without the [video] extra\n    \"\"\"Return backend failures that should surface as `VideoExtractionError`.\"\"\"\n    errors: list[type[BaseException]] = [OSError]\n    av_error = getattr(av, \"error\", None)\n    for name in (\"FFmpegError\", \"InvalidDataError\"):\n        error_type = getattr(av_error, name, None)\n        if (\n            isinstance(error_type, type)\n            and issubclass(error_type, BaseException)\n            and not any(issubclass(error_type, existing) for existing in errors)\n        ):\n            errors.append(error_type)\n    return tuple(errors)\n\n\ndef _find_video_stream(container: Any) -> Any:  # noqa: ANN401  # PyAV types are unavailable without the [video] extra","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/_video.py#L209-L245","documentation":"PyAV failed to open the video byte payload, and `_open_video_container` normalizes every backend open failure (OSError, av.error types) into `VideoExtractionError`. This means the bytes are not decodable as a media container by the installed PyAV/FFmpeg.","triggerScenarios":"Passing truncated, corrupted, or non-video bytes (HTML error page, text, partially downloaded MP4) to `extract_video_frames`; unsupported codec/container for the installed FFmpeg build.","commonSituations":"Download interrupted mid-file; an API returned a JSON error body stored as .mp4; a codec (e.g. newer H.266) the bundled FFmpeg cannot demux.","solutions":["Verify the bytes are a real video (check magic bytes / try ffprobe on the saved file)","Re-download or re-export the video; confirm the download completed (Content-Length check)","Catch `VideoExtractionError` and treat the file as unsupported, skipping it","Upgrade the `deepagents[video]` extra / PyAV and FFmpeg to support newer containers"],"exampleFix":"// before\nresult = extract_video_frames(response.content, offset_seconds=0, duration_seconds=10, sampling_rate=1)\n// after\ntry:\n    result = extract_video_frames(response.content, offset_seconds=0, duration_seconds=10, sampling_rate=1)\nexcept VideoExtractionError as exc:\n    logger.warning(\"Skipping undecodable video: %s\", exc)\n    result = None","handlingStrategy":"try-catch","validationCode":"def looks_like_video(data: bytes) -> bool:\n    return data[:12].startswith((b'\\x00\\x00\\x00\\x18ftyp', b'\\x1a45dfa3', b'RIFF')) or b'ftyp' in data[:64]","typeGuard":"def is_nonempty_bytes(data: object) -> TypeGuard[bytes]:\n    return isinstance(data, bytes) and len(data) > 0","tryCatchPattern":"try:\n    result = extract_video_frames(content, offset_seconds=0, duration_seconds=10, sampling_rate=1)\nexcept VideoExtractionError as exc:\n    logger.warning(\"Unopenable video payload: %s\", exc)\n    result = None","preventionTips":["Verify downloads completed (size/checksum) before extraction","Check magic bytes or ffprobe the file before passing bytes","Keep PyAV/FFmpeg updated for newer container support"],"tags":["video","pyav","decoding","corrupt-input"],"backgroundTag":"video-decode-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}