Comfy-Org/ComfyUI · error · ValueError
Video frame count must be at most {max_frame_count}, got {fr
Error message
Video frame count must be at most {max_frame_count}, got {frame_count} What it means
Raised by validate_video_frame_count() in comfy_api_nodes/util/validation_utils.py when a video passed to an API node has more frames than the provider's max_frame_count. It is the upper-bound counterpart of the minimum check on the next line; the guard exists so over-long clips fail locally with a clear message instead of burning a paid API request or producing a provider-side 400. get_frame_count() failures are swallowed (logged) and skip validation entirely.
Source
Thrown at comfy_api_nodes/util/validation_utils.py:151
if max_duration is not None and duration > max_duration + epsilon:
raise ValueError(f"Video duration must be at most {max_duration}s, got {duration}s")
def validate_video_frame_count(
video: Input.Video,
min_frame_count: int | None = None,
max_frame_count: int | None = None,
):
try:
frame_count = video.get_frame_count()
except Exception as e:
logging.error("Error getting frame count of video: %s", e)
return
if min_frame_count is not None and min_frame_count > frame_count:
raise ValueError(f"Video frame count must be at least {min_frame_count}, got {frame_count}")
if max_frame_count is not None and frame_count > max_frame_count:
raise ValueError(f"Video frame count must be at most {max_frame_count}, got {frame_count}")
def get_number_of_images(images):
if isinstance(images, torch.Tensor):
return images.shape[0] if images.ndim >= 4 else 1
return len(images)
def validate_audio_duration(
audio: Input.Audio,
min_duration: float | None = None,
max_duration: float | None = None,
) -> None:
sr = int(audio["sample_rate"])
dur = int(audio["waveform"].shape[-1]) / sr
eps = 1.0 / sr
if min_duration is not None and dur + eps < min_duration:
raise ValueError(f"Audio duration must be at least {min_duration}s, got {dur + eps:.2f}s")View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Trim or subsample the video before the node: cut the clip to <= max_frame_count frames (use a video trim/subsample node or re-export at a lower duration).
- Raise the output fps relationship arithmetic: frames = duration * fps; reduce duration or drop frames (e.g. take every 2nd frame) to get under the cap.
- Check the node's tooltip / provider docs for the exact frame limit and recalculate your clip length in frames, not seconds.
- If the limit is genuinely too small for your content, look for a chunked/iterative variant of the node or process the video in segments.
Example fix
# before: 30 s clip at 25 fps = 750 frames into a 300-frame-cap node validate_video_frame_count(video, max_frame_count=300) # raises # after: trim to 12 s before the node # (use a trim/video-combine node so get_frame_count() <= 300)
Defensive patterns
Strategy: validation
Validate before calling
import cv2
cap = cv2.VideoCapture(path)
frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)); fps = cap.get(cv2.CAP_PROP_FPS); cap.release()
assert frames <= MAX_FRAMES, f'{frames} frames exceeds cap {MAX_FRAMES} ({frames/fps:.1f}s at {fps}fps)' Try / catch
try: validate_video_frame_count(v, max_frame_count=N) except ValueError as e: raise UserVisibleError(str(e)) from e
Prevention
- Remember frames = duration x fps; compute both before connecting long clips.
- Trim upstream with a video-trim node sized to the provider cap.
- Process long content in segments rather than one oversized clip.
When it happens
Trigger: Connecting a long video to an api-node that calls validate_video_frame_count(video, max_frame_count=N) — e.g. lip-sync / video-extension nodes where providers cap input length (commonly 300 frames, 25 fps * N seconds). Any clip whose get_frame_count() exceeds N raises immediately at node execution time, before any HTTP request is made.
Common situations: User loads a multi-minute source video into a provider that only accepts ~10 s; frame rate mismatch after re-encoding inflates frame counts; or a workflow built for short clips is reused with long content. Providers frequently tighten limits between API versions, so an old workflow can start failing after a node-pack update.
Related errors
- Video frame count must be at least {min_frame_count}, got {f
- Reference video {i} is too short: {dur:.1f}s. Minimum durati
- Total reference video duration is {total_video_duration:.1f}
- The 'end_frame' input cannot be used simultaneously with 're
- The maximum number of reference images allowed is 6.
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/9b2fa11928ffb1b6.
Report an issue: GitHub.