Comfy-Org/ComfyUI · error · ValueError

Audio duration must be at most {max_duration}s, got {dur - e

Error message

Audio duration must be at most {max_duration}s, got {dur - eps:.2f}s

What it means

Raised by validate_audio_duration() in comfy_api_nodes/util/validation_utils.py when an AUDIO input is longer than the provider's maximum. Duration is waveform length / sample_rate, minus a one-sample epsilon so a clip of exactly max_duration passes. Raised before any network call so oversized audio fails locally instead of on the provider side.

Source

Thrown at comfy_api_nodes/util/validation_utils.py:171

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")
    if max_duration is not None and dur - eps > max_duration:
        raise ValueError(f"Audio duration must be at most {max_duration}s, got {dur - eps:.2f}s")


def validate_string(
    string: str,
    strip_whitespace=True,
    field_name="prompt",
    min_length=None,
    max_length=None,
):
    if string is None:
        raise Exception(f"Field '{field_name}' cannot be empty.")
    if strip_whitespace:
        string = string.strip()
    if min_length and len(string) < min_length:
        raise Exception(
            f"Field '{field_name}' cannot be shorter than {min_length} characters; was {len(string)} characters long."
        )
    if max_length and len(string) > max_length:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Trim the audio to <= max_duration seconds before the node (audio trim/crop node or split into segments).
  2. Compute the exact duration first: audio['waveform'].shape[-1] / audio['sample_rate'] and compare against the node's documented cap.
  3. For long content, split into chunks and run the node per chunk, then recombine outputs.
  4. If the provider offers a higher-limit endpoint, switch to the corresponding node variant.

Example fix

# before: 45 s audio into validate_audio_duration(clip, max_duration=30.0)
# raises: Audio duration must be at most 30.0s, got 45.00s

# after: trim to first 30 s
max_samples = int(30.0 * clip['sample_rate'])
clip['waveform'] = clip['waveform'][..., :max_samples]
Defensive patterns

Strategy: validation

Validate before calling

dur = audio['waveform'].shape[-1] / audio['sample_rate']
if dur - 1.0 / audio['sample_rate'] > MAX_DUR:
    audio['waveform'] = audio['waveform'][..., :int(MAX_DUR * audio['sample_rate'])]

Try / catch

try: validate_audio_duration(audio, max_duration=MAX) except ValueError as e: raise RuntimeError(f'Audio too long: {e}') from e

Prevention

When it happens

Trigger: Passing an AUDIO tensor to a node calling validate_audio_duration(audio, max_duration=N): sync.so enforces 600 s, bytedance clip-context 30 s, Kling 300 s, Wan variants 29-60 s. A 45 s clip into validate_audio_duration(audio, max_duration=30.0) raises.

Common situations: Long podcast/music audio fed into a lip-sync or video-augmentation node with a permissive-looking UI; workflows reused across providers with different caps; audio whose real duration is underestimated because the user reasons in minutes while the cap is in seconds.

Related errors


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