Skip to content

frontend: Stop the recording before quitting instead of dropping its end - #781

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/quit-recording-drain
Oct 15, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/quit-recording-drain

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes #780

What and why

Quitting OBS while it records no longer cuts the end off the recording.

  • OBSBasic::closeWindow() (frontend/widgets/OBSBasic.cpp line 1840) left the recording running until applicationShutdown() destroyed the outputs with outputHandler.reset() (line 1334). Destroying an active output force-stops it, so every frame the video encoder still held (x264's lookahead and B-frames) was lost: about 0.7 s at 30 fps with x264 veryfast. Stop Recording does not lose them, because obs_output_stop() lets the muxer write everything up to the moment of the stop.
  • pheanex reported it on the OBS forum in December 2024 (thread 182904, OBS 30.2.3 on Ubuntu: Ctrl+Q or SIGTERM while recording, "a few seconds are missing at the end"; no replies). There is no GitHub issue.
  • closeWindow() now stops an active recording the way Stop Recording does, right after the virtual camera and before the scenes are cleared, and waits until it has stopped. The wait is bounded: after 5 s the recording is force-stopped as before (with a warning in the log), so quitting never hangs on it. StopRecordingForShutdown() is a header template next to StopVirtualCamForShutdown(), so the test runs it without the frontend.
  • The UI's stopRecording / recordStopping handlers are disconnected first. The window is going away, and, as before, a quit shows no "Recording saved" message or error dialog and starts no Automatic Remux.
  • Not changed: streaming (a graceful stop with Stream Delay can take minutes) and the Replay Buffer (a stop discards it either way) keep their current shutdown. The exit confirmation dialog's text ("All streams/recordings will be shut down") still fits.

Reproduced in release v0.1.0-beta.20261014 (AppImage, headless: private Xvfb, private HOME, dbus-run-session, --multi). Simple output, x264 Small (veryfast), MKV, 640x360 at 30 fps, a looping Media Source, recording started over obs-websocket and run for 10 s:

How the recording ends Release: video frames (duration) This branch (Rust libobs lane, with the frontend)
Stop Recording, then quit (control) 301 (10.03 s)
Quit, confirmation dialog off 275 of 300 (9.23 s) 303 of 300 (10.13 s)
Quit, confirmation dialog on (default), OK after about 11.6 s 344 of about 364 (11.50 s) 350 of 348 (11.67 s)
Pause at 10 s, quit 1 s later 280 of 300 (9.40 s) 302 of 300 (10.10 s)
SIGTERM, confirmation dialog off 277 of 300 (9.30 s) 301 of 300 (10.10 s)

On the branch the graceful stop took 0.9 s of the quit on this machine (software GL, heavily loaded); the 5 s limit was never reached.

RED → GREEN

  • RED commit: 470633a test/cmocka: Add failing test for quitting OBS while recording. test_recording_shutdown runs StopRecordingForShutdown() (in the RED commit it does what closeWindow() does today: nothing) on a real libobs output whose video encoder holds back 12 frames and which stops like obs-ffmpeg-mux, then releases the output as outputHandler.reset() does. 2 of 3 cases fail in both lanes: test_quit_keeps_frames_held_by_encoder (42 frames into the encoder before the quit, 30 reach the output) and test_quit_does_not_hang_on_stuck_recording (a recording that never finishes stopping is left running). test_quit_without_recording passes (no handler, no active recording).
  • GREEN: 5ae7050. 3 of 3 with ENABLE_RUST_LIBOBS OFF and ON (43 packets for 42 frames; the stuck recording is force-stopped after 301 to 302 ms of a 300 ms limit); timing, so repeated 20 times per lane: 20/20. Needs core video, so the two libobs cases skip without a display (checked with DISPLAY unset). Full ctest (private Xvfb, system libobs-opengl masked, TMPDIR unset): 221/221 in both lanes, every PipeWire/PulseAudio test ran; skipped only open_crashes_without_obs_core and (Rust lane) test_startup_shutdown_cycles, as on master here. (A first Rust-lane run had test_startup_cycle_stress reported failed after its case skipped, from xvfb-run's teardown ("kill: No such process"); the rerun passed.) clang-format, gersemi and ci/test_registration.py clean.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

AI note: Claude Code (Claude Opus 5.5) wrote the code, the test, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner October 14, 2026 23:44
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 14, 2026
rdoupe and others added 2 commits October 14, 2026 16:57
Quitting OBS while it records (File > Exit, Ctrl+Q, closing the window,
SIGINT) drops the end of the recording. OBSBasic::closeWindow() leaves
the recording running until applicationShutdown() destroys the outputs
with outputHandler.reset(), and destroying an active output force-stops
it: every frame the video encoder still holds (x264's lookahead and
B-frames) is lost. Stop Recording stops the output gracefully and keeps
them.

RecordingShutdown.hpp holds StopRecordingForShutdown(), the step
closeWindow() will run before the outputs are destroyed. For now it does
what closeWindow() does today: nothing.

test_recording_shutdown runs it on a real libobs output whose video
encoder holds back 12 frames and which stops like obs-ffmpeg-mux, then
releases the output as outputHandler.reset() does. Two cases fail: the
frames the encoder held at the quit must reach the recording, and a
recording that never finishes stopping must be force-stopped after the
timeout instead of left running.

Refs obs-rust#780.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quitting OBS while it records (File > Exit, Ctrl+Q, closing the window,
SIGINT; after "Yes" on the exit prompt too) cut the end off the
recording. closeWindow() left the recording running until
applicationShutdown() destroyed the outputs, and destroying an active
output force-stops it: the frames the video encoder still held (x264's
lookahead and B-frames, about 0.7 s at 30 fps with x264 veryfast) never
reached the file.

closeWindow() now stops an active recording the way Stop Recording does
and waits until it has stopped, before it clears the scenes, so the file
ends at the moment of the quit. The wait is bounded (5 s); a recording
that has not stopped by then is force-stopped as before, so quitting
never hangs on it. The UI's own stop handlers are disconnected first:
the window is going away, and, as before, a quit does not show the
"recording saved" message, error dialogs or start an Automatic Remux.

Fixes obs-rust#780.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=6ba684713a432673c599479d76e1e603cf5151f1 secs=524 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1792022746,"gate":"rust/all/fmt","host":"linux-x86_64","key":"0a69292d402b4f5f37c5022d24365d2924e8e59046662f5e2a649e14ec4e92c1","lane":"lint","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":61,"stamp":"d85c8b09c97006340403e981b314db35","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"0a69292d402b4f5f37c5022d24365d2924e8e59046662f5e2a649e14ec4e92c1","lane":"lint","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":61,"stamp":"069bbdbabfc645ddbd38b461630d5ae0","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"3497d4b9b95a979d44f2da102f9c07fac30403d157925b4cbfb7196712014667","lane":"rust-test","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":134,"stamp":"b9b2ac504cd40118b18569ced8ce739b","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"da43a0e01d7c8cd75a3c390127eb24aceae5508a652b2f29d80fc1472e9e672c","lane":"cross","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":113,"stamp":"4106c50da674d34053f98722f8326d80","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"da43a0e01d7c8cd75a3c390127eb24aceae5508a652b2f29d80fc1472e9e672c","lane":"cross","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":113,"stamp":"5dc0597f09f8347804cdeb241b2f81a7","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"da43a0e01d7c8cd75a3c390127eb24aceae5508a652b2f29d80fc1472e9e672c","lane":"cross","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":113,"stamp":"a8952e435cad6390c07a5e76c750a6c8","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"da43a0e01d7c8cd75a3c390127eb24aceae5508a652b2f29d80fc1472e9e672c","lane":"cross","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":113,"stamp":"13fa251abbbfbe2cbda1b031efa26f9c","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"da43a0e01d7c8cd75a3c390127eb24aceae5508a652b2f29d80fc1472e9e672c","lane":"cross","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":113,"stamp":"aaed1be817cb8e38768da3f5de60f047","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"da43a0e01d7c8cd75a3c390127eb24aceae5508a652b2f29d80fc1472e9e672c","lane":"cross","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":113,"stamp":"5f84e378b5af935ebbb38fa0e701d680","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
Ci-Attestation: {"at":1792022746,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4bfc67b49a755152d4986aa22659f14b8bb88b25390678719623f939ebe899ea","lane":"tier2-linux","parents":["feeb8685167a38697774a664a6565c9b03fc80b0"],"secs":216,"stamp":"62ba51bea89a0c68084105e5552b65a3","tree":"6ba684713a432673c599479d76e1e603cf5151f1","v":1,"via":"run"}
@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member

Rebased onto master, set ci-full (frontend change), and ran the stamped local gate. Your RED (470633a84: test_recording_shutdown fails with today's no-op shutdown) / GREEN evidence above stands.

  • Rebased on master, local gate passed; pushed as 7c1f992.

@zackees
zackees force-pushed the fix/quit-recording-drain branch from 5ae7050 to 7c1f992 Compare October 15, 2026 00:05
@zackees
zackees added this pull request to the merge queue Oct 15, 2026
Merged via the queue into obs-rust:master with commit b06e00f Oct 15, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: frontend: quitting OBS while recording cuts the end off the recording (forum thread 182904)

2 participants