Skip to content

fix(windows): preserve WGC duration through static frames#551

Merged
meiiie merged 3 commits into
mainfrom
fix/windows-recording-duration-triage
May 22, 2026
Merged

fix(windows): preserve WGC duration through static frames#551
meiiie merged 3 commits into
mainfrom
fix/windows-recording-duration-triage

Conversation

@meiiie
Copy link
Copy Markdown
Collaborator

@meiiie meiiie commented May 22, 2026

Summary

  • Repeat the previous WGC frame across static-frame gaps before writing the next frame.
  • Reuse the same padding path at stop so tail-static recordings keep a continuous MP4 timeline.
  • Refresh the Windows wgc-capture.exe helper manifest and staged helper binary from a temp CMake build.

Why

Refs #375. Users are reporting recordings that are shorter in the editor/export, with one signal pointing at static screen sections. WGC can stop delivering frames while the captured scene is unchanged; if the MP4 only receives sparse samples, the editor can see a shorter effective timeline. This keeps the encoded video timeline continuous without touching the broader export/NVIDIA path.

Validation

  • cmake -S electron/native/wgc-capture -B %TEMP%/recordly-wgc-build-* -G "Visual Studio 17 2022" -A x64
  • cmake --build %TEMP%/recordly-wgc-build-* --config Release
  • npx tsc --noEmit
  • npm test -- src/hooks/useScreenRecorder.test.ts src/lib/mediaTiming.test.ts
  • git diff --check

Known unrelated baseline: npm test -- electron/ipc/recording/diagnostics.test.ts src/hooks/useScreenRecorder.test.ts currently has one diagnostics expectation mismatch on getCompanionAudioFallbackPaths where code returns the .system.wav sidecar but the test expects only video + mic.

Summary by CodeRabbit

  • Bug Fixes

    • Improved MP4 timeline continuity during video capture by more reliably filling short frame gaps before writing new samples.
    • Prevented invalid capture settings by rejecting non-positive frame-rate values.
  • Refactor

    • Encoder frame-extension logic reorganized for clearer locked handling and more robust timing.
  • Chores

    • Updated Windows helper manifest metadata (checksum/timestamp) for the native capture tooling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f77b518a-6496-448b-82f6-749116171982

📥 Commits

Reviewing files that changed from the base of the PR and between ed11c26 and 58e413f.

⛔ Files ignored due to path filters (1)
  • electron/native/bin/win32-x64/wgc-capture.exe is excluded by !**/*.exe
📒 Files selected for processing (2)
  • electron/native/bin/win32-x64/helpers-manifest.json
  • electron/native/wgc-capture/src/mf_encoder.cpp
✅ Files skipped from review due to trivial changes (1)
  • electron/native/bin/win32-x64/helpers-manifest.json

📝 Walkthrough

Walkthrough

Adds MFEncoder::extendLastFrameToLocked to repeat the last buffered NV12 frame across intermediate timestamps (with readiness checks and fps-based durations); writeFrame now calls this helper and returns false if extension fails. Also updates wgc-capture helper binary metadata in the Windows manifest.

Changes

Frame Extension Refactoring

Layer / File(s) Summary
Declaration and writeFrame integration
electron/native/wgc-capture/src/mf_encoder.h, electron/native/wgc-capture/src/mf_encoder.cpp
Adds private extendLastFrameToLocked(int64_t) declaration, validates positive fps in initialize, updates writeFrame to call the locked extender when a prior buffered frame exists (aborting on extension failure), and uses computed frameDurationHns when setting sample duration.
extendLastFrameToLocked implementation
electron/native/wgc-capture/src/mf_encoder.cpp
Implements locked helper with encoder/writer readiness checks, computes frame duration from fps_, early-returns when target timestamp is within one frame, and writes repeated buffered NV12 frames at successive timestamps until just before the requested timestamp.
Helper binary manifest update
electron/native/bin/win32-x64/helpers-manifest.json
Updates helpers.wgc-capture binarySha256, sourceFingerprint, and updatedAt fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • webadderallorg/Recordly#100: Modifies mf_encoder.cpp write path (adds locking around writeFrame), overlapping the same function's core logic.

Suggested labels

Checked, Slop

Poem

🐰 I nudge the timeline, frame by frame,
Filling gaps so playback's tame,
NV12 echoes soft and bright,
Timestamps march through silent night,
Hopping frames until they're right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing Windows WGC recording duration preservation through handling static frames. It is concise and clearly conveys the primary purpose of the changeset.
Description check ✅ Passed The PR description includes a clear Summary section explaining the changes, a Why section providing motivation (referencing issue #375), and a Validation section with detailed testing steps. However, it does not follow the required template structure with sections like Type of Change, Related Issue(s) link, Screenshots/Video, Testing Guide, or Checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/windows-recording-duration-triage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@meiiie
Copy link
Copy Markdown
Collaborator Author

meiiie commented May 22, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@electron/native/wgc-capture/src/mf_encoder.cpp`:
- Around line 255-256: The code computes frameDurationHns using fps_ before
validating fps_, which will divide by zero if fps_ == 0; update the logic around
the computation that sets frameDurationHns so you first check/guard fps_ (e.g.,
if (fps_ <= 0) return false;) then compute const int64_t frameDurationHns =
10000000LL / fps_; and keep the existing check for frameDurationHns <= 0 if
still needed; reference fps_ and frameDurationHns when making this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 085d32e8-5967-4c53-9ce5-4b3e427b01bc

📥 Commits

Reviewing files that changed from the base of the PR and between 5924f92 and 6227eb8.

⛔ Files ignored due to path filters (1)
  • electron/native/bin/win32-x64/wgc-capture.exe is excluded by !**/*.exe
📒 Files selected for processing (3)
  • electron/native/bin/win32-x64/helpers-manifest.json
  • electron/native/wgc-capture/src/mf_encoder.cpp
  • electron/native/wgc-capture/src/mf_encoder.h

Comment thread electron/native/wgc-capture/src/mf_encoder.cpp
@meiiie
Copy link
Copy Markdown
Collaborator Author

meiiie commented May 22, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@electron/native/wgc-capture/src/mf_encoder.cpp`:
- Around line 255-257: The code only checks fps_ when padding frames, but
writeNv12SampleLocked() also computes frameDurationHns = 10000000LL / fps_
(risking divide-by-zero) and initialize() currently doesn't validate fps_; add
validation of fps_ in initialize() to ensure fps_ > 0 (or set a safe default)
and/or add a guard at the start of writeNv12SampleLocked() to return an error if
fps_ <= 0; update any callers (e.g., extendLastFrameToLocked()) to rely on this
invariant so frameDurationHns computation is always safe.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c27185c9-d5ba-4904-ae6a-32f4abf5a36c

📥 Commits

Reviewing files that changed from the base of the PR and between 6227eb8 and ed11c26.

⛔ Files ignored due to path filters (1)
  • electron/native/bin/win32-x64/wgc-capture.exe is excluded by !**/*.exe
📒 Files selected for processing (2)
  • electron/native/bin/win32-x64/helpers-manifest.json
  • electron/native/wgc-capture/src/mf_encoder.cpp
✅ Files skipped from review due to trivial changes (1)
  • electron/native/bin/win32-x64/helpers-manifest.json

Comment thread electron/native/wgc-capture/src/mf_encoder.cpp
@meiiie
Copy link
Copy Markdown
Collaborator Author

meiiie commented May 22, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meiiie meiiie marked this pull request as ready for review May 22, 2026 10:19
@meiiie meiiie merged commit e024060 into main May 22, 2026
3 checks passed
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.

1 participant