Skip to main content
Segra’s recording engine is built on top of Open Broadcaster Software (OBS) using ObsKit.NET, a modern C# wrapper that provides type-safe access to OBS’s powerful recording capabilities.

Architecture Overview

Segra uses a layered architecture to interact with OBS:
Segra Application

   ObsKit.NET (C# Wrapper)

   OBS Studio (libobs)

  Hardware Encoders (NVENC/AMF/QSV)

Core Components

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 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)
  • Signal handling for events (hooked/unhooked, replay saved)
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.
2

Initialize OBS Context

Creates an OBS context with the fluent API:
_obsContext = Obs.Initialize(config =>
{
    config
        .WithLocale("en-US")
        .WithDataPath("./data/libobs/")
        .WithModulePath("./obs-plugins/64bit/", "./data/obs-plugins/%module%/")
        .WithVideo(v => v.Resolution(1920, 1080).Fps(60))
        .WithAudio(a => a.WithSampleRate(44100).WithSpeakers(SpeakerLayout.Stereo))
        .WithLogging((level, message) => { /* Log processing */ });
});
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):
  1. Display Capture (fallback layer)
  2. Game Capture (primary layer when hooked)
  3. Audio sources (microphones, desktop audio, game audio)

Game Capture Hooking

Segra uses OBS’s game capture plugin to hook directly into games:
GameCaptureSource = new GameCapture("gameplay", GameCapture.CaptureMode.SpecificWindow);
GameCaptureSource.SetWindow($"*:*:{fileName}");

// Subscribe to hook events
GameCaptureSource.Hooked += OnGameCaptureHookedEvent;
GameCaptureSource.Unhooked += OnGameCaptureUnhookedEvent;
Some applications are blacklisted by OBS and cannot be captured using game capture:
  • explorer.exe, chrome.exe, discord.exe, firefox.exe
  • Steam, Battle.net, Origin launchers
  • Windows system apps
Segra automatically falls back to display capture for these applications.

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 feature

Game + Discord

Records game audio and Discord voice chat separately
When game capture hooks successfully, Segra automatically:
  • 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:
videoEncoderSettings.Set("rate_control", "CBR");
videoEncoderSettings.Set("bitrate", targetBitrateKbps);
videoEncoderSettings.Set("max_bitrate", targetBitrateKbps);

Recording Modes

Segra supports three recording modes, each using different OBS output types:

Session Recording

Uses RecordingOutput to record the entire gaming session to an MP4 file:
_output = new RecordingOutput("simple_output", videoOutputPath);
_output.SetFormat(RecordingFormat.HybridMp4);
_output.WithVideoEncoder(_videoEncoder);
_output.WithAudioEncoder(_audioEncoder, track: 0);
_output.Start();

Replay Buffer

Uses ReplayBuffer to maintain a rolling buffer in memory:
_bufferOutput = new ReplayBuffer(
    "replay_buffer_output",
    Settings.Instance.ReplayBufferDuration,
    Settings.Instance.ReplayBufferMaxSize
);
_bufferOutput.SetDirectory(bufferDir);
_bufferOutput.Start();

// Save the buffer when user presses hotkey
_bufferOutput.Save();

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)
// Assign source to multiple tracks
uint mixersMask = (1u << 0) | (1u << (trackIndex + 1));
allAudioSources[i].AudioMixers = mixersMask;

// Create encoder for each track
for (int t = 0; t < trackCount; t++)
{
    var audioEncoder = AudioEncoder.CreateAac(encoderName, 128, t);
    _audioEncoders.Add(audioEncoder);
}
Separate audio tracks enable advanced editing workflows where you can independently control game audio, microphone, and Discord volumes in post-production.

Display Capture Methods

Segra supports two display capture methods:
MethodTechnologyPerformanceCompatibility
DXGIDesktop Duplication APIHighWindows 8+
WGCWindows Graphics CaptureVery HighWindows 10 1903+
AutoSelects best available-All versions
var captureMethod = Settings.Instance.DisplayCaptureMethod switch
{
    DisplayCaptureMethod.DXGI => MonitorCaptureMethod.DesktopDuplication,
    DisplayCaptureMethod.WGC => MonitorCaptureMethod.WindowsGraphicsCapture,
    _ => MonitorCaptureMethod.Auto
};

_displaySource = MonitorCapture.FromMonitor(monitorIndex, "display")
    .SetCaptureMethod(captureMethod);

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
Never dispose OBS resources while they are still in use. Always stop outputs before disposing sources and encoders.

Log Processing

OBS log messages are processed asynchronously using channels to prevent blocking:
private static readonly Channel<(int level, string message)> _logChannel =
    Channel.CreateUnbounded<(int, string)>(new UnboundedChannelOptions
    {
        SingleReader = true,
        SingleWriter = false
    });

// OBS logging callback (non-blocking)
.WithLogging((level, message) =>
{
    _logChannel.Writer.TryWrite(((int)level, message));
})

// Background processing
await foreach (var (level, formattedMessage) in _logChannel.Reader.ReadAllAsync())
{
    Log.Information($"{(ObsLogLevel)level}: {formattedMessage}");
}
This prevents OBS’s internal logging thread from being blocked by Serilog’s file I/O operations.