{"record":{"id":"0014cc1f9a113bd1","repo":"run-llama/llama_index","slug":"resolve-video-returned-zero-bytes","errorCode":null,"errorMessage":"resolve_video returned zero bytes","messagePattern":"resolve_video returned zero bytes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/base/llms/types.py","lineNumber":635,"sourceCode":"        \"\"\"\n        data_buffer = (\n            self.video\n            if isinstance(self.video, IOBase)\n            else resolve_binary(\n                raw_bytes=self.video,\n                path=self.path,\n                url=str(self.url) if self.url else None,\n                as_base64=as_base64,\n            )\n        )\n\n        # Check size by seeking to end and getting position\n        data_buffer.seek(0, 2)  # Seek to end\n        size = data_buffer.tell()\n        data_buffer.seek(0)  # Reset to beginning\n\n        if size == 0:\n            raise ValueError(\"resolve_video returned zero bytes\")\n        return data_buffer\n\n    def inline_url(self) -> str:\n        b64 = self.resolve_video(as_base64=True)\n        b64_str = b64.read().decode(\"utf-8\")\n        if self.video_mimetype:\n            return f\"data:{self.video_mimetype};base64,{b64_str}\"\n        return f\"data:video;base64,{b64_str}\"\n\n    async def aestimate_tokens(self, *args: Any, **kwargs: Any) -> int:\n        \"\"\"\n        Use TinyTag to estimate the duration of the video file and convert to tokens.\n\n        Gemini estimates 263 tokens per second of video\n        https://ai.google.dev/gemini-api/docs/tokens?lang=python\n        \"\"\"\n        try:\n            # First try tinytag","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/llms/types.py#L617-L653","documentation":"Raised by VideoBlock.resolve_video when the buffer resolved from raw bytes, path, or URL is empty (zero bytes). It is the video equivalent of the image/audio zero-byte guards and stops empty video payloads before an API call.","triggerScenarios":"VideoBlock(video=b\"\" or data=b\"\"), a 0-byte video file, or a video URL that returns an empty response.","commonSituations":"Video ingestion where a downloader wrote an empty file; interrupted uploads; placeholder/fixture video records; expired signed URLs.","solutions":["Check size before building the block: os.path.getsize(path) > 0 / len(raw) > 0.","For URL sources, download once, verify non-empty, then pass raw bytes or a verified path.","Fix the upstream producer/downloader responsible for empty artifacts."],"exampleFix":"# before\nblock = VideoBlock(path=\"intro.mp4\")  # 0-byte file\nbuf = block.resolve_video(as_base64=True)\n\n# after\nif os.path.getsize(\"intro.mp4\") == 0:\n    raise RuntimeError(\"empty video file\")\nblock = VideoBlock(path=\"intro.mp4\")\nbuf = block.resolve_video(as_base64=True)","handlingStrategy":"validation","validationCode":"import os\nok = (video_bytes and len(video_bytes) > 0) or (path and os.path.getsize(path) > 0)\nif not ok:\n    raise ValueError(\"video source is empty\")","typeGuard":null,"tryCatchPattern":"try:\n    buf = block.resolve_video(as_base64=True)\nexcept ValueError as e:\n    if \"zero bytes\" in str(e):\n        refetch_or_skip()\n    else:\n        raise","preventionTips":["Validate video artifacts right after download/creation.","Log and quarantine 0-byte media files upstream."],"tags":["llama-index","video","empty-input","multimodal"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}