Skip to content

fix(web): keep the audio in every trim, not just the first - #3433

Open
patrickballard wants to merge 1 commit into
CapSoftware:mainfrom
patrickballard:fix/trim-again-audio
Open

patrickballard wants to merge 1 commit into
CapSoftware:mainfrom
patrickballard:fix/trim-again-audio

Conversation

@patrickballard

@patrickballard patrickballard commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3432.

processTrim now creates the preview's MediaElementAudioSourceNode and its MediaStreamDestination once, keeps them in a ref, and adds that destination's audio track to each recording. Before, every trim called createMediaElementSource on the same always-mounted preview <video>, which browsers allow only once per element, so from the second trim on it threw InvalidStateError, the catch logged it, and the trim was recorded silent.

6 s H.264 + AAC MP4, full-length trims before (cap.so) after
first trim video + audio, 6.0 s video + audio, 5.9 s
after Trim Again video only, 5.0 s video + audio, 5.96 s
after Choose Different Video video only, 5.0 s video + audio, 5.96 s

Tests

  • New trimming-tool-audio.test.ts, added to CI's web test list. It trims, then trims again after Trim Again and after choosing a different video, with an AudioContext stand-in that, like browsers, allows one MediaElementAudioSourceNode per element, and checks that each recording gets an audio track. Both cases fail without the change (the second recording has none).
  • Checked in Chromium 152 by building the component into a Next 16 page (Turbopack) and trimming with real clicks: all three trims above have an Opus audio track with the test tone intact.
  • bun run typecheck: no errors. Biome: the test is clean, and the component's existing lint errors are unchanged.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

The PR reuses the preview’s audio destination so repeated trims retain audio.

  • Repeat trims keep the preview video's audio in each recording.

Reviews (1) · Last reviewed commit: "fix(web): keep the audio in every trim, ..." · Reviewed by Greptile

The trim tool connected the preview video to a new
MediaElementAudioSourceNode on every trim, but an element can only ever
have one, so from the second trim on the call threw, the catch logged it
and the trim was recorded without audio. Create the connection once per
preview element and reuse it.
@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@patrickballard is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trim tool drops the audio from every trim after the first

1 participant