langchain-ai/deepagents · error · VideoExtractionError

Video stream has no time_base; cannot determine frame timest

Error message

Video stream has no time_base; cannot determine frame timestamps

What it means

PyAV reports frame timestamps relative to a stream time_base. If video_stream.time_base is None (some containers/streams expose no time base), frame timestamps cannot be computed, so VideoExtractionError is raised.

Source

Thrown at libs/deepagents/deepagents/middleware/_video.py:165

            offset_seconds=offset_seconds,
            duration_seconds=duration_seconds,
            sampling_rate=sampling_rate,
        )
    except ValueError as exc:
        raise VideoExtractionError(str(exc)) from exc
    rate = float(sampling_rate)
    duration = float(duration_seconds)

    av = _import_av()
    container = _open_video_container(av, content)
    backend_error_types = _video_backend_error_types(av)
    try:
        try:
            video_stream = _find_video_stream(container)
            raw_time_base = video_stream.time_base
            if raw_time_base is None:
                msg = "Video stream has no time_base; cannot determine frame timestamps"
                raise VideoExtractionError(msg)
            time_base = float(raw_time_base)
            if time_base == 0.0:
                msg = "Video stream time_base is zero; cannot determine frame timestamps"
                raise VideoExtractionError(msg)
            stream_start_seconds = _stream_start_seconds(video_stream, time_base)
            if offset_seconds > 0:
                # `seek` keeps the math correct across containers that already sit
                # at a non-zero timeline (e.g. trimmed clips).
                start_pts = _stream_start_pts(video_stream) + int(offset_seconds / time_base)
                container.seek(start_pts, any_frame=False, backward=True, stream=video_stream)

            blocks = list(
                _sample_frames_in_window(
                    container.decode(video_stream),
                    offset_seconds=offset_seconds,
                    duration_seconds=float(duration),
                    sampling_rate=rate,
                    time_base=time_base,

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Remux/transcode the file with ffmpeg (e.g. `ffmpeg -i in.mp4 -c copy fixed.mp4`) to regenerate stream metadata.
  2. Re-encode the video: `ffmpeg -i in.mp4 -c:v libx264 out.mp4`.
  3. Inspect with ffprobe to confirm the stream lacks time_base.
  4. Catch VideoExtractionError and report the file as unsupported.

Example fix

// before
frames = extract_video_frames(broken_bytes)
# VideoExtractionError: no time_base
// after
subprocess.run(["ffmpeg", "-y", "-i", "in.mp4", "-c:v", "libx264", "fixed.mp4"])
frames = extract_video_frames(open("fixed.mp4", "rb").read())
Defensive patterns

Strategy: try-catch

Validate before calling

import av
def stream_has_time_base(data: bytes) -> bool:
    try:
        c = av.open(data)
        s = next((s for s in c.streams if s.type == "video"), None)
        ok = s is not None and s.time_base is not None
        c.close()
        return ok
    except Exception:
        return False

Type guard

def is_decodable_stream(stream) -> bool:
    return stream is not None and stream.time_base is not None

Try / catch

try:
    frames = extract_video_frames(content, offset_seconds=0, duration_seconds=5)
except VideoExtractionError as exc:
    if "time_base" in str(exc):
        content = remux_with_ffmpeg(content)
        frames = extract_video_frames(content, offset_seconds=0, duration_seconds=5)
    else:
        raise

Prevention

When it happens

Trigger: extract_video_frames encountering a video stream whose time_base attribute is None — typically malformed files, exotic containers (raw or fragmented streams), or files produced by encoders that omit the time base.

Common situations: Processing scraped or user-uploaded videos with unusual metadata; corrupted/partial downloads; codec/container combinations PyAV maps without a time base.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/4851717d8671b256. Report an issue: GitHub.