Render audio differs from run to run: amix input order follows prep completion order (and the −1 dBTP guard flips)
Describe the bug
Rendering the same composition twice gives different audio. Between renders the decoded audio differs about 33 dB below the signal. On a composition whose true peak sits near −1 dBTP, some renders also come out 0.6 dB quieter: the log line Audio lowered by 0.6 dB to stay under −1 dBTP appears on some runs and not on others. It happens with --workers 1 too. Video is not affected.
We've seen it on 0.8.156 through 0.8.161, on two Macs.
Minimal reproduction
A self-contained script with synthetic assets. It needs only ffmpeg. It builds a 3 s audio-only composition (one mono tone, one stereo noise bed, 12 overlapping 0.6 s noise pops), renders it 4 times, and prints a hash of each render's decoded audio.
#!/usr/bin/env bash
# Builds a 3 s audio-only composition from synthetic assets, renders it 4 times, prints a hash of the decoded audio.
set -e
V=${V:-latest}
md5=$(command -v md5sum || command -v md5)
mkdir -p hf-audio-repro/a && cd hf-audio-repro
gen() { ffmpeg -v error -f lavfi -i "$2" -af "$3" -ac "$4" -ar 48000 -c:a pcm_s16le -y "a/$1"; }
gen voice.wav "sine=f=180:d=3,aeval=val(0)*0.5+0.25*sin(2*PI*1375*t)" "volume=0.55" 1
gen bed.wav "anoisesrc=d=3:c=pink:a=0.5:s=7" "volume=0.25" 2
for k in 0 1 2 3; do gen pop$k.wav "anoisesrc=d=0.6:c=white:a=0.9:s=$((k+1))" "afade=t=out:st=0:d=0.6:curve=exp,volume=0.6" 2; done
cat > index.html <<EOF
<!doctype html><html><head><meta charset="utf-8"></head><body>
<div id="root" data-composition-id="main" data-start="0" data-width="180" data-height="320" data-duration="3" data-fps="30">
<audio id="vo" src="a/voice.wav" data-start="0" data-duration="3" data-track-index="10" data-volume="1"></audio>
<audio id="bed" src="a/bed.wav" data-start="0" data-duration="3" data-track-index="21" data-volume="0.8"></audio>
$(awk 'BEGIN { for (i = 0; i < 12; i++) printf "<audio id=\"sfx%d\" src=\"a/pop%d.wav\" data-start=\"%.3f\" data-duration=\"0.6\" data-track-index=\"%d\" data-volume=\"%.2f\"></audio>\n", i, i % 4, 0.2 + i * 0.21, 40 + i % 3, 0.3 + 0.05 * (i % 5) }')
</div><script>window.__timelines = window.__timelines || {};</script></body></html>
EOF
for i in 1 2 3 4; do
npx -y hyperframes@$V render --quality delivery --workers 1 --quiet -o out-$i.mp4 . > render-$i.log 2>&1
echo "render $i: decoded audio $(ffmpeg -v error -i out-$i.mp4 -map 0:a -f s16le - | $md5 | cut -c1-12)"
done
Steps to reproduce
- Save the script as
repro.sh. - Run
V=0.8.161 bash repro.sh. - Compare the four hashes.
Expected behavior
The same composition renders to the same audio every time (identical decoded PCM), the way the video already does.
Actual behavior
On 0.8.161 (Apple M4, macOS, ffmpeg 9.0.2):
render 1: decoded audio abc0446d18a9
render 2: decoded audio 9b4316ea2a22
render 3: decoded audio abc0446d18a9
render 4: decoded audio 5d36e1c76aac
On a real 30 s composition with 53 audio tracks, 4 renders came out at two levels 0.61 dB apart. The quieter renders were the ones that logged Audio lowered by 0.6 dB to stay under −1 dBTP.
Environment
✓ Version 0.8.161 (latest)
✓ Node.js v26.11.1 (darwin arm64)
✓ CPU 10 cores · Apple M4 @ 2400MHz
✓ FFmpeg ffmpeg 9.0.2 at /opt/homebrew/bin/ffmpeg
✓ FFprobe ffprobe 9.0.2 at /opt/homebrew/bin/ffprobe
✓ Chrome cache: chrome-headless-shell mac_arm-152.0.7977.30
(Relevant npx hyperframes doctor lines. It also reproduces on a second Mac with the same ffmpeg.)
Additional context
Cause, as far as we can tell from the dist build:
- The mix order depends on timing.
processCompositionAudio(engine/src/services/audioMixer.ts) prepares every element withelements.map(async ...)insidePromise.all. It callstracks.push(track)(orbucket.push(track)for groups) when that element's ffmpeg prepare finishes, so theamixinput order is the completion order. With the shim described below, we saw the order change on every render. - The AAC encoder magnifies rounding.
amixsums its inputs in order. Swapping two inputs doesn't change a float sum, but where three or more inputs are non-zero at once, the rounding differs (about −155 dB). The native AAC encoder then writes a different bitstream from the first frame where a coding decision flips. The decoded difference is about −33 dB. - The true-peak check flips on that codec noise.
enforceAacTruePeak(producer/src/services/render/audioPadTrim.ts) measures the re-encoded AAC withebur128, which reports true peak in 0.1 dB steps, and compares it with −1.0 dBTP. A mix near that line reads −0.9 on some runs and −1.0 on others, so it gets lowered by 0.6 dB only sometimes. With one shuffled order we tried offline, the AAC read +0.5 dBTP, which would have lowered that render by 2 dB.
Evidence. We set HYPERFRAMES_FFMPEG_PATH to a logging shim and captured the final mix from two renders of the 53-track composition. Their 53 input WAVs were bit-identical; only the order differed. Mixed to float WAV, the two orders came out −160 dB apart. Mixed to AAC as the renderer does, they came out −34 dB apart.
Suggested fix. Keep document order: store each prepared track by its element index (tracks[i] = track, and the same for group buckets), drop the failed slots, and stop pushing on completion. Separately, applying the true-peak guard before the first AAC encode (on the float mix), or measuring with finer resolution, would stop the level depending on codec noise.
Workaround we use. An ffmpeg wrapper set as HYPERFRAMES_FFMPEG_PATH. For the amix call only, it sorts the inputs by file name and renumbers the filter graph before running ffmpeg. Every other call passes through unchanged. With it, the repro and the real composition give bit-identical audio on every render, including across the two Macs.
I checked this on Windows to see whether anything is left after #5672.
Setup: Windows 11 x64, FFmpeg 9.0.2 (gyan.dev), the composition and assets from the script above, render --quality delivery --workers 1. Hashes are md5 of the decoded s16le audio.
| 0.8.161 | 0.8.185 | |
|---|---|---|
| Repro as posted, full renders | 7 renders, 3 hashes, true peak −7.9 / −8.1 dBTP | 6 renders, 1 hash |
Same elements through processCompositionAudio only |
40 mixes, 5 hashes | 40 mixes, 1 hash |
Every data-volume ×2.2208 (+6.93 dB), mixer only |
48 mixes, 6 hashes: 42 at −1.1 dBTP, 6 at −0.3 dBTP | 48 mixes, 1 hash, −1.4 dBTP |
| Same volumes, full renders | 16 renders, 5 hashes, all −1.1 dBTP | 6 renders, 1 hash, −1.4 dBTP |
So the guard flip comes from the order race here too: at +6.93 dB the order that reads −0.3 dBTP would be lowered and the others would not. I only caught that order in the mixer runs, not in the 16 full renders. On 0.8.185 the audio and the guard decision repeat every time. On current main (2c1d9d5, under WSL) the engine audio and producer pad/trim and true-peak suites pass, and audioMixer.order.test.ts fails 3/3 with #5672's mixer change reverted.
One thing the order fix doesn't change: the post-encode peak isn't monotonic in gain (on 0.8.161, +6.8 dB read −0.9 dBTP and +7.0 dB read −1.1). So a small authoring edit can still flip the guard, just not between identical renders.
Two questions:
- Is anything left here, or can this close as fixed by #5672 (0.8.163+)?
- Would you take a test-only PR adding a real-FFmpeg companion to
audioMixer.order.test.ts? It holds each prepared track until it's released in authored, reversed or interleaved order, then asserts that the float sum (keepEncoderInputAt) and the decoded AAC match, ungrouped and with one bus. It passes onmainand fails with #5672's mixer change reverted. The float sum catches what one second of AAC doesn't. Happy to drop it if the mocked test is enough, and I'd leave the true-peak measurement to you.
Closing: the fix merged in #5672. If this still reproduces on a release that includes it, please reopen with the version and a repro.