render.py crashes in loudnorm when the edit's audio is digital silence
What happens
helpers/render.py exits with a CalledProcessError traceback when the edit's audio is digital silence, for example a screen recording with a muted microphone, or b-roll with an empty audio track. No output video is written. Both modes fail:
--draft(one-pass loudnorm): loudnorm writes NaN samples. The AAC encoder rejects them, and ffmpeg exits 234:Error encoding a frame: Invalid argument- Final (two-pass):
measure_loudness()returns"input_i": "-inf"and"target_offset": "inf". Pass 2 passes these values to loudnorm, and ffmpeg exits 222:Value -inf for parameter 'measured_I' out of range [-99 - 0]
A source with no audio stream renders without error (the output has no audio track). An edit with audible audio also renders without error. Only an audio track that is entirely silent fails.
Reproduce
At commit b877063, with ffmpeg 8.0.1, Python 3.11.14, macOS (Apple silicon):
ffmpeg -v error -y -f lavfi -i "testsrc2=s=1920x1080:r=30:d=3" \
-f lavfi -i "anullsrc=r=48000:cl=stereo:d=3" \
-c:v libx264 -pix_fmt yuv420p -c:a aac -shortest silent_track.mp4
printf '{"version":1,"sources":{"A":"silent_track.mp4"},"ranges":[{"source":"A","start":0.0,"end":2.0}]}\n' > silent.json
python /path/to/video-use/helpers/render.py silent.json -o out.mp4 --draft # exit status 234
python /path/to/video-use/helpers/render.py silent.json -o out.mp4 # exit status 222Cause
EBU R128 integrated loudness ignores blocks below -70 LUFS. On digital silence every block is ignored, so loudnorm measures -inf.
measure_loudness()checks only that the JSON keys exist. It returns the-infmeasurement as valid, so the "measurement failed — falling back to 1-pass" branch inapply_loudnorm_two_pass()does not run. The one-pass path fails on the same input anyway.- The
apply_loudnorm_two_pass()docstring says it returns False when measurement fails, so the caller can copy the input unchanged. The function never returns False; it raises.
Suggested fix
Measure in both modes. If input_i is not finite, skip loudnorm and copy the input to the output: the audio is silent, so there is nothing to normalize. A wrapper that does this around render.py renders the repro above in both modes and keeps the silent audio track.
Source: browser-use/video-use