Comfy-Org/ComfyUI · error · ValueError

Video duration ({actual_duration:.2f}s) exceeds the maximum

Error message

Video duration ({actual_duration:.2f}s) exceeds the maximum allowed ({max_duration}s).

What it means

upload_video_to_comfyapi enforces an optional max_duration: it calls video.get_duration() and rejects clips longer than the API's limit with a ValueError naming both actual and maximum. The limit exists because the receiving API rejects or truncates over-long uploads.

Source

Thrown at comfy_api_nodes/util/upload_helpers.py:149

async def upload_video_to_comfyapi(
    cls: type[IO.ComfyNode],
    video: Input.Video,
    *,
    container: Types.VideoContainer = Types.VideoContainer.MP4,
    codec: Types.VideoCodec = Types.VideoCodec.H264,
    max_duration: int | None = None,
    wait_label: str | None = "Uploading",
) -> str:
    """
    Uploads a single video to ComfyUI API and returns its download URL.
    Uses the specified container and codec for saving the video before upload.
    """
    if max_duration is not None:
        try:
            actual_duration = video.get_duration()
            if actual_duration > max_duration:
                raise ValueError(
                    f"Video duration ({actual_duration:.2f}s) exceeds the maximum allowed ({max_duration}s)."
                )
        except Exception as e:
            logging.error("Error getting video duration: %s", str(e))
            raise ValueError(f"Could not verify video duration from source: {e}") from e

    upload_mime_type = f"video/{container.value.lower()}"
    filename = f"{uuid.uuid4()}.{container.value.lower()}"

    # Convert VideoInput to BytesIO using specified container/codec
    video_bytes_io = BytesIO()
    try:
        video.save_to(video_bytes_io, format=container, codec=codec)
    except Exception as e:
        raise ValueError(
            f"Could not convert the input video to {container.value.upper()} for upload; "
            f"the file may be corrupted or use an unsupported codec. "
            f"Try re-exporting it as MP4 (H.264). Original error: {e}"

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Trim the clip to at most max_duration seconds before uploading (trim_video or an external tool).
  2. Check the node's docs for the model's duration cap and match your source.
  3. If the duration looks wrong, re-mux/re-encode the source so its container metadata is accurate.
  4. As a last resort use a different endpoint/node without the cap — do not bypass the check, the server enforces it too.

Example fix

// before
url = await upload_video_to_comfyapi(cls, video, max_duration=10)  # 30s clip

// after
video = trim_video(video, start_time=0.0, duration=10.0)
url = await upload_video_to_comfyapi(cls, video, max_duration=10)
Defensive patterns

Strategy: validation

Validate before calling

MAX_DURATION = 10
duration = video.get_duration()
if duration > MAX_DURATION:
    raise ValueError(f'Clip is {duration:.2f}s; trim to <= {MAX_DURATION}s before upload')

Prevention

When it happens

Trigger: Calling upload with max_duration set (e.g. 10 for an image-to-video API whose model accepts at most 10s) while the supplied VideoInput's duration exceeds it.

Common situations: Feeding a long stock clip into a first-frame/last-frame video model; forgetting to trim before upload; source duration misreported by its container so get_duration() returns the full original length.

Related errors


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