run-llama/llama_index · error · ValueError

resolve_video returned zero bytes

Error message

resolve_video returned zero bytes

What it means

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.

Source

Thrown at llama-index-core/llama_index/core/base/llms/types.py:635

        """
        data_buffer = (
            self.video
            if isinstance(self.video, IOBase)
            else resolve_binary(
                raw_bytes=self.video,
                path=self.path,
                url=str(self.url) if self.url else None,
                as_base64=as_base64,
            )
        )

        # Check size by seeking to end and getting position
        data_buffer.seek(0, 2)  # Seek to end
        size = data_buffer.tell()
        data_buffer.seek(0)  # Reset to beginning

        if size == 0:
            raise ValueError("resolve_video returned zero bytes")
        return data_buffer

    def inline_url(self) -> str:
        b64 = self.resolve_video(as_base64=True)
        b64_str = b64.read().decode("utf-8")
        if self.video_mimetype:
            return f"data:{self.video_mimetype};base64,{b64_str}"
        return f"data:video;base64,{b64_str}"

    async def aestimate_tokens(self, *args: Any, **kwargs: Any) -> int:
        """
        Use TinyTag to estimate the duration of the video file and convert to tokens.

        Gemini estimates 263 tokens per second of video
        https://ai.google.dev/gemini-api/docs/tokens?lang=python
        """
        try:
            # First try tinytag

View on GitHub (pinned to afd0fef371)

Solutions

  1. Check size before building the block: os.path.getsize(path) > 0 / len(raw) > 0.
  2. For URL sources, download once, verify non-empty, then pass raw bytes or a verified path.
  3. Fix the upstream producer/downloader responsible for empty artifacts.

Example fix

# before
block = VideoBlock(path="intro.mp4")  # 0-byte file
buf = block.resolve_video(as_base64=True)

# after
if os.path.getsize("intro.mp4") == 0:
    raise RuntimeError("empty video file")
block = VideoBlock(path="intro.mp4")
buf = block.resolve_video(as_base64=True)
Defensive patterns

Strategy: validation

Validate before calling

import os
ok = (video_bytes and len(video_bytes) > 0) or (path and os.path.getsize(path) > 0)
if not ok:
    raise ValueError("video source is empty")

Try / catch

try:
    buf = block.resolve_video(as_base64=True)
except ValueError as e:
    if "zero bytes" in str(e):
        refetch_or_skip()
    else:
        raise

Prevention

When it happens

Trigger: VideoBlock(video=b"" or data=b""), a 0-byte video file, or a video URL that returns an empty response.

Common situations: Video ingestion where a downloader wrote an empty file; interrupted uploads; placeholder/fixture video records; expired signed URLs.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/0014cc1f9a113bd1. Report an issue: GitHub.