Skip to content

fix(windows): prevent OBS Virtual Camera from freezing during recording - #1684

Open
frayzis wants to merge 1 commit into
getopenscreen:mainfrom
frayzis:fix/obs-virtual-camera-clock
Open

frayzis wants to merge 1 commit into
getopenscreen:mainfrom
frayzis:fix/obs-virtual-camera-clock

Conversation

@frayzis

@frayzis frayzis commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #1683

On Windows, OBS Virtual Camera can produce a stuttering preview and a webcam recording that holds its first frame while the screen recording continues. A looping OBS media source reproduces the recording freeze without a phone or physical camera. The same virtual-camera stream records with motion in FFmpeg.

Set a null reference clock on the DirectShow graph for the OBS Virtual Camera CLSID before starting capture. The change is confined to electron/native/wgc-capture/src/dshow_webcam_capture.cpp. OpenScreen continues to timestamp the screen and camera on its shared recording clock.

Validated on Windows 11 with OBS Studio 33.0.3 and the OpenScreen 2.4.0 Store build. The patched helper recorded 181 camera frames in about six seconds without a freeze. In a separate test with a four-second pause, both tracks finished at 12.368 seconds and the test pattern timecode showed no accumulated camera delay after resume. This change targets the saved webcam recording. The preview before recording was not validated.

Summary by CodeRabbit

  • Bug Fixes
    • OBS Virtual Camera capture now uses updated synchronization settings during initialization. If those settings cannot be applied, capture initialization fails instead of continuing with an incomplete setup.
    • Other camera devices are unaffected by this change.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

For OBS Virtual Camera, DirectShow capture initialization now disables the graph reference clock. If querying IMediaFilter or setting the sync source fails, initialization returns false. Other devices skip this behavior.

Changes: OBS Virtual Camera clock handling

Layer / File(s) Summary
Identify the device and configure its graph clock
electron/native/wgc-capture/src/dshow_webcam_capture.cpp
The code adds the OBS Virtual Camera CLSID. For that device, initialization queries IMediaFilter and calls SetSyncSource(nullptr). Initialization returns false if either operation fails. Other devices do not enter this branch.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 73857

This change targets the OBS Virtual Camera freeze on Windows and applies only to that device, so other webcams keep their existing behavior. No merge-blocking risk is identified. Preview behavior was not validated, as the PR states.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Issue #1683 requires a fix for the OBS Virtual Camera recording freeze on Windows. It asks for IMediaFilter::SetSyncSource(nullptr) before Run(), limited to the OBS Virtual Camera CLSID, with other we…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes one file, electron/native/wgc-capture/src/dshow_webcam_capture.cpp, with +12 lines. Every change is the new CLSID constant, the OBS-only SetSyncSource(…
Title check Passed The title names the fix (preventing OBS Virtual Camera freezing) and the platform (Windows), which matches the changeset. It sets a null reference clock on the DirectShow graph for the OBS Virtual Cam…
Description check Passed The description covers the problem, the approach, the affected file, and the validation performed, and it links issue #1683. It states the scope limit that preview was not validated. The template's Ty…
Full details: Linked Issues check

Explanation

Issue #1683 requires a fix for the OBS Virtual Camera recording freeze on Windows. It asks for IMediaFilter::SetSyncSource(nullptr) before Run(), limited to the OBS Virtual Camera CLSID, with other webcam graphs unchanged and timestamps still on the shared recording clock. The diff in dshow_webcam_capture.cpp adds CLSID_ObsVirtualCamera ({A3FCE0F5-3493-419F-958A-ABA1250EC20B}). After the sample grabber setup and before the IMediaControl query, which precedes Run(), it calls SetSyncSource(nullptr) only when selectedClsid matches that CLSID. Other devices skip this path. Failures return false. No file outside the helper changed, so the shared recording clock is untouched. The issue asks for no automated tests, and the diff adds none. Preview behavior is out of scope per the issue. Limitation: the diff context does not show the declaration of selectedClsid, so the compile-time scope was not independently confirmed.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes one file, electron/native/wgc-capture/src/dshow_webcam_capture.cpp, with +12 lines. Every change is the new CLSID constant, the OBS-only SetSyncSource(nullptr) block, and an INFO log line. All of these serve issue #1683. No unrelated files, refactors, or preview-path changes appear in the diff.

Full details: Title check

Explanation

The title names the fix (preventing OBS Virtual Camera freezing) and the platform (Windows), which matches the changeset. It sets a null reference clock on the DirectShow graph for the OBS Virtual Camera CLSID, and the title describes that outcome. The title is specific and concise.

Full details: Description check

Explanation

The description covers the problem, the approach, the affected file, and the validation performed, and it links issue #1683. It states the scope limit that preview was not validated. The template's Type of change, Release impact, Desktop impact, and Screenshots sections are not filled in. The Testing section is written as narrative results rather than steps or commands, and the template's Related issue wording uses 'Fixes #1683', which is valid.

Resolution

Optional improvements: tick the Type of change (Bug fix), Release impact (Patch), and Desktop impact (Windows) boxes, state that no screenshots apply or add a short video, and list the test commands or steps in the Testing section. The Summary section could also be a brief one-line statement at the top, separate from the background.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a38f1507-a3b8-4b76-aa3f-f1cbbbe24403
Commits

Reviewing files that changed from the base of the PR and between 2b65ea9 and 7385775.

Files selected for processing: 1

  • electron/native/wgc-capture/src/dshow_webcam_capture.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@frayzis frayzis changed the title Fix OBS Virtual Camera freeze on Windows fix(windows): prevent OBS Virtual Camera from freezing during recording Nov 25, 2026

@My-Denia My-Denia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @frayzis. I tested 73857758c on Windows 11 (RTX 4090 Laptop) with the official OBS Studio 33.0.3 virtual camera (CLSID {A3FCE0F5-3493-419F-958A-ABA1250EC20B}), fed a looping test card with a frame counter. The WGC helper was built from this head and from its parent 2b65ea937 with the same toolchain and flags, so the two binaries differ only by this change.

Pass:

  • A/B on the helper. I drove each build directly with a config built from the fields in electron/ipc/handlers.ts (display capture plus OBS Virtual Camera at 1280x720@30). The app path is tested separately, below. Both builds miss the device in Media Foundation and fall back to DirectShow (Requested webcam device was not found by Media Foundation; trying DirectShow); only this head logs INFO: OBS Virtual Camera DirectShow graph clock disabled.
    Build Camera track freezedetect Counter at 2 s / 10 s / 20 s
    parent 742 frames, 24.7 s frozen from 0 s to the end 23 / 23 / 23
    this head (two takes) 743 and 740 frames, 24.7 s no freeze 18 / 26 / 36
  • Through the app. I selected OBS Virtual Camera in Device settings and recorded a 29 s take with a ~5 s pause:
    • The floating camera preview kept moving during the take (counter 18 → 28, then 44 after resume).
    • The camera and screen tracks both came out at 28.834 s, and the camera track has no freeze.
  • Media Foundation cameras keep their path. A USB UVC webcam was picked by Media Foundation (score=1000), and the new branch did not run.

About the evidence in the description. The frame count on its own ("181 camera frames in about six seconds") would look the same without the fix: the frozen parent take above also has ~30 fps of frames, because captureLoop stores whatever GetCurrentBuffer returns on every tick and bumps the sequence each time. The moving test-pattern timecode you checked in the pause test is what tells the two apart (as does ffmpeg -vf freezedetect), so it may be worth leading with that.

Worth checking. I couldn't tie these to the change, but two starts with this head stalled out of about eight:

  • Right after a frozen take with the parent helper, the next take with this head spent over two minutes before DirectShow format negotiation (DirectShow webcam format), which runs before the new code. It then failed with Timed out waiting for first WGC frame.
  • The first app take after restarting OBS failed with Timed out waiting for native Windows capture to start. The next app take started in under a second.

After restarting OBS, three direct takes started in under a second. The parent helper only ran twice and didn't stall. My guess is OBS's virtual camera being left in a bad state, not this change.

Small things:

  • If QueryInterface(IMediaFilter) or SetSyncSource fails, initialize returns false (dshow_webcam_capture.cpp:349-353) and the take continues without a camera. Logging a warning and carrying on with the clock attached would keep today's behaviour as the fallback.
  • The comment at :345-347 could say why it stalls: OBS stamps samples with absolute reference time and ignores tStart.
  • The PR template's Type of change, Release impact and Desktop impact boxes are unchecked.

Not covered: a non-OBS DirectShow-only camera (I don't have one), Windows 10 and arm64. The USB webcam smoke test ended with SinkWriter::Finalize failed (0xc00d4a44) because the camera delivered no visible frames in a dark room. The parent helper fails the same way, so I can't read anything about this change from it.

The failing "Rust test (macOS compositor)" job is audio::tests::a_clipped_voice_exports_under_minus_one_dbtp_and_keeps_what_loudness_it_can, which fails the same way on main at 96e3cd327 (run 45831334221). #1678, still open, fixes 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.

[Bug]: OBS Virtual Camera track freezes on its first frame on Windows

2 participants