Comfy-Org/ComfyUI · error · ValueError

Decoded zero audio frames.

Error message

Decoded zero audio frames.

What it means

After confirming an audio stream exists, audio_bytes_to_audio_input decodes it; if the decode loop yields zero frames it raises ValueError('Decoded zero audio frames.'). The container header advertises an audio stream but no packets decode — typically truncated or zero-length audio data.

Source

Thrown at comfy_api_nodes/util/conversions.py:599

        in_sr = int(stream.codec_context.sample_rate)
        out_sr = in_sr

        frames: list[torch.Tensor] = []
        n_channels = stream.channels or 1

        for frame in af.decode(streams=stream.index):
            arr = frame.to_ndarray()  # shape can be [C, T] or [T, C] or [T]
            buf = torch.from_numpy(arr)
            if buf.ndim == 1:
                buf = buf.unsqueeze(0)  # [T] -> [1, T]
            elif buf.shape[0] != n_channels and buf.shape[-1] == n_channels:
                buf = buf.transpose(0, 1).contiguous()  # [T, C] -> [C, T]
            elif buf.shape[0] != n_channels:
                buf = buf.reshape(-1, n_channels).t().contiguous()  # fallback to [C, T]
            frames.append(buf)

    if not frames:
        raise ValueError("Decoded zero audio frames.")

    wav = torch.cat(frames, dim=1)  # [C, T]
    wav = _f32_pcm(wav)
    return {"waveform": wav.unsqueeze(0).contiguous(), "sample_rate": out_sr}


def resize_mask_to_image(
    mask: torch.Tensor,
    image: torch.Tensor,
    upscale_method="nearest-exact",
    crop="disabled",
    allow_gradient=True,
    add_channel_dim=False,
):
    """Resize mask to be the same dimensions as an image, while maintaining proper format for API calls."""
    _, height, width, _ = image.shape
    mask = mask.unsqueeze(-1)
    mask = mask.movedim(-1, 1)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Check the downloaded byte count against Content-Length before decoding.
  2. Save the bytes and try opening in ffplay/VLC to confirm truncation.
  3. Retry the API request — truncated/empty media from a server glitch is usually transient.
  4. If reproducible, capture the raw response and report to the API provider; the body is malformed audio.

Example fix

// before
audio = audio_bytes_to_audio_input(data)

// after
if len(data) < 1024:
    raise ValueError(f'Suspiciously small audio payload: {len(data)} bytes')
audio = audio_bytes_to_audio_input(data)
Defensive patterns

Strategy: retry

Validate before calling

content_length = resp.headers.get('Content-Length')
if content_length and len(audio_bytes) < int(content_length):
    raise ValueError(f'Truncated download: {len(audio_bytes)}/{content_length} bytes')

Try / catch

for attempt in range(3):
    data = await fetch(url)
    try:
        audio = audio_bytes_to_audio_input(data)
        break
    except ValueError as e:
        if 'zero audio frames' in str(e) and attempt < 2:
            continue  # truncated download, retry
        raise

Prevention

When it happens

Trigger: Downloading a partially written or truncated audio file (connection cut mid-download); a stream with a valid header but no packets (server bug); a 0-byte or header-only response from the API.

Common situations: Flaky network truncating the download; the upstream service streaming an empty result on internal failure; a proxy timing out and returning the first chunk only; retrying a generation job that failed server-side.

Related errors


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