Comfy-Org/ComfyUI · error · ValueError

Video frame count must be at least {min_frame_count}, got {f

Error message

Video frame count must be at least {min_frame_count}, got {frame_count}

What it means

Raised by validate_video_frame_count() in comfy_api_nodes/util/validation_utils.py when an API video-generation node receives a video whose frame count is below the provider's minimum. The check calls video.get_frame_count() and compares against min_frame_count; it exists because upstream APIs (e.g. Kling, LTX, Wan lip-sync/audio nodes) reject too-short clips with worse error messages or waste a paid API call. Note that if get_frame_count() itself throws, the helper logs and returns silently — this ValueError only fires when the count was successfully read and is still too low.

Source

Thrown at comfy_api_nodes/util/validation_utils.py:149

    if min_duration is not None and min_duration - epsilon > duration:
        raise ValueError(f"Video duration must be at least {min_duration}s, got {duration}s")
    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

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Increase the source video length: load a longer clip or repeat/extend frames (e.g. VHS_VideoCombine settings or a frame-duplication node) so frame_count >= min_frame_count.
  2. Check the node's documentation tooltip for the provider's minimum frame count (often 2 for start/end-frame nodes) and pick inputs accordingly.
  3. If the video unexpectedly reports a low frame count, re-encode or reload the file — a corrupt container can cause get_frame_count() to under-report, though that usually takes the silent-log path instead.
  4. If you control the workflow, switch to a node variant that accepts images (first/last frame image inputs) instead of a video when you only have stills.

Example fix

// before: 1-frame video fed to a node requiring min_frame_count=2
validate_video_frame_count(video, min_frame_count=2)  # raises ValueError

// after: duplicate the frame or supply a real clip
# in the workflow: use a LoadImage + image-based node variant, or
# pad the video to >= 2 frames before connecting it
Defensive patterns

Strategy: validation

Validate before calling

# ComfyUI VIDEO object: probe via cv2/VHS-style loader, or trust the source node
# If you have the file path:
import cv2
cap = cv2.VideoCapture(path)
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
cap.release()
assert frame_count >= MIN_FRAMES, f'need >= {MIN_FRAMES} frames, got {frame_count}'

Try / catch

In a custom node wrapper: try: validate_video_frame_count(v, min_frame_count=N) except ValueError as e: return (ui_message(f'Input video rejected: {e}'),)

Prevention

When it happens

Trigger: Feeding a short video into an api-node that calls validate_video_frame(video, min_frame_count=N) (e.g. video-to-video, first-last-frame, or lip-sync nodes in comfy_api_nodes/nodes_kling.py / nodes_wan.py / nodes_ltxv.py) with fewer frames than the provider requires. Typical call: validate_video_frame_count(video, min_frame_count=2) with a single-frame video.

Common situations: User connects a single still image loaded as a 1-frame video (VHS VideoLoad or LoadVideo with a short clip), trims a clip too aggressively, or a upstream node emits fewer frames than requested. Also happens when fps/duration misconfiguration makes an exported clip shorter than expected.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/88e4038ac0b140a8. Report an issue: GitHub.