Skip to content

feat: record a window through Windows Graphics Capture (#113) - #165

Merged
TMHSDigital merged 1 commit into
mainfrom
feat/wgc-recording-113
Oct 25, 2026
Merged

TMHSDigital merged 1 commit into
mainfrom
feat/wgc-recording-113

Conversation

@TMHSDigital

Copy link
Copy Markdown
Owner

Closes #113: the recording half, which was blocked.

Why it was blocked, and what I measured (FFmpeg 8.1.1):

  • gfxcapture emits a frame only when the window presents. A static window gave zero frames, by title or by HWND, and ffmpeg then ignored the graceful-stop q.
  • One RedrawWindow gives a first frame within ~30 ms.
  • ffmpeg holds the newest frame back until another arrives: frames after a change came out as a burst, only when the next frame pushed them. So a window that changes once and then sits still never shows its final state.
  • Repaint variants on a static window over 4 s:
repaint uncovered covered
1×1, invalidate+update 115 frames 0
1×1, +erase 107 103
full window, no erase 0 0
full window, +erase 102 105

Design: start_recording { backend: "wgc" } (window: targets, FFmpeg 8+) spawns dist/wgcRecorder.js instead of ffmpeg:

  • grab: ffmpeg turns gfxcapture=hwnd=… into even-sized raw yuv420p on stdout, with -flush_packets 1.
  • nudge: a 1×1 erase+invalidate+update repaint of the window every 200 ms, the lightest variant that works covered. It stops when the window closes.
  • pace: the recorder keeps the latest frame and writes it to an encoder ffmpeg at the requested fps, on wall-clock time. It repeats the frame while the window is static and drops frames if the encoder falls behind.
  • protocol: like ffmpeg. q on stdin, stdin closing (server gone), or the duration cap finalizes and exits 0; the window closing ends the recording cleanly. stop_recording, maxDurationSec, crash detection and the fragmented-mp4 safety are unchanged. On its first frame it prints an ffmpeg-style start: banner, so start_recording returns once frames flow and the input event log aligns as with gdigrab.
  • events: the frame is the window's client area, so enumeration now reports each window's client origin, and the event log maps onto it.
  • errors: non-window targets, audio, and FFmpeg < 8 get clear errors. gdigrab stays the default, so nothing changes for existing callers.

Tests

  • Unit: grab and encode args, raw-size parsing (output stream, not input), wall-clock pacing, the start banner aligning with parseCaptureStart, the nudge script.
  • Live: a static lime window under a topmost magenta cover, recorded with wgc. Once recording, it moves and turns blue, then sits still. The output is 400×300 (client area), lime at the start and blue at the end (never magenta), and stops gracefully. The full harness passes 19/19.

Bumps to 0.32.0.

🤖 Generated with Claude Code

start_recording backend: "wgc" records a window's own surface, covered,
moved, or in the background. A recorder process nudges the window with
1px repaints so gfxcapture keeps emitting frames, repeats the latest
frame at a fixed rate, and stops on q like ffmpeg.

Closes #113

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 25, 2026
@TMHSDigital
TMHSDigital merged commit 92bceca into main Oct 25, 2026
8 checks passed
@TMHSDigital
TMHSDigital deleted the feat/wgc-recording-113 branch October 25, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows Graphics Capture backend via FFmpeg gfxcapture for true per-window capture

1 participant