{"record":{"id":"4851717d8671b256","repo":"langchain-ai/deepagents","slug":"video-stream-has-no-time-base-cannot-determine-fr","errorCode":null,"errorMessage":"Video stream has no time_base; cannot determine frame timestamps","messagePattern":"Video stream has no time_base; cannot determine frame timestamps","errorType":"exception","errorClass":"VideoExtractionError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/_video.py","lineNumber":165,"sourceCode":"            offset_seconds=offset_seconds,\n            duration_seconds=duration_seconds,\n            sampling_rate=sampling_rate,\n        )\n    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,","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/_video.py#L147-L183","documentation":"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.","triggerScenarios":"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.","commonSituations":"Processing scraped or user-uploaded videos with unusual metadata; corrupted/partial downloads; codec/container combinations PyAV maps without a time base.","solutions":["Remux/transcode the file with ffmpeg (e.g. `ffmpeg -i in.mp4 -c copy fixed.mp4`) to regenerate stream metadata.","Re-encode the video: `ffmpeg -i in.mp4 -c:v libx264 out.mp4`.","Inspect with ffprobe to confirm the stream lacks time_base.","Catch VideoExtractionError and report the file as unsupported."],"exampleFix":"// before\nframes = extract_video_frames(broken_bytes)\n# VideoExtractionError: no time_base\n// after\nsubprocess.run([\"ffmpeg\", \"-y\", \"-i\", \"in.mp4\", \"-c:v\", \"libx264\", \"fixed.mp4\"])\nframes = extract_video_frames(open(\"fixed.mp4\", \"rb\").read())","handlingStrategy":"try-catch","validationCode":"import av\ndef stream_has_time_base(data: bytes) -> bool:\n    try:\n        c = av.open(data)\n        s = next((s for s in c.streams if s.type == \"video\"), None)\n        ok = s is not None and s.time_base is not None\n        c.close()\n        return ok\n    except Exception:\n        return False","typeGuard":"def is_decodable_stream(stream) -> bool:\n    return stream is not None and stream.time_base is not None","tryCatchPattern":"try:\n    frames = extract_video_frames(content, offset_seconds=0, duration_seconds=5)\nexcept VideoExtractionError as exc:\n    if \"time_base\" in str(exc):\n        content = remux_with_ffmpeg(content)\n        frames = extract_video_frames(content, offset_seconds=0, duration_seconds=5)\n    else:\n        raise","preventionTips":["Validate uploads with ffprobe before processing.","Remux/transcode unusual containers to MP4/H.264 upfront.","Reject truncated or corrupt files at ingest time.","Keep PyAV/FFmpeg up to date for broader container support."],"tags":["video","media-metadata","pyav"],"backgroundTag":"missing-stream-time-base","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}