Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions apps/web/src/lib/export/audio-codec-support.ts
Original file line number Diff line number Diff line change
@@ -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<AudioEncoderConfig | null> {
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;
}
Comment on lines +28 to +45
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify helper adoption and detect remaining hardcoded probing in exporter flow.

set -euo pipefail

echo "== locate new helper usages =="
rg -nP --type=ts '\bresolveSupportedMp4AudioConfig\s*\(' -C2

echo
echo "== locate direct AudioEncoder probing still in renderer/export paths =="
rg -nP --type=ts '\bAudioEncoder\.isConfigSupported\s*\(' -C3 apps/web/src/services/renderer/scene-exporter.ts apps/web/src/lib/export/audio-codec-support.ts || true

echo
echo "Expected:"
echo "1) scene-exporter path references resolveSupportedMp4AudioConfig()."
echo "2) hardcoded AAC probe logic is removed or delegated to the utility."

Repository: OpenCut-app/OpenCut

Length of output: 1930


Integrate the new helper into the MP4 export path.

The resolveSupportedMp4AudioConfig() function is defined but never called. scene-exporter.ts (lines 107–110) still contains the hardcoded AAC probe logic that should delegate to this utility:

const { supported } = await AudioEncoder.isConfigSupported({
    codec: "mp4a.40.2",
    sampleRate: this.audioBuffer.sampleRate,
    numberOfChannels: this.audioBuffer.numberOfChannels,

Replace this with resolveSupportedMp4AudioConfig() to centralize codec negotiation and achieve the PR's runtime-fallback objective.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/lib/export/audio-codec-support.ts` around lines 28 - 45, Replace
the hardcoded AAC probe in the MP4 export flow with the new helper: call
resolveSupportedMp4AudioConfig() from the export logic (the place currently
calling AudioEncoder.isConfigSupported with codec "mp4a.40.2" and
sampleRate/numberOfChannels) and use the returned AudioEncoderConfig (or null)
instead of the inline probe; if it returns null, proceed with the existing
fallback/no-audio path. Update the code path that currently expects { supported
} from AudioEncoder.isConfigSupported to await resolveSupportedMp4AudioConfig()
and branch on its result so codec negotiation is centralized.