{"record":{"id":"bc561301aaf01c59","repo":"langchain-ai/deepagents","slug":"video-stream-time-base-is-zero-cannot-determine-f","errorCode":null,"errorMessage":"Video stream time_base is zero; cannot determine frame timestamps","messagePattern":"Video stream time_base is zero; cannot determine frame timestamps","errorType":"exception","errorClass":"VideoExtractionError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/_video.py","lineNumber":169,"sourceCode":"    except ValueError as exc:\n        raise VideoExtractionError(str(exc)) from exc\n    rate = float(sampling_rate)\n    duration = float(duration_seconds)\n\n    av = _import_av()\n    container = _open_video_container(av, content)\n    backend_error_types = _video_backend_error_types(av)\n    try:\n        try:\n            video_stream = _find_video_stream(container)\n            raw_time_base = video_stream.time_base\n            if raw_time_base is None:\n                msg = \"Video stream has no time_base; cannot determine frame timestamps\"\n                raise VideoExtractionError(msg)\n            time_base = float(raw_time_base)\n            if time_base == 0.0:\n                msg = \"Video stream time_base is zero; cannot determine frame timestamps\"\n                raise VideoExtractionError(msg)\n            stream_start_seconds = _stream_start_seconds(video_stream, time_base)\n            if offset_seconds > 0:\n                # `seek` keeps the math correct across containers that already sit\n                # at a non-zero timeline (e.g. trimmed clips).\n                start_pts = _stream_start_pts(video_stream) + int(offset_seconds / time_base)\n                container.seek(start_pts, any_frame=False, backward=True, stream=video_stream)\n\n            blocks = list(\n                _sample_frames_in_window(\n                    container.decode(video_stream),\n                    offset_seconds=offset_seconds,\n                    duration_seconds=float(duration),\n                    sampling_rate=rate,\n                    time_base=time_base,\n                    stream_start_seconds=stream_start_seconds,\n                    deadline_seconds=time.monotonic() + MAX_VIDEO_DECODE_SECONDS,\n                    decode_error_types=backend_error_types,\n                )","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/_video.py#L151-L187","documentation":"A stream time_base of zero is mathematically unusable for timestamp conversion (division by zero), so extract_video_frames raises VideoExtractionError when float(video_stream.time_base) == 0.0.","triggerScenarios":"extract_video_frames on a video whose stream reports time_base equal to zero — seen with corrupted files, degenerate container metadata, or synthetic streams from faulty encoders.","commonSituations":"Truncated or corrupted uploads; programmatically generated videos with incorrect timing metadata; storage/transcoding pipelines that mangled stream headers.","solutions":["Re-encode or remux the file with ffmpeg to fix stream metadata.","Validate the video with ffprobe before extraction.","Replace the source file — the container metadata is corrupt.","Catch VideoExtractionError and skip/report the file as undecodable."],"exampleFix":"// before\nframes = extract_video_frames(corrupt_bytes)\n// after\nif ffprobe_reports_valid_timebase(\"clip.mp4\"):\n    frames = extract_video_frames(read(\"clip.mp4\"))","handlingStrategy":"try-catch","validationCode":"def time_base_is_usable(stream) -> bool:\n    tb = getattr(stream, \"time_base\", None)\n    return tb is not None and float(tb) != 0.0","typeGuard":null,"tryCatchPattern":"try:\n    frames = extract_video_frames(content, offset_seconds=0, duration_seconds=5)\nexcept VideoExtractionError as exc:\n    if \"time_base is zero\" in str(exc):\n        return {\"error\": \"Video metadata is corrupt; re-encode the file with ffmpeg\"}\n    raise","preventionTips":["Verify media integrity at ingest (ffprobe duration and time_base checks).","Re-encode programmatic/generated videos with standard tooling before storage.","Reject zero-duration or zero-rate streams in upload validators.","Catch VideoExtractionError per-file so one bad file cannot fail a batch."],"tags":["video","media-metadata","pyav"],"backgroundTag":"invalid-stream-time-base","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}