Comfy-Org/ComfyUI · error · ValueError

Could not verify video duration from source: {e}

Error message

Could not verify video duration from source: {e}

What it means

When max_duration is set, upload_video_to_comfyapi must first read the source duration; if video.get_duration() itself throws, the helper wraps it as ValueError('Could not verify video duration from source: ...'). Note the inner over-limit ValueError is also caught here, so its message appears in the chain — but the primary trigger is get_duration() failing.

Source

Thrown at comfy_api_nodes/util/upload_helpers.py:154

    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}"
        ) from e
    video_bytes_io.seek(0)

    return await upload_file_to_comfyapi(cls, video_bytes_io, filename, upload_mime_type, wait_label)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Read the appended original error — it names why probing failed.
  2. Re-mux the file to set duration metadata: ffmpeg -i in.mp4 -c copy out.mp4.
  3. Re-export as standard MP4 (H.264/AAC) if the container is exotic.
  4. Verify the file plays in ffprobe/VLC before uploading.
Defensive patterns

Strategy: validation

Validate before calling

try:
    duration = video.get_duration()
except Exception:
    raise ValueError('Source has no readable duration metadata; re-mux with ffmpeg -c copy')

Try / catch

try:
    url = await upload_video_to_comfyapi(cls, video, max_duration=10)
except ValueError as e:
    if 'Could not verify video duration' in str(e):
        # fix metadata, then retry
        raise
    if 'exceeds the maximum' in str(e):
        raise  # user must trim
    raise

Prevention

When it happens

Trigger: VideoInput.get_duration() raising on unreadable/corrupt media, a container without duration metadata, a codec PyAV cannot probe, or a stream whose duration is unknown (live capture, some WebM/MKV files).

Common situations: Corrupted or truncated video files; screen recordings or pipe-produced streams missing header duration; exotic containers; a file with a mismatched extension.

Related errors


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