{"record":{"id":"2698050096dbe883","repo":"Comfy-Org/ComfyUI","slug":"decoded-zero-audio-frames","errorCode":null,"errorMessage":"Decoded zero audio frames.","messagePattern":"Decoded zero audio frames\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/conversions.py","lineNumber":599,"sourceCode":"        in_sr = int(stream.codec_context.sample_rate)\n        out_sr = in_sr\n\n        frames: list[torch.Tensor] = []\n        n_channels = stream.channels or 1\n\n        for frame in af.decode(streams=stream.index):\n            arr = frame.to_ndarray()  # shape can be [C, T] or [T, C] or [T]\n            buf = torch.from_numpy(arr)\n            if buf.ndim == 1:\n                buf = buf.unsqueeze(0)  # [T] -> [1, T]\n            elif buf.shape[0] != n_channels and buf.shape[-1] == n_channels:\n                buf = buf.transpose(0, 1).contiguous()  # [T, C] -> [C, T]\n            elif buf.shape[0] != n_channels:\n                buf = buf.reshape(-1, n_channels).t().contiguous()  # fallback to [C, T]\n            frames.append(buf)\n\n    if not frames:\n        raise ValueError(\"Decoded zero audio frames.\")\n\n    wav = torch.cat(frames, dim=1)  # [C, T]\n    wav = _f32_pcm(wav)\n    return {\"waveform\": wav.unsqueeze(0).contiguous(), \"sample_rate\": out_sr}\n\n\ndef resize_mask_to_image(\n    mask: torch.Tensor,\n    image: torch.Tensor,\n    upscale_method=\"nearest-exact\",\n    crop=\"disabled\",\n    allow_gradient=True,\n    add_channel_dim=False,\n):\n    \"\"\"Resize mask to be the same dimensions as an image, while maintaining proper format for API calls.\"\"\"\n    _, height, width, _ = image.shape\n    mask = mask.unsqueeze(-1)\n    mask = mask.movedim(-1, 1)","sourceCodeStart":581,"sourceCodeEnd":617,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/conversions.py#L581-L617","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the downloaded byte count against Content-Length before decoding.","Save the bytes and try opening in ffplay/VLC to confirm truncation.","Retry the API request — truncated/empty media from a server glitch is usually transient.","If reproducible, capture the raw response and report to the API provider; the body is malformed audio."],"exampleFix":"// before\naudio = audio_bytes_to_audio_input(data)\n\n// after\nif len(data) < 1024:\n    raise ValueError(f'Suspiciously small audio payload: {len(data)} bytes')\naudio = audio_bytes_to_audio_input(data)","handlingStrategy":"retry","validationCode":"content_length = resp.headers.get('Content-Length')\nif content_length and len(audio_bytes) < int(content_length):\n    raise ValueError(f'Truncated download: {len(audio_bytes)}/{content_length} bytes')","typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    data = await fetch(url)\n    try:\n        audio = audio_bytes_to_audio_input(data)\n        break\n    except ValueError as e:\n        if 'zero audio frames' in str(e) and attempt < 2:\n            continue  # truncated download, retry\n        raise","preventionTips":["Verify downloaded size against Content-Length before parsing.","Treat empty-frame decodes as transient and retry once or twice.","Prefer resumable/verified downloads for large media."],"tags":["audio","pyav","truncated-download","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}