Skip to content

fix: main video invisible in editor (CORS) + webcam recording truncated (encoder contention) - #20

Merged
Alfredoalv13 merged 1 commit into
mainfrom
fix/main-video-cors-and-webcam-encoder-contention
Jul 25, 2026
Merged

fix: main video invisible in editor (CORS) + webcam recording truncated (encoder contention)#20
Alfredoalv13 merged 1 commit into
mainfrom
fix/main-video-cors-and-webcam-encoder-contention

Conversation

@Alfredoalv13

Copy link
Copy Markdown
Owner

Summary

Two independent, core-functionality bugs, both root-caused by directly instrumenting the actual recording/playback lifecycle rather than guessing:

  1. Main screen recording never appeared in the editor preview. Loaded fine (correct dimensions/duration, no decode error) but throwing SecurityError on texImage2D when Pixi tried to use it as a WebGL texture, because mediaServer.ts and rendererServer.ts each listen on separate random localhost ports, making the video cross-origin from the page. The server already sends Access-Control-Allow-Origin, but the <video> element needs crossOrigin set to actually make the CORS-mode request that permission depends on. Fix: add crossOrigin="anonymous" to the main video element.

  2. Webcam recording always truncated to a fraction of a second. Traced via direct MediaRecorder instrumentation: with MP4/H.264 preferred, ondataavailable never fired during recording - only once, at stop(). Likely cause: macOS VideoToolbox only supports a small number of concurrent hardware H.264 encode sessions, and the screen recording's native ScreenCaptureKit helper already holds one. Reordering the webcam MIME type preference to try VP9/VP8 (software-encoded) first fixed it immediately - verified ondataavailable firing every ~267ms for a full 31s recording afterward.

Test plan

  • tsc --noEmit clean
  • npm test - 94/94 files, 819/819 tests passing (one test updated for the new MIME preference order, split into two cases)
  • Manual: full end-to-end recording (screen + webcam + audio, ~31s) played back correctly in the editor with zoom effects intact and full-length webcam footage

…ated (encoder contention)

Two independent, previously-undiagnosed bugs found by instrumenting the
actual recording/playback lifecycle end-to-end:

1. The main screen recording never appeared in the editor preview (only
   the background layer showed, with none of the zoom/pan effects) - not
   because it failed to load, but because feeding it to Pixi as a WebGL
   texture threw `SecurityError: Failed to execute 'texImage2D'... cross-
   origin data`. mediaServer.ts and rendererServer.ts each listen on a
   separate random localhost port, so the video is cross-origin from the
   page's perspective. The media server already sends
   Access-Control-Allow-Origin, but a <video> element only makes the
   CORS-mode request that permission depends on if crossOrigin is set on
   the element itself - without it, the video plays back fine directly but
   still taints any canvas/WebGL texture created from it. The webcam
   preview was unaffected because it's rendered as a plain <video> tag,
   never uploaded to a WebGL texture.

2. The recorded webcam file was always truncated to a fraction of a
   second regardless of actual recording length. Traced via direct
   instrumentation of the MediaRecorder lifecycle: with MP4/H.264 selected
   (first in the webcam preference list), ondataavailable never fired
   during recording at all - only once, at stop(), with a couple of small
   chunks. Switching preference to VP9/VP8 (software-encoded, WebM) fixed
   it immediately: ondataavailable now fires every ~267ms for the entire
   recording as expected. The likely cause is macOS's VideoToolbox
   supporting only a small number of concurrent hardware H.264 encode
   sessions - the screen recording's native ScreenCaptureKit helper
   already holds one, and the webcam's MP4 MediaRecorder was competing for
   hardware encoder time it couldn't get.

Verified directly: 786 -> 819 passing tests (one test updated for the new
mime type preference, split into two cases), tsc clean, and a real
end-to-end recording (screen + webcam + audio, ~31s) played back
correctly in the editor afterward with zoom effects intact.
@Alfredoalv13
Alfredoalv13 merged commit c5d9c6f into main Jul 25, 2026
1 check passed
@Alfredoalv13
Alfredoalv13 deleted the fix/main-video-cors-and-webcam-encoder-contention branch July 25, 2026 01:52
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.

2 participants