Introducing a new way to review your PRs.

Read the announcement

capsoftware / cap

Open source Loom alternative. Beautiful, shareable screen recordings.

View on GitHub

31 documents · Updated Nov 23, 2026

docs / capture-and-recording-pipeline

Capture and recording pipeline

The capture and recording pipeline turns selected desktop, camera, cursor, microphone, system-audio, and audio-only inputs into a time-aligned recording project. It supports native capture services on each desktop platform, keeps optional input loss separate from display capture, and preserves unfinished media so a later recovery step can complete the recording.

Recording model

The pipeline treats display video as the required visual track for normal recordings. Camera, microphone, system audio, cursor events, and keyboard events are optional inputs that join the same recording timeline. Audio-only recording is an explicit exception that uses audio as the useful media and a timing-only display path. Cursor and keyboard data remain project events rather than video, so later playback and editing can use them as separate data.

This page sits below the recording and media engine. Completed media moves into media encoding and muxing, while project tracks and event data support export and editor rendering.

Capture targets

A capture target describes which visual source becomes the display track. The target also supplies the display and crop context needed to place pixels and cursor events in the same coordinate space.

TargetRecording role
DisplayCaptures a full display.
WindowCaptures a window in relation to its display.
AreaCaptures a selected region of a display.
Camera-onlyUses the camera as the main video source and does not need a display.
Audio-onlyRecords audio while using a timing-only display path so the recording keeps the normal segment and project lifecycle.

Window targets are handled as native window captures where the platform supports them. On macOS, a window that is also marked for exclusion stays on the display-crop path so the exclusion can take effect. On Windows, the window capture item defines the output size and does not use a display crop.

References: crates/…/mod.rs• L65-77 crates/…/mod.rs• L98-105 crates/…/macos.rs• L31-72 crates/…/windows.rs• L356-389

Track assembly

Each recording segment uses one shared time origin. The pipeline attaches enabled sources to separate media or event paths, then stores their paths, start times, device identity, and health data in project metadata. It also persists track start times as sources become ready and again as the segment stops, which keeps alignment data available after a crash. Audio-only segments use the same timing and project path without requiring a real display source. The audio-only clock measures the segment from its own ticks, so priming time does not extend the visual stand-in. This design lets an optional source fail without hiding whether the required display recording survived.

The high-level flow is:

flowchart LR
    Target[Display, window, area, or camera target] --> Backend[Platform capture backend]
    Backend --> Video[Screen video]
    Camera[Camera] --> Video
    Mic[Microphone] --> Audio[Audio tracks]
    System[System audio] --> Audio
    Cursor[Cursor and keyboard input] --> Events[Project events]
    Video --> Segment[Recording segment]
    Audio --> Segment
    Events --> Segment
    Segment --> Project[Recording project]

References: crates/…/studio_recording.rs• L1286-1318 crates/…/studio_recording.rs• L1500-1598 crates/…/studio_recording.rs• L2715-2761

Audio-only segments

Audio-only recording keeps audio as the useful media while supplying a clock for segment timing. This lets pause, stop, recovery, and editing treat the segment like other recordings even though no screen or camera picture is captured. It is a distinct capture target rather than a missing display selection.

When the segment ends, the pipeline creates a black display stand-in that spans the measured segment. The stand-in uses a fixed canvas and a software video path, so audio-only capture does not depend on a graphics encoder session. A segment with no timing samples produces no display file, so an empty audio-only start does not become false media.

References: crates/…/audio_only.rs• L24-60 crates/…/audio_only.rs• L63-109 crates/…/audio_only.rs• L112-177

Capture backends

The pipeline presents one screen-capture contract to the recording flow while selecting the desktop service that fits the host platform. Each backend turns a display or crop into timestamped frames and can provide system audio when the platform exposes it through the same capture service.

Platform screen capture

Platform capture differs in permission, device, and stream behavior, but the recording flow keeps the same target choices and track meaning.

PlatformCapture serviceMain role
macOSScreenCaptureKitCaptures displays or windows and crops and can carry cursor and system audio.
WindowsWindows Graphics Capture with Direct3DCaptures display or window textures and uses loopback for system audio.
LinuxX11 or a Wayland portal with PipeWireUses direct X11 capture where possible and portal-approved streams on Wayland. PipeWire can provide shared-memory or DMA-BUF frames.

The target is mapped to platform coordinates before capture starts. Area bounds convert from logical desktop units to physical pixels where needed. The pipeline clamps invalid bounds, keeps crop regions inside the display, uses a safe refresh rate, and keeps output dimensions even and within the selected size limit. These rules protect capture on high-DPI displays and keep a full-display selection from becoming a partial crop.

macOS uses a window-specific capture filter when the selected window is available and not excluded. It keeps excluded windows on a display filter instead. Window capture trims the rounded outer edge and fits the window to the requested frame size. If the display changes size during capture, the backend scales frames until the original output size is available again. A closed window is treated as a lost target rather than as a reason to capture whatever later occupies its area.

Windows uses the window's GraphicsCaptureItem for window targets, so the selected window can move without changing the captured region. Display and area targets use a display crop. The backend limits delivery on high-refresh displays to the requested cadence and scales frames when the source size changes. Startup is not complete until an accepted screen frame reaches the pipeline.

Linux chooses the Wayland portal when the session indicates Wayland. Portal approval supplies a PipeWire stream and remains owned until capture cleanup finishes. X11 uses direct capture when the session does not prefer the portal.

The Linux screen backend also supplies the system-audio source used by audio-only recording. It owns the temporary audio feed and restores the prior route when the source stops, so an audio-only session does not leave the host audio path changed.

References: crates/…/mod.rs• L65-112 crates/…/mod.rs• L305-347 crates/…/mod.rs• L527-645 crates/…/macos.rs• L31-105 crates/…/macos.rs• L317-405 crates/…/macos.rs• L434-605 crates/…/windows.rs• L356-452 crates/…/windows.rs• L594-663 crates/…/windows.rs• L1093-1117 crates/…/linux.rs• L90-167 crates/…/linux.rs• L405-511 crates/…/linux.rs• L1419-1499 crates/…/linux.rs• L1895-1963 crates/…/wayland_portal_tests.rs• L207-340

Linux DMA-BUF import

Linux Wayland capture can receive shared-memory frames or DMA-BUF frames. Linear DMA-BUF frames can be read through a short-lived CPU mapping, while tiled GPU-owned frames use the import path so compositors do not need to create a linear copy first.

The Linux backend offers formats in a safe order: shared memory first, then linear DMA-BUF, then tiled modifiers that a usable GPU can import. The importer discovers compatible EGL devices and modifiers. For each tiled frame it favors the exporting GPU and then tries other compatible GPUs. It returns a normal RGBA frame to the common video path. If no GPU import is available, the earlier shared-memory or linear path remains the fallback. Portal sessions close when capture ends, including when startup is cancelled or PipeWire setup fails, so permission resources do not outlive the recording.

This flow is shown below:

flowchart LR
    Portal[Wayland portal and PipeWire] --> Buffer[DMA-BUF frame]
    Buffer --> Match[Match format and GPU modifier]
    Match --> Import[EGL GPU import]
    Import --> RGBA[RGBA frame]
    RGBA --> Pipeline[Recording output pipeline]
    Portal --> Fallback[Shared-memory or linear path]
    Fallback --> Pipeline

References: crates/…/linux.rs• L545-711 crates/…/linux.rs• L721-886 crates/…/linux.rs• L890-1123 crates/…/linux.rs• L1247-1417 crates/…/linux.rs• L1426-1499 crates/…/linux_dmabuf_import.rs• L80-431 crates/…/wayland_portal_tests.rs• L207-340

X11 shared-memory capture

The Linux X11 backend can use the MIT-SHM service to copy screen pixels through a shared memory segment. It checks that the server supports a safe version, sizes each segment from the image stride, and falls back to the normal X11 image request when shared memory is disabled or unavailable. The CAP_X11_DISABLE_SHM setting provides an explicit opt-out for hosts where the fast path cannot attach a segment.

The shared memory segment is marked for removal after the X server attaches it. This lets the kernel release it after both sides detach, including after a process failure. X11 integration checks compare shared-memory frames with the fallback path for full displays, unaligned regions, resized windows, missing extensions, remote displays, and repeated grabbers.

References: crates/…/linux_shm.rs• L13-64 crates/…/linux_shm.rs• L67-225 crates/…/x11_shm_capture.rs• L184-286 crates/…/x11_shm_capture.rs• L288-405

Platform capture recovery

Capture can stop when a display sleeps, a window disappears, or a graphics device is lost. The recording flow reports the failure through track health and uses platform restart support when the source can be rebuilt. A user stop remains a terminal action and does not start a new capture session.

macOS rebuilds the ScreenCaptureKit content filter and keeps the selected-window and excluded-window rules during a restart. A closed window or unavailable display is reported as a lost target, and the pipeline keeps the media already captured. Windows distinguishes a lost target from a removed Direct3D device. It can recreate the device for the latter and rebuild the capture session for transient closure. Both platforms stop after a bounded number of retries.

Recovery cannot restore a target that no longer exists. The display track is required for a normal recording, so an unrecoverable display failure preserves the local recording as failed or incomplete. Optional track failures remain attached to diagnostics and do not by themselves discard the display media.

References: crates/…/macos.rs• L759-964 crates/…/macos.rs• L1094-1107 crates/…/macos.rs• L1131-1373 crates/…/windows.rs• L501-526 crates/…/windows.rs• L905-1079 crates/…/core.rs• L390-500 crates/…/core.rs• L532-614 crates/…/studio_recording.rs• L1769-1891

Capture diagnostics

Capture diagnostics gives support and sync checks a compact view of the machine and its recent recording behavior. It probes displays, cameras, microphones, audio outputs, storage, and platform graphics support, then adds recent track timing facts and replay hints for the same capture shapes.

The report uses the same display and microphone probes for its device summary and sync matrix hints. Recent recording entries identify the mode, status, creation time, and per-track timing without exposing a capture-target directory name. Home paths are replaced with ~ in report strings and sync-test data. A corrupt recent recording becomes an error on that entry so one bad project does not hide the other entries.

The report is an additive contract. Consumers can accept new fields, while an incompatible shape change requires a schema version change. Platform diagnostics also explain capture and encoding limits, such as Windows graphics-capture support or macOS Metal support, so a recording issue can be related to the host environment.

References: crates/…/diagnostics.rs• L7-19 crates/…/diagnostics.rs• L23-105 crates/…/diagnostics.rs• L471-595 crates/…/diagnostics.rs• L658-767 crates/…/diagnostics.rs• L770-789 crates/…/diagnostics.rs• L791-1297

Input tracks

The recording flow handles video, audio, and input events according to their timing needs. Video sources provide frames, audio sources provide sample blocks, and cursor or keyboard sources provide timestamped project events.

Screen and camera video

Screen video is the main visual record for display, window, and area targets. Camera video is an independent track when enabled, or it becomes the main video track for camera-only recording. The camera feed can serve preview and recording at the same time, while bounded hand-off paths keep a slow recording consumer from blocking capture.

Camera setup uses bounded work and cancellation so repeated device changes do not create unlimited setup work. When a camera frame is late or a downstream queue is full, the pipeline records the loss as health data and protects screen capture first. On Linux instant display recordings, the camera can also be composed into the screen video. A missing or stale camera frame falls back to screen-only output and reports the camera condition rather than stopping the display track.

A studio camera switch keeps the same recording track open while it detaches from the old feed and attaches to the new one. The new feed may have a different size or pixel format, but the track keeps its original output shape and adapts the incoming frames before they reach the recording path.

Native camera capture reports loss at each boundary from the shared camera feed to the recording queue and then to the encoder. This separates camera ingress loss from encoder backpressure and keeps a slow camera path from blocking the display track.

References: crates/…/camera.rs• L30-157 crates/…/camera.rs• L489-741 crates/…/camera.rs• L1037-1143 crates/…/camera.rs• L1335-1479 crates/…/camera.rs• L63-293 crates/…/camera_input.rs• L16-35 crates/…/camera_input.rs• L193-297 crates/…/native_camera.rs• L43-80 crates/…/native_camera.rs• L93-198 crates/…/studio_recording.rs• L1286-1318 crates/…/instant_recording.rs• L1219-1319

Microphone audio

The microphone track reads a selected input device as timestamped audio. It stays aligned with the recording timeline when the device reports a different format, when the stream reconnects, or when the recording applies a mute. A running recording can also move to an already-open replacement feed without changing the track identity.

The audio path converts each device format to the recording format and keeps the input capture timestamp on the converted frame. This preserves duration when the device rate or channel count changes. A short callback stall waits for real samples instead of adding forward-timestamped silence; a sustained outage emits keepalive silence and starts bounded reconnect attempts. This prevents both false timeline growth and a frozen audio track.

On Linux, a microphone or system-audio stream can wait until its requested audio route is confirmed. A replacement stream is accepted only when it belongs to the current recording generation. An unresolved backend failure remains visible at stop instead of being reported as a healthy track. Recording mute keeps the stream cadence intact and changes sample content rather than shifting the timeline. The source also reports a sustained run of exact digital silence while unmuted as a health signal.

Microphone data can also arrive progressively to consumers that need only part of a decoded track. ProgressiveAudio publishes contiguous sample blocks and reports which frames are ready, while a requested window waits only until its full range is available. A failed or dropped loader remains an error; it does not become silent audio or a false successful completion.

References: crates/…/microphone.rs• L21-189 crates/…/microphone.rs• L241-390 crates/…/microphone.rs• L432-527 crates/…/microphone.rs• L576-1046 crates/…/microphone.rs• L1285-1455 crates/…/microphone.rs• L31-80 crates/…/microphone.rs• L166-285 crates/…/microphone.rs• L500-667 crates/…/microphone.rs• L1216-1505 crates/…/microphone.rs• L1744-1855 crates/…/progressive.rs• L137-195 crates/…/progressive.rs• L242-431

System audio

System audio records sound produced by the computer rather than sound from the microphone. macOS receives it from the screen capture stream, Windows uses output loopback, and Linux uses a monitor source from the host audio service. In an audio-only recording, a macOS system-audio stream ending is treated as the end of the recording because no display stream exists to rebuild it.

The track starts at the recording origin even when the first system sound arrives later. This keeps a silent opening from moving the audio track forward and preserves alignment with the display and microphone tracks. On Windows, a changed default output device or a loopback stream error causes the source to rebuild. The source inserts a short silence bridge during a device switch so the audio timeline remains continuous.

On Linux, system-audio setup identifies a monitor route and confirms that audio arrives after the route changes. It retries a failed route setup, limits routing changes to streams owned by the recorder, and restores the prior route when the source stops. This prevents system-audio capture from silently recording the wrong input or leaving another application routed to a monitor source.

References: crates/…/macos.rs• L290-297 crates/…/macos.rs• L508-565 crates/…/macos.rs• L1297-1427 crates/…/windows.rs• L1143-1223 crates/…/windows.rs• L1243-1344 crates/…/windows.rs• L1398-1529 crates/…/linux.rs• L1663-1784 crates/…/linux.rs• L1855-1963 crates/…/linux.rs• L1975-2050 crates/…/linux.rs• L2273-2312 crates/…/core.rs• L2075-2091 crates/…/studio_recording.rs• L1500-1598

Cursor and keyboard events

Cursor capture stores cursor images, cursor movement, mouse clicks, and keyboard presses as project-side event data. It stores each cursor image once and references it from later events. Target-relative coordinates keep those events correct for display, window, and area captures.

Linux window capture uses window-local normalized coordinates so a resize does not change the meaning of the event position.

The event timeline starts at the recording start gate when a recording is primed. The first sample after that gate records the cursor position, so playback has a known position at time zero. Cursor images and incremental event files are written away from the sampling loop. A slow storage path can delay or retry file writes without stopping input sampling; images that remain unsaved are removed from the registered cursor set.

Some Wayland sessions do not allow global input access. In that case the recorder reports that global cursor and keyboard data is unavailable instead of claiming that it captured events. The screen service may still embed the cursor in the video when the desktop grants that permission.

References: crates/…/cursor.rs• L53-110 crates/…/cursor.rs• L218-305 crates/…/cursor.rs• L441-479 crates/…/cursor.rs• L524-731 crates/…/studio_recording.rs• L137-172

Recording modes

The pipeline supports two recording lifecycles. Studio recording builds a project from independent tracks and pause-separated segments, while instant recording favors early media availability through a live segmented stream.

Studio recording

Studio recording owns the active segment and its enabled inputs as one lifecycle. Pause closes the current segment and keeps the cursor state for the next one. Resume creates a new segment, while stop closes the sources, stores segment metadata, and writes the project configuration. Track start times are saved during capture as well as at stop, so an unfinished segment retains useful alignment data.

The display track remains required. Camera, microphone, system audio, cursor, and keyboard data are optional. The pipeline records optional-track failures in recording-diagnostics.json so later recovery can distinguish a degraded project from a recording with an unusable required track. The active pipeline watches for early track completion, treats the display as required, and records optional track failures without discarding the display media.

Stop also has a cleanup result. The recording is publishable only after the platform confirms that capture tasks have stopped. On Linux this is a quiescence acknowledgement. macOS and Windows use a terminal stop acknowledgement. The terminal action is cached, so repeated calls return the same preserve or discard outcome and cannot change an earlier failure into success. If cleanup is not confirmed, the pipeline preserves the local recording and keeps the terminal failure for later stop calls instead of reporting a false success.

On Linux, resume is a cancellable transaction. The next segment is prepared in isolation and is committed only after its capture work is ready and has not already ended. A failed or interrupted cleanup blocks another resume attempt until the pipeline can account for the unfinished work.

References: crates/…/studio_recording.rs• L178-315 crates/…/studio_recording.rs• L414-485 crates/…/studio_recording.rs• L544-763 crates/…/studio_recording.rs• L816-1137 crates/…/studio_recording.rs• L1296-1318 crates/…/studio_recording.rs• L1320-1473 crates/…/studio_recording.rs• L1500-1598 crates/…/studio_recording.rs• L1621-1891 crates/…/studio_recording.rs• L1908-2111

Instant recording

Instant recording writes display segments while capture continues. It can add microphone and system audio to the live stream, and it can use the camera as the main video source in camera-only mode. Completed segment notifications let downstream consumers use media before the recording ends.

Instant output is accepted only when its required tracks and cleanup state are healthy. A terminal track or finalization failure stays terminal across repeated stop or cleanup calls, so a later call cannot turn failed capture into success. Startup cancellation and early handle cleanup still request shutdown through the recording lifecycle rather than leaving capture work untracked. Linux callers must wait for capture quiescence before they reveal or delete output. Linux camera-only mode does not accept system audio, and Linux display mode can place the camera inside the screen video when that option is enabled.

An output with an initialization file but no complete segment is degraded, while an output with no video segments is damaged. Clean instant completion is certified only after the segmented output work finishes successfully; the presence of media files alone does not certify a healthy result.

References: crates/…/instant_recording.rs• L64-273 crates/…/instant_recording.rs• L314-407 crates/…/instant_recording.rs• L427-517 crates/…/instant_recording.rs• L559-633 crates/…/instant_recording.rs• L1100-1153 crates/…/instant_recording.rs• L1188-1469 crates/…/instant_recording.rs• L1494-1571

Timing and runtime health

The pipeline uses source timestamps and one recording epoch to keep tracks aligned. It also bounds how long a slow source can hold up capture, so an encoder, device, or disk problem does not block every input indefinitely.

Shared timeline

Video and audio sources can start at different instants. The output path records source starts, aligns nearby starts, trims small overlaps, and inserts silence for real audio gaps. It treats starts within one audio output buffer as simultaneous and writes the resulting values beside active segments, so crash recovery uses the same alignment as a normal stop. Intermittent system audio is anchored at the pipeline epoch, while device-backed audio can use its first frame as its start. Audio sample counts and the master clock prevent source-rate differences from creating long-term drift.

The start gate lets primed recordings warm up their sources before the user starts. It discards pre-arm video, trims audio that crosses the arm point, and makes the first admitted media define recording time zero. A failsafe opens a gate that was never armed so a caller error does not hold the recording forever.

The video path keeps capture cadence through normal delivery delay and uses wall-clock limits to contain source-clock jumps. On Linux, monotonic capture timestamps remain the basis for frame spacing, while a discontinuity can bridge from the last output time. On other platforms, the path can correct slow source-clock drift without allowing processing stalls to change media cadence. When capture ends between video frame boundaries, the output path can use the last valid frame to close the final interval.

The start gate coordinates the first video and audio media. It trims leading audio or advances the audio timeline when the first frames do not align within the allowed range. A gate timeout releases the audio path without encoder-pair gating rather than holding the recording forever.

References: crates/…/start_gate.rs• L12-158 crates/…/core.rs• L29-75 crates/…/core.rs• L170-190 crates/…/core.rs• L756-845 crates/…/core.rs• L896-1097 crates/…/core.rs• L1326-1664 crates/…/core.rs• L2060-2205 crates/…/frame_pacing.rs• L20-113 crates/…/studio_recording.rs• L1500-1598 crates/…/studio_recording.rs• L2715-2761

Backpressure and health

Every source uses a bounded path into the output pipeline. A short stall budget protects the capture loop; after that budget the source drops a frame or sample block and emits a health event. Runtime health covers frame drops, source stalls, device loss, target loss, timestamp problems, low disk space, digital microphone silence, and media finalization failure.

The pipeline checks free disk space during capture. Low space reports a warning, while exhausted space stops the recording. Required-track health can stop the recording. Optional-track health remains in diagnostics and allows the display recording to continue when the required path is still usable. The watcher treats an early required-track end as terminal and records optional-track errors for the project.

Platform muxers can run in the recording process or in an isolated helper when that platform supports it. If the helper is not available, the pipeline falls back to the in-process path so the requested recording mode remains usable.

References: crates/…/core.rs• L390-505 crates/…/core.rs• L536-718 crates/…/core.rs• L632-713 crates/…/ffmpeg.rs• L1-120 crates/…/macos_fragmented_m4s.rs• L1-120 crates/…/oop_fragmented_m4s_win.rs• L1-120 crates/…/win_fragmented_m4s.rs• L1-120 crates/…/microphone.rs• L1435-1505 crates/…/native_camera.rs• L124-198 crates/…/studio_recording.rs• L1769-1891

Recovery and publication

Recovery turns unfinished segmented media into a complete project or instant output. It first finds complete local fragments, rejects invalid or incomplete data, builds the final media in a private staging area, and publishes only after the source and result pass validation.

Fragment recovery

The recovery manager finds incomplete projects by reading recording metadata and segment folders. It accepts display fragments as the required input and includes camera, microphone, system-audio, and cursor data when those sources exist. It can also rescue a temporary fragment when its media prefix is complete; a truncated or invalid temporary fragment is marked corrupt and is not promoted.

Recovery checks manifest claims, file size, media validity, fragment order, local path boundaries, and required-track diagnostics. It refuses to recover a project that records a required-track failure or that changes while recovery copies and validates the source.

References: crates/…/recovery.rs• L49-75 crates/…/recovery.rs• L162-195 crates/…/recovery.rs• L364-485 crates/…/recovery.rs• L487-717 crates/…/recovery.rs• L809-976 crates/…/recovery.rs• L1221-1345 crates/…/prefix.rs• L1-90

Media finalization

Finalization joins display and camera fragments into playable video and joins microphone and system-audio fragments into finalized audio tracks. It then validates the resulting tracks, updates recording metadata, and creates the project timeline. Instant output follows the same staged pattern and merges video with audio when both are present.

The display duration is checked against the span persisted in the project configuration. This catches a mismatch between the capture timeline and the media that recovery is about to publish. Recovery keeps the original recording when validation or publication fails. Publication does not replace an existing destination, and its fallback copy removes only its own incomplete output.

References: crates/…/recovery.rs• L1137-1279 crates/…/recovery.rs• L1335-1434 crates/…/recovery.rs• L1437-1709 crates/…/recovery.rs• L1712-1931 crates/…/recovery.rs• L1934-2052 crates/…/recovery.rs• L2054-2258 crates/…/prefix.rs• L3-90 crates/…/studio_recording.rs• L2783-3117

Track healing

Track healing repairs older studio recordings whose video timestamps made the display or camera play too slowly. It runs when the project opens, changes timestamps only when the duration and frame pattern give a clear defect signal, and keeps the original media beside the repaired track.

Display repair runs before camera repair because the display provides the main timeline reference. A successful repair updates the project metadata, while an uncertain or failed repair leaves the original track in place.

References: crates/…/track_heal.rs• L1-90 crates/…/track_heal.rs• L118-279 crates/…/track_heal.rs• L286-420

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep ScreenCaptureTarget aligned with display lookup, crop conversion, cursor bounds, and camera-only validation.
  • Keep AudioOnly target handling aligned with target naming, display lookup, cursor bounds, audio-source setup, and the timing-only display stand-in.
  • Keep AudioOnly target handling aligned with target naming, display lookup, cursor bounds, audio-source setup, and the timing-only display stand-in.
  • Keep native window capture rules aligned with excluded-window behavior, target sizing, cursor coordinates, and restart rebuilds on macOS and Windows.
  • Keep logical-to-physical crop conversion aligned with overlay size, high-DPI displays, and encoder output limits.
  • Keep macOS window corner trimming and even-pixel sizing aligned with ScreenCaptureKit source rectangles and output dimensions.
  • Keep Windows GraphicsCaptureItem sizing aligned with the rule that native window capture does not use a display crop.
  • Keep Windows capture cadence accounting separate from real frame drops so high-refresh decimation does not create false health events.
  • Keep first accepted screen-frame startup acknowledgement aligned with source creation, start errors, and target-loss handling.
  • Keep PipeWire DMA-BUF format offers aligned with the modifiers that the EGL import path can read back. Preserve shared-memory and linear fallbacks.
  • Keep Linux DMA-BUF buffer mapping and read synchronization aligned with PipeWire's frame size and stride rules. Tiled frames must remain on the GPU import path.
  • Keep X11 shared-memory stride and segment lifetime aligned with server attach, window resize, and fallback capture behavior.
  • Keep Wayland portal source selection aligned with session detection, PipeWire node setup, cancellation, and portal-session cleanup ownership.
  • Keep Wayland portal cleanup errors distinct from a quiescent stop. An already-removed portal object is safe to close, but a rejected close must remain visible.
  • Keep platform timestamps and system-audio start anchoring aligned with the shared recording epoch.
  • Keep the start gate aligned across first video frames, first audio samples, cursor events, and primed recordings.
  • Keep frame pacing aligned with pause behavior, source timestamps, and the rule that only real stalls produce repeats.
  • Keep the active-track watcher aligned with the required display rule. Optional track failure must remain diagnostic while early display completion remains terminal.
  • Keep producer-stop errors separate from media-finalization errors. Unconfirmed cleanup must not be reported as usable media.
  • Keep persisted segment start times aligned between live updates, clean stop, and recovery. Use the same epoch and near-start snapping rules.
  • Keep required display failures separate from optional camera, microphone, and system-audio failures in both stop results and recording-diagnostics.json.
  • Keep camera setup cancellation, native ingress loss, fan-out loss, and encoder-queue loss visible as separate health signals.
  • Keep camera track switches aligned with replacement queue hand-off, old-feed release, new-camera sizing, and the track's original output format.
  • Keep native camera ingress capacity aligned with frame size, frame rate, shared-feed mailbox bursts, and the byte budget.
  • Keep camera track switches aligned with replacement queue hand-off, old-feed release, new-camera sizing, and the track's original output format.
  • Keep native camera ingress capacity aligned with frame size, frame rate, shared-feed mailbox bursts, and the byte budget.
  • Keep microphone rate inference, pending-sample timestamp normalization, Linux route confirmation, and reconnect generations aligned with sample timestamps and audio continuity.
  • Keep microphone stall handling aligned with the rule that late real samples own their original time. Only a sustained outage may add keepalive silence.
  • Keep microphone digital-silence health separate from user mute and from missing callback data. Do not report mute as a device fault.
  • Keep recording mute as a payload change. It must not change stream cadence, sample timing, or muxer alignment.
  • Keep stop and resume cleanup acknowledgements aligned with the rule that unconfirmed capture preserves local media.
  • Keep Linux terminal stop intent caching aligned with quiescence state so repeated preserve or discard calls cannot race or change the result.
  • Keep Linux resume preparation transactional. Do not commit a new segment until capture is ready, and do not allow a failed cleanup to be hidden by a later resume.
  • Keep instant recording lifecycle ownership aligned with startup cancellation, handle-drop cleanup, quiescence acknowledgement, and terminal stop errors.
  • Keep clean instant completion tied to successful segmented mux work rather than to the presence of media files alone.
  • Keep progressive audio windows explicit about available sample ranges. A ready prefix must not imply end-of-file or silence.
  • Keep bounded output queues, disk-space status, and digital-silence health aligned with the events that downstream recovery and diagnostics consume.
  • Keep temporary fragment rescue aligned with complete media prefixes and corruption health events.
  • Keep recovery validation aligned with manifests, source snapshots, local path boundaries, and display-duration checks.
  • Keep non-replacing publication aligned across platform rename support and the durable copy fallback.
  • Keep instant camera-only input limits aligned with system-audio validation and output completion rules.
  • Keep load-time track healing aligned with backup names, metadata updates, and one-time repair behavior.
  • Keep the diagnostic report schema version aligned with incompatible report changes, while report consumers continue to accept additive fields.
  • Keep matrix hints derived from the same display and microphone probes as the report so sync replay matches the captured snapshot.
  • Keep recent-recording digests free of target-title directory names and redact home paths in report strings, errors, and sync-test data.

Important failure modes

TriggerConsequenceGuard
A selected display or window cannot be resolvedThe required display track cannot start.Resolve the target and its display before creating the capture pipeline.
An audio-only target is treated as a normal display targetSetup waits for a display that the recording does not need, or the wrong output path is selected.Keep audio-only validation separate and use the timing-only display source.
A selected macOS window is excluded from recordingsA direct window filter would bypass the exclusion.Use the display-crop path with excluded windows.
A crop uses the wrong coordinate space on a high-DPI displayThe recording can contain only part of the selected area.Convert logical bounds to physical bounds and clamp them to the display.
A macOS window capture includes rounded outer pixelsThe output can contain transparent corners that become black.Trim the window crop and fit the native window capture to the output.
A Windows window target is treated as a display cropThe recording stays tied to the window's old position or has the wrong size.Capture the window's GraphicsCaptureItem and derive output size from it.
Windows delivers updates above the requested frame rateThe recording can process excess frames and report misleading drops.Apply the cadence gate before conversion and exclude decimated frames from drop health.
Windows capture starts without an accepted screen frameThe recording can report success while no visual track exists.Require an accepted first frame before startup completes.
A Wayland compositor sends a tiled DMA-BUF that no usable GPU can importThe Linux screen frame cannot enter the common pixel path.Negotiate supported modifiers and retain shared-memory or linear fallback paths.
Wayland startup is cancelled or PipeWire setup fails after a portal session is createdThe portal session can remain live and hold capture permission resources.Keep session cleanup under the recording lifetime and wait for its close result.
A Wayland portal close is rejected during stopCleanup is not quiescent even though the PipeWire remote has ended.Preserve the cleanup error and do not report a confirmed stop. Treat already-missing portal objects as already closed.
A Wayland producer supplies an unmapped linear DMA-BUF with an invalid size or strideThe frame is rejected instead of producing an out-of-bounds or corrupted image.Map only after checking the descriptor size, synchronize the read, and validate each copied row.
X11 MIT-SHM is missing or the server cannot attach a segmentCapture uses the normal X11 image path instead of failing the recording.Check the extension and attach result, then fall back without retaining the segment.
A platform capture source stops unexpectedlyThe pipeline retries when possible or preserves the recording as failed or incomplete.Platform restart handling and required-track health state.
A required studio track ends before the user stops recordingThe recording is marked failed and other capture paths are cancelled.Watch track completion and treat the display as a required track.
A Direct3D device is removedWindows screen capture stops until its graphics device and session are rebuilt.Classify device loss separately and recreate the device before restart.
A camera setup or fan-out mailbox stays fullCamera frames are lost and the recording becomes degraded without blocking the display.Use bounded camera paths and emit health data at each loss boundary.
A camera switch closes the old queue before the replacement is visibleThe recording can end the camera track instead of continuing with the new device.Queue the replacement before allowing the old queue to close.
A replacement camera changes size or pixel formatFrames can be rejected or reach the encoder with the wrong shape.Keep the track's original format and scale replacement frames to it.
Native camera ingress exceeds its time or byte budgetMemory use can grow or frames can be lost without clear source attribution.Bound ingress by frame time and retained bytes and report feed, ingress, and encoder losses separately.
A microphone callback is late for less than the sustained-outage windowSynthetic silence can extend the audio timeline beyond the real samples when they arrive.Wait for late samples and let timestamp reconciliation handle the short gap.
A microphone remains stalled for a sustained periodThe audio track can stop advancing while reconnect work runs.Emit short keepalive silence, then retry reconnect with bounded backoff.
An unmuted microphone delivers exact digital silence for a sustained runThe recording can contain silence because another process holds or suppresses the input.Emit a digital-silence health event, while keeping the samples in the track.
A newer camera or microphone selection replaces an older setupLate frames from the old setup can enter the new recording.Cancel old setup work and accept frames only for the current generation.
The default Windows output device changes during captureSystem audio can stop or become misaligned with the display.Rebuild loopback capture and insert a short silence bridge.
Callback timing briefly suggests a new microphone rateAudio can be resampled at the wrong ratio and change pitch or duration.Require repeated rate agreement before changing the active rate.
A Linux audio callback arrives before its requested route is confirmedSamples can come from the old route or the wrong system-audio source.Admit samples only after route confirmation.
A source queue stays full past its stall budgetA frame or sample block is dropped and the source reports a stall.Use bounded queues with a short send budget and emit health events.
A source clock reports repeated bad timestampsThe affected timeline can stop rather than produce unbounded time errors.Keep the last valid time, resync large jumps, and stop after repeated anomalies.
A primed start gate is never armedMedia can wait until the recording appears stuck.Open the gate after its failsafe interval and report the caller error.
Disk space is exhausted during captureThe recording stops before output can be written safely.Poll the destination and make exhausted space a terminal health state.
An optional track fails during capture or stopThe display recording can continue, but the project is degraded.Record the track failure in diagnostics and omit only that optional output.
An audio-only segment has no timing ticksRecovery can publish a false empty display track.Write the black stand-in only when the timing source has a measured span.
Capture cleanup is not confirmedPublishing or deleting output can race with active capture work.Require platform stop acknowledgement or Linux quiescence before publication or deletion.
A producer stop error is mixed with a media-finalization errorThe result can claim usable media while capture cleanup is unknown.Classify stop errors separately and preserve the local recording until all producers are accounted for.
A Linux system-audio route changes without post-route audioThe recording can contain the wrong source or a silent system-audio track.Confirm a new owned stream and audio timestamp after routing, retry setup, and restore the prior route on stop.
Instant startup is cancelled or its owner is dropped before shutdown acknowledgementCapture work can outlive the caller, or the result can be exposed before cleanup finishes.Keep lifecycle ownership through shutdown and require a quiescence acknowledgement.
A Linux resume is cancelled after its next segment starts buildingAn untracked segment or live capture task can remain beside the paused recording.Cancel and join the child scope, discard only its segment directory, and block later resume when cleanup is unconfirmed.
A required instant track ends early or finalization failsRepeated stop calls could otherwise report a false successful completion.Preserve the first terminal stop error across later cleanup calls.
Progressive audio has a discontinuity or invalid blockAudio loading fails instead of exposing incorrect samples.Require contiguous sample starts, stable channels, and complete sample frames.
A temporary media fragment has a truncated prefixRecovery skips it and records a corruption health event.Validate the fragment prefix before promoting it as complete.
Recording metadata or media changes during recoveryRecovery stops without replacing the source.Stage inputs, compare snapshots, validate, then publish.
A required track failure remains in diagnosticsRecovery refuses to present partial media as a healthy recording.Check required-track diagnostics before finalization.
Instant camera-only mode requests system audio on LinuxRecording setup is rejected.Validate the target and audio combination before pipeline creation.
A track has an old stretched timestamp patternVideo plays slowly or loses sync with the project timeline.Run conservative load-time healing and keep the original until verification passes.
A recent recording directory is corrupt or unreadableThe diagnostic report can lose useful entries if collection stops at the bad project.Store an error on that digest and continue with the remaining .cap directories.
A diagnostic report changes incompatibly without a schema updateReport consumers can misread or reject the environment snapshot.Bump the schema version for incompatible shape changes and keep additive fields optional.
A sync-test payload or error contains a home pathA support report can expose the user's account name or local path.Redact string values before adding sync data to the report.
Report device probes and matrix-hint probes see different hardwareA replayed sync matrix does not represent the reported machine.Probe displays and microphones once and derive both report sections from those results.

Key files

FileWhy to read it
crates/…/studio_recording.rsShows how capture sources become pause-separated project segments, how active tracks report failures, and how stop health is preserved.
crates/…/instant_recording.rsShows the live segmented recording lifecycle, cleanup acknowledgement, and early output completion.
crates/…/capture_pipeline.rsShows how targets select platform capture and how each platform selects its recording output path.
crates/…/mod.rsDefines capture targets and the shared cross-platform capture contract.
crates/…/audio_only.rsDefines the audio-only timing source and the black display stand-in used to preserve the normal project lifecycle.
crates/…/linux.rsShows Linux X11 and Wayland stream negotiation, shared and DMA-BUF frame handling, and system-audio route ownership and restoration.
crates/…/wayland_portal_tests.rsShows that Wayland portal sessions close on cancellation, failed startup, repeated stop, and portal close errors.
crates/…/linux_dmabuf_import.rsShows how Linux imports tiled DMA-BUF frames across compatible GPUs and returns RGBA pixels.
crates/…/linux_shm.rsShows the Linux X11 shared-memory path, safe fallback, and segment cleanup.
crates/…/x11_shm_capture.rsShows the X11 backend contract through pixel, resize, fallback, and leak checks.
crates/…/macos.rsShows the macOS screen and system-audio capture path, window filtering, and restart behavior.
crates/…/windows.rsShows the Windows display, window, graphics-device, cadence, first-frame, and loopback-audio paths.
crates/…/camera.rsShows the camera feed shared by preview and recording and its bounded fan-out.
crates/…/camera_input.rsShows how one camera track moves between devices without ending the segment.
crates/…/camera.rsShows the decoded camera path and frame adaptation when the source shape changes.
crates/…/native_camera.rsShows native camera ingress sizing and loss reporting at feed and encoder boundaries.
crates/…/microphone.rsShows microphone setup, rate behavior, mute timing, route confirmation, reconnect health, and stream cleanup.
crates/…/microphone.rsShows microphone format conversion, replacement-feed switching, stall recovery, digital-silence health, and stop cleanup.
crates/…/progressive.rsShows progressive audio loading and range readiness for downstream audio consumers.
crates/…/cursor.rsShows how cursor and keyboard input becomes project event data and how file writes stay off the sampling loop.
crates/…/core.rsShows shared timing, start alignment, backpressure, disk checks, source health, and cleanup rules.
crates/…/start_gate.rsShows how primed media waits for the recording cue and establishes time zero.
crates/…/frame_pacing.rsShows how Windows handles real frame stalls without mistiming late frames.
crates/…/recovery.rsShows fragment inspection, staged finalization, validation, and publication.
crates/…/prefix.rsShows safe promotion of complete temporary media without replacing existing output.
crates/…/track_heal.rsShows conservative repair of older stretched video tracks.
crates/…/diagnostics.rsShows the environment report, recent-recording timing summary, sync replay hints, and path redaction used to explain capture issues.