Comfy-Org / Comfy-Org/ComfyUI

SaveVideo: avoid fatal avcodec_send_frame(22) on invalid audio tensors

Open
#13,192 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 7h
Merged PRs (30d)
158

Description

### Version
- Reproduced on `225c52f6` (`v0.18.1-20-gb0fd65e8`)

### Problem
`SaveVideo` can fail the entire prompt with:

```
av.error.ArgumentError: Invalid argument: 'avcodec_send_frame()' returned 22
```

Trace points to audio encode path in `VideoFromComponents.save_to()`.

### Repro pattern
- Workflows with video + audio (LTX pipelines, especially longer outputs) intermittently produce invalid audio tensors (NaN/Inf or out-of-range values).
- `save_to()` currently sends the frame to ffmpeg without sanitizing values and without a fallback path.

### Expected
- Video save should not hard-fail due to malformed audio tensor values.
- If audio track cannot be encoded, save video-only output and log warning.

### Proposed fix
In `comfy_api/latest/_input_impl/video_types.py`:
1. Sanitize waveform before encoder (`torch.nan_to_num(...).clamp(-1, 1)`).
2. Re-check encoded numpy buffer for non-finite values.
3. Wrap audio encode/mux in `try/except` and continue with video-only output on failure.
4. Mux helper supports packet/list return styles from pyav encode.

I have a patch prepared and will open a PR referencing this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.