{"record":{"id":"b82faba1f3f103e0","repo":"Comfy-Org/ComfyUI","slug":"video-duration-actual-duration-2f-s-exceeds-th","errorCode":null,"errorMessage":"Video duration ({actual_duration:.2f}s) exceeds the maximum allowed ({max_duration}s).","messagePattern":"Video duration \\((.+?)s\\) exceeds the maximum allowed \\((.+?)s\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/upload_helpers.py","lineNumber":149,"sourceCode":"\nasync def upload_video_to_comfyapi(\n    cls: type[IO.ComfyNode],\n    video: Input.Video,\n    *,\n    container: Types.VideoContainer = Types.VideoContainer.MP4,\n    codec: Types.VideoCodec = Types.VideoCodec.H264,\n    max_duration: int | None = None,\n    wait_label: str | None = \"Uploading\",\n) -> str:\n    \"\"\"\n    Uploads a single video to ComfyUI API and returns its download URL.\n    Uses the specified container and codec for saving the video before upload.\n    \"\"\"\n    if max_duration is not None:\n        try:\n            actual_duration = video.get_duration()\n            if actual_duration > max_duration:\n                raise ValueError(\n                    f\"Video duration ({actual_duration:.2f}s) exceeds the maximum allowed ({max_duration}s).\"\n                )\n        except Exception as e:\n            logging.error(\"Error getting video duration: %s\", str(e))\n            raise ValueError(f\"Could not verify video duration from source: {e}\") from e\n\n    upload_mime_type = f\"video/{container.value.lower()}\"\n    filename = f\"{uuid.uuid4()}.{container.value.lower()}\"\n\n    # Convert VideoInput to BytesIO using specified container/codec\n    video_bytes_io = BytesIO()\n    try:\n        video.save_to(video_bytes_io, format=container, codec=codec)\n    except Exception as e:\n        raise ValueError(\n            f\"Could not convert the input video to {container.value.upper()} for upload; \"\n            f\"the file may be corrupted or use an unsupported codec. \"\n            f\"Try re-exporting it as MP4 (H.264). Original error: {e}\"","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/upload_helpers.py#L131-L167","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Trim the clip to at most max_duration seconds before uploading (trim_video or an external tool).","Check the node's docs for the model's duration cap and match your source.","If the duration looks wrong, re-mux/re-encode the source so its container metadata is accurate.","As a last resort use a different endpoint/node without the cap — do not bypass the check, the server enforces it too."],"exampleFix":"// before\nurl = await upload_video_to_comfyapi(cls, video, max_duration=10)  # 30s clip\n\n// after\nvideo = trim_video(video, start_time=0.0, duration=10.0)\nurl = await upload_video_to_comfyapi(cls, video, max_duration=10)","handlingStrategy":"validation","validationCode":"MAX_DURATION = 10\nduration = video.get_duration()\nif duration > MAX_DURATION:\n    raise ValueError(f'Clip is {duration:.2f}s; trim to <= {MAX_DURATION}s before upload')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the model node's documented duration cap and trim sources beforehand.","Expose duration as a clamped widget in custom nodes (max = API limit).","Check get_duration() on loaded clips early in the workflow, not at upload time."],"tags":["video","upload","duration-limit","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}