Comfy-Org/ComfyUI · error · ValueError
Could not determine frame count for file '{self.__file}'\nNo
Error message
Could not determine frame count for file '{self.__file}'\nNo frames exist for start_time {self.__start_time} What it means
When counting frames in a trim window, VideoFromFile seeks to start_pts and iterates until the first frame with pts >= start_pts. If the iterator exhausts without any frame reaching start_pts — the requested start_time lies beyond the last frame of the stream — the for/else raises, combining 'Could not determine frame count' with the fact that no frames exist at that start_time.
Source
Thrown at comfy_api/latest/_input_impl/video_types.py:266
if estimated_frames > 0:
return estimated_frames
# 3. Last resort: decode frames and count them (streaming)
start_time, duration = self.get_active_trim_window()
frame_count = 1
start_pts = int(start_time / video_stream.time_base)
end_pts = int((start_time + duration) / video_stream.time_base)
container.seek(start_pts, stream=video_stream)
frame_iterator = (
container.decode(video_stream)
if video_stream.codec.capabilities & 0x100
else container.demux(video_stream)
)
for frame in frame_iterator:
if frame.pts >= start_pts:
break
else:
raise ValueError(f"Could not determine frame count for file '{self.__file}'\nNo frames exist for start_time {self.__start_time}")
for frame in frame_iterator:
if frame.pts >= end_pts:
break
frame_count += 1
return frame_count
def get_frame_rate(self) -> Fraction:
"""
Returns the average frame rate of the video using container metadata
without decoding all frames.
"""
if isinstance(self.__file, io.BytesIO):
self.__file.seek(0)
with av.open(self.__file, mode="r") as container:
video_stream = self._get_first_video_stream(container)
# Preferred: use PyAV's average_rate (usually already a Fraction-like)
if video_stream.average_rate:View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Clamp start_time below the video's actual duration: start = min(start_time, get_duration() - 1/fps)
- Validate trim parameters against get_duration() before calling get_frame_count/as_trimmed
- If metadata duration was wrong, remux to fix the header (see duration error) so clamping works off real values
Example fix
// before count = video.get_frame_count(start_time=10.0) # clip is 8s long # after dur = video.get_duration() count = video.get_frame_count(start_time=min(10.0, dur - 0.1))
Defensive patterns
Strategy: validation
Validate before calling
dur = video.get_duration()
if start_time >= dur:
start_time = max(0.0, dur - 1.0 / float(video.get_frame_rate())) Prevention
- Clamp trim windows against the real duration before seeking
- Treat metadata durations as upper bounds and re-check after remux
When it happens
Trigger: Calling get_frame_count (or as_trimmed with a window) where start_time is at or after the end of the video, e.g. start_time >= duration, so every decoded frame has pts < start_pts.
Common situations: Trim node computes start_time from a larger assumed duration; user requests the last fraction of a clip whose real duration is shorter than metadata claims; off-by-one seek to end_pts exactly.
Related errors
- Custom alpha video frame count ({mask.shape[0]}) does not ma
- Video too short: need at least 16 frames for Moonvalley
- Failed to trim video: {str(e)}
- resize produced no frames (start_time={start_time}, duration
- {type(model).__name__} must implement map_context_window_to_
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/f02196b11e712d89.
Report an issue: GitHub.