NormalizeAudioLoudness: NaN loudness measurement poisons audio tensor, crashing AAC encoder on save

Open
#1,985 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
numpy, python

Research direction

Read nodes_utility.py and locate loudness_norm, especially the integrated-loudness check and normalization call. Reproduce with very short or near-silent audio passed through NormalizeAudioLoudness; done means invalid loudness measurements leave the audio unchanged and the resulting output no longer causes the AAC save error.

Written by the indexing model from the issue text.

Description

When NormalizeAudioLoudness receives audio that is very short or near-silence, pyloudnorm's integrated loudness measurement returns NaN rather than a valid LUFS value. The existing guard only checks abs(loudness) > 100, which evaluates to False for NaN, so normalization proceeds — multiplying every sample by NaN and producing a fully NaN waveform tensor.

The node itself does not crash. The NaN tensor is silently passed downstream, and the error surfaces only when the video save node attempts to encode the audio with AAC:

!!! Exception during processing !!!
[Errno 22] Invalid argument: 'avcodec_send_frame()'; last error log: [aac] Input contains (near) NaN/+-Inf
...
av.error.ValueError: [Errno 22] Invalid argument: 'avcodec_send_frame()'; last error log: [aac] Input contains (near) NaN/+-Inf
Root cause:

In nodes_utility.py, loudness_norm:

loudness = meter.integrated_loudness(audio_array)
if abs(loudness) > 100: # abs(NaN) > 100 → False — guard does not fire
return audio_array
normalized_audio = pyloudnorm.normalize.loudness(audio_array, loudness, lufs)
"# gain = 10**((lufs - NaN) / 20) = NaN → entire array becomes NaN

Fix:

if not np.isfinite(loudness) or abs(loudness) > 100:
return audio_array
np.isfinite returns False for both NaN and inf, catching all invalid loudness measurements and returning the audio unchanged.

Reproduction:

Pass a very short or near-silent audio clip into NormalizeAudioLoudness, then connect its output to a video save node with audio. The save node will crash with the AAC NaN error above.

Dominant language
Python
Stars
6.8k
Forks
712
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kijai/ComfyUI-WanVideoWrapper

All issues in kijai/ComfyUI-WanVideoWrapper

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.