Architecture Overview
Segra uses a layered architecture to interact with OBS:Core Components
OBSService - Backend/Recorder/OBSService.cs
OBSService - Backend/Recorder/OBSService.cs
The
OBSService class is the central hub for all recording operations. It manages:- OBS context initialization and shutdown
- Video encoder configuration (NVENC, AMF, QSV, x264)
- Audio source management (microphones, desktop audio, game audio)
- Scene composition with game capture and display capture
- Recording outputs (sessions, replay buffer, hybrid mode)
ObsKit.NET Integration
ObsKit.NET Integration
ObsKit.NET provides a fluent, type-safe API for interacting with OBS. Segra uses it for:
- Video/audio encoder creation
- Source management (GameCapture, MonitorCapture, AudioInputCapture)
- Output handling (RecordingOutput, ReplayBuffer)
- .NET events for OBS callbacks (
Hooked/UnhookedonGameCapture,Saved/StoppedonReplayBuffer,StoppedonRecordingOutput) — replaces the older rawConnectSignal(OutputSignal.*)handles - Global hotkey registration via
Obs.RegisterHotkey(...)(see Hotkeys)
Segra.csproj.GPU Vendor Detection
GPU Vendor Detection
Segra automatically detects your GPU vendor (NVIDIA, AMD, Intel) to select the optimal hardware encoder:
- NVIDIA: NVENC (H.264/HEVC)
- AMD: AMF (H.264/HEVC)
- Intel: QSV (H.264/HEVC)
- Fallback: x264 (software encoding)
Initialization Process
When Segra starts, it initializes OBS through several stages:1
Check OBS Installation
Verifies that
obs.dll exists in the application directory. If missing, Segra downloads the appropriate OBS version from Segra’s CDN. Current builds bundle OBS 30.1.1, 31.1.2, 32.1.2, 32.2.1, and 32.2.2 with FFmpeg 9.0.1; the automatic default (when selectedOBSVersion is null) is the latest non-beta build.2
Initialize OBS Context
Creates an OBS context with the fluent API:
3
Detect Available Encoders
Queries OBS for available video encoders and stores them in application state for the settings UI.
4
Start Game Detection
Begins monitoring Windows processes for game launches using WMI event watchers.
Recording Pipeline
Scene Composition
Segra creates a layered scene with multiple capture sources:Layer Order (bottom to top):
- Display Capture (fallback layer)
- Game Capture (primary layer when hooked)
- Audio sources (microphones, desktop audio, game audio)
Game Capture Hooking
Segra uses OBS’s game capture plugin to hook directly into games:Audio Routing
Segra supports three audio output modes:All Audio
Records all desktop audio sources (default behavior)
Game Only
Records only game audio using OBS’s
capture_audio featureGame + Discord
Records game audio and Discord voice chat separately
- Mutes desktop audio sources
- Unmutes game audio and Discord sources (if enabled)
- Switches back to desktop audio when the game unhooks
Encoder Configuration
Segra configures encoders based on user settings:Recording Modes
Segra supports three recording modes, each using different OBS output types:Session Recording
UsesRecordingOutput to record the entire gaming session to an MP4 file. Segra always attempts the Hybrid MP4 muxer (crash-resilient, chapter markers; OBS 30.2+) and transparently falls back to the plain ffmpeg muxer when the running OBS build doesn’t register mp4_output:
Replay Buffer
UsesReplayBuffer to maintain a rolling buffer in memory:
Hybrid Mode
Runs both session recording and replay buffer simultaneously, allowing:- Full session recording with bookmarks
- Instant replay saving during gameplay
- Separate file organization
Separate Audio Tracks
Segra can record up to 6 audio tracks using OBS’s multi-track support:1
Track 1 - Master Mix
All audio sources combined (always present)
2
Tracks 2-6 - Individual Sources
Up to 5 separate audio sources (microphones, game audio, Discord)
Display Capture Methods
Segra supports three display capture methods (Auto is the default and picks the best of the two backends below for your hardware):
Resource Management
Segra follows strict resource disposal patterns to prevent memory leaks:1
Stop Outputs
Gracefully stop recording/replay buffer with 30-second timeout
2
Dispose Scene
Remove and dispose all scene items and the scene itself
3
Dispose Sources
Release game capture, display capture, and audio sources
4
Clear Encoders
Encoders are automatically disposed by ObsKit.NET when outputs stop
Log Processing
OBS log messages are processed asynchronously using channels to prevent blocking:Related Resources
ObsKit.NET
Modern C# wrapper for OBS Studio
OBS Studio
Free and open source recording software
Performance
Optimize recording performance
Troubleshooting
Common issues and solutions