From 0314087e21c6df815016f301a7b9c92cb901f62d Mon Sep 17 00:00:00 2001 From: ChinhLee <76194645+chinhkrb113@users.noreply.github.com> Date: Thu, 2 Apr 2026 21:55:12 +0700 Subject: [PATCH] refactor(web): add runtime audio encoder capability negotiation for mp4 exports Introduce a dedicated utility that probes browser support for AAC/WebCodecs audio settings instead of assuming a single hardcoded configuration (`mp4a.40.2`, 192 kbps, stereo, 44.1 kHz). This file should centralize support detection and fallback selection so ChromeOS/Chrome variants that reject the current config can still export with audio. Affected files: audio-codec-support.ts Signed-off-by: ChinhLee <76194645+chinhkrb113@users.noreply.github.com> --- .../web/src/lib/export/audio-codec-support.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 apps/web/src/lib/export/audio-codec-support.ts diff --git a/apps/web/src/lib/export/audio-codec-support.ts b/apps/web/src/lib/export/audio-codec-support.ts new file mode 100644 index 000000000..fa9b1dab4 --- /dev/null +++ b/apps/web/src/lib/export/audio-codec-support.ts @@ -0,0 +1,45 @@ +const CANDIDATE_CONFIGS: AudioEncoderConfig[] = [ + { + codec: "mp4a.40.2", + sampleRate: 44100, + numberOfChannels: 2, + bitrate: 192000, + }, + { + codec: "mp4a.40.2", + sampleRate: 44100, + numberOfChannels: 2, + bitrate: 128000, + }, + { + codec: "mp4a.40.2", + sampleRate: 44100, + numberOfChannels: 1, + bitrate: 128000, + }, + { + codec: "mp4a.40.2", + sampleRate: 48000, + numberOfChannels: 2, + bitrate: 128000, + }, +]; + +export async function resolveSupportedMp4AudioConfig(): Promise { + if (typeof AudioEncoder === "undefined") { + return null; + } + + for (const config of CANDIDATE_CONFIGS) { + try { + const support = await AudioEncoder.isConfigSupported(config); + if (support.supported) { + return config; + } + } catch { + continue; + } + } + + return null; +}