Windows and Linux MP4 exports spend ~70% of their audio encode in FFmpeg's mid/side search
[!NOTE] 🤖 Claude Opus 5.5 responding on behalf of @samanyudas
On Windows and Linux, MP4 export audio goes through FFmpeg's built-in aac encoder, and about 70% of that encoder's time is its mid/side stereo search.
macOS moved off this encoder in #2623. Windows and Linux still use it through AACEncoder::init_for_export → AACEncoder::init (crates/enc-ffmpeg/src/audio/aac.rs).
Evidence
All numbers are from the GPUI app's release build on Linux (Intel Core i7-10510U, 4 cores / 8 threads), with the bundled FFmpeg 7.1 from scripts/setup.js and Cap's reference recording (30.8 s, mic + system audio).
Profile of a real export.
I sampled the app (samply, 2 kHz) while CAP_GPUI_AUTO_EXPORT exported the reference recording to MP4 at 720p30.
The export-audio thread used 7.46 s of CPU in a 10.8 s export, 99% of it inside avcodec_send_frame.
Encoder alone.
I fed the export's own mixed audio track to AACEncoder::init_for_export in the export's 1,600-sample chunks.
Each row is a median of 3 runs.
FFmpeg aac option |
Encode time for 30.8 s | Audio bytes | Round-trip SNR |
|---|---|---|---|
defaults (aac_ms auto) |
2,760 ms | 860 KB | 60.0 dB |
aac_ms=0 |
776 ms | 1,133 KB | 57.9 dB |
aac_ms=1 (forced, no search) |
2,506 ms | 939 KB | 59.6 dB |
aac_is=0 / aac_pns=0 / aac_tns=0 |
2,670 to 2,690 ms | about 860 KB | not measured |
Only mid/side coding moves the time. Turning it off spends more of the 320 kbps budget that the encoder is already configured for, and the encode no longer needs about 2 s of CPU.
Why it matters for export time.
ExportAudioWorker::write_ready blocks the video encoder once audio falls more than AUDIO_LAG_LIMIT_SECS (2 s) behind.
So no export finishes sooner than this single-threaded encode, about 11× realtime here.
When the machine is busy, the encoder thread also takes a core away from decoding: in the profiled export, the same work cost 7.46 s of CPU against 2.76 s alone.
Expected
Windows and Linux exports encode their audio without the mid/side search, at a quality that still round-trips well above 50 dB at 320 kbps.