sgl-project/sglang · error · ValueError

No frames before start_time {start_time} in all_timestamps {

Error message

No frames before start_time {start_time} in all_timestamps {all_timestamps.tolist()}

What it means

Raised by segment_frame_selector when selecting frames in [start_time, end_time] yields no candidates AND there are also no frames at or before start_time to fall back to. This means the requested segment starts before the first timestamp in the decoded video (e.g. start_time earlier than frame 0, or timestamps all after the window).

Source

Thrown at python/sglang/srt/multimodal/processors/mimo_v2.py:720

            )
            max_pixels = max(min_pixels, min(max_pixels_per_frame, max_pixels))
            return min_pixels, max_pixels

        def segment_frame_selector(all_timestamps, start_time, end_time):
            """Select frame indices in [start_time, end_time). If none found, pick the nearest frame to the left."""
            if not isinstance(all_timestamps, torch.Tensor):
                all_timestamps = torch.tensor(all_timestamps)

            mask = (all_timestamps >= start_time) & (all_timestamps < end_time)
            candidate_indices = torch.where(mask)[0]

            if len(candidate_indices) == 0:
                left_mask = all_timestamps <= start_time
                left_indices = torch.where(left_mask)[0]
                if len(left_indices) > 0:
                    selected_frame_indices = left_indices[-1:].clone()
                else:
                    raise ValueError(
                        f"No frames before start_time {start_time} in all_timestamps {all_timestamps.tolist()}"
                    )
            else:
                selected_frame_indices = candidate_indices

            assert (
                len(selected_frame_indices) > 0
            ), f"No frames selected for segment {start_time} - {end_time} in all_timestamps {all_timestamps.tolist()}"
            return selected_frame_indices

        kwargs = self.prepare_video_kwargs(video_input)
        video = video_input.video

        if not isinstance(video, tuple):
            raise ValueError(
                f"video must be a tuple of (video_tensor, timestamps), but got {type(video)}. "
                "Video download and decoding should be done by sglang load_video before calling process_video."
            )

View on GitHub (pinned to 0132848349)

Solutions

  1. Validate that start_time <= min(timestamps) tolerance and end_time > start_time before calling
  2. Normalize time units (seconds) for start_time/end_time on both client and server
  3. For short videos, lower the sampling fps floor or extend end_time so at least one frame falls in the window

Example fix

# before
selector = proc.segment_frame_selector(timestamps, start_time=100, end_time=200)  # ms vs s
# after
selector = proc.segment_frame_selector(timestamps, start_time=0.1, end_time=0.2)  # seconds
Defensive patterns

Strategy: validation

Validate before calling

ts = timestamps.tolist()
assert ts and min(ts) <= start_time + 1e-6 and end_time > max(start_time, min(ts)), \
    f'segment [{start_time},{end_time}] has no frames; timestamps span [{min(ts)},{max(ts)}]'

Try / catch

try:
    idx = proc.segment_frame_selector(timestamps, start_time, end_time)
except ValueError as e:
    if 'No frames before start_time' in str(e):
        start_time = min(timestamps).item()  # clamp to first frame
        idx = proc.segment_frame_selector(timestamps, start_time, end_time)
    else:
        raise

Prevention

When it happens

Trigger: Calling process_video on a video whose sampled timestamps are all later than the requested start_time, and the start_time-relative candidate set within [start_time, end_time] is empty — e.g. segment start_time=0 with timestamps beginning at 0.5, plus a misaligned window where left_indices is also empty.

Common situations: Client sends video segment metadata with start_time earlier than the first decoded frame (pre-roll trimmed by decoder); mismatched time bases (milliseconds vs seconds); very short videos where fps sampling yields a single frame after the window.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/8f59c20cb38c4e58. Report an issue: GitHub.