Skip to main content

Overview

This guide covers performance optimization across video encoding, audio processing, capture pipeline, and network configuration. All settings reference actual configuration from config.json.

Video Encoding Optimization

Bitrate Configuration

Balance quality and latency with bitrate settings:
Tuning Guidelines: Network Conditions:
  • Excellent (< 20ms, < 1% loss): Use bitrateMax
  • Good (20-50ms, 1-2% loss): Use bitrateStart
  • Fair (50-100ms, 2-5% loss): Reduce to bitrateMin
  • Poor (>100ms, >5% loss): Consider reducing bitrateMin

Encoder Presets

NVENC preset affects encoding speed and quality:
Preset Selection:
  • p1 - Fastest, lowest quality, ~1-2ms encoding latency
  • p2 - Fast, good quality, ~2-3ms latency (default)
  • p3 - Balanced, better quality, ~3-5ms latency
  • p4 - High quality, ~5-8ms latency
  • p5-p7 - Highest quality, 10-20ms+ latency (not recommended for streaming)
Rate Control Modes:
  • cbr (Constant Bitrate) - Predictable bandwidth, best for streaming
  • vbr (Variable Bitrate) - Better quality, less predictable
  • vbr_hq - Highest quality, highest latency

Advanced Encoder Settings

Low-Latency Profile:
High-Quality Profile:

Bitrate Adaptation

Automatic bitrate adjustment based on network conditions:
Tuning for Stability:
  • Increase cleanSamplesRequired to 5-10 for more stable bitrate
  • Increase decreaseCooldownMs to 2000-3000ms to prevent oscillation
  • Reduce increaseStepBps to 500000 (500 Kbps) for gradual ramp-up

Frame Rate Pacing

Common Frame Rates:
  • 30fps: pacingFixedUs: 33333
  • 60fps: pacingFixedUs: 16666 (default)
  • 90fps: pacingFixedUs: 11111
  • 120fps: pacingFixedUs: 8333
  • 144fps: pacingFixedUs: 6944

Audio Latency Optimization

Frame Size and Buffering

Smaller frame sizes reduce latency but increase CPU overhead:
Frame Size Trade-offs: Recommendation: Use 10ms for competitive gaming, 20ms for casual use.

Ultra-Low Latency Mode

Ultra-Low Profile (Experimental):
⚠️ Warning: Ultra-low latency increases CPU usage and packet loss sensitivity.

Audio Bitrate Adaptation

Conservative Profile:

WASAPI Configuration

Exclusive Mode Trade-off:
  • ✅ Pros: 2-3ms lower latency, more consistent timing
  • ❌ Cons: Blocks other applications from audio device

Capture Performance

MMCSS Priority

Multimedia Class Scheduler Service ensures consistent timing:
Priority Levels:
  • 1-2: Background capture
  • 3-4: Normal streaming (recommended)
  • 5-6: High priority for demanding games
  • 7: Critical priority (may starve other processes)
Go Thread Priority:

Frame Pool and Queue Depth

Low-Latency Profile:
High-Throughput Profile:

Skip Unchanged Frames

Reduces bandwidth and CPU for static content (menus, lobbies).

Adaptive Backoff

Set adaptiveBackoff: true if capture frequently reports DXGI_ERROR_WAIT_TIMEOUT.

Network Optimization

TURN Server Placement

For clients behind restrictive NAT/firewalls: Environment Variables:
Metered TURN Configuration:
Placement Best Practices:
  • Deploy TURN servers in same region as hosts
  • Use multiple TURN servers for redundancy
  • Monitor TURN bandwidth usage (relay is expensive)
  • Set expirySeconds to match average session length (default: 3600s)

ICE Configuration

WebRTC connection establishment:
Connection Priority:
  1. Host - Direct connection (lowest latency)
  2. Server Reflexive - Via STUN (low latency)
  3. Relay - Via TURN (higher latency, always works)

Buffer Pool Optimization

Tiers Explained:
  • 128-512B: Audio frames, small RTP packets
  • 1500B: Standard MTU size
  • 4KB-32KB: 1080p video frames
  • 64KB-256KB: 4K low-motion frames
  • 512KB-1MB: 4K high-motion frames
Memory Tuning:
Reduce preallocation counts if memory is constrained.

Input Processing Optimization

Adaptive Quality Control

Input events are prioritized based on network conditions.

Thread Priority

Priority 15 = THREAD_PRIORITY_TIME_CRITICAL for lowest input latency.

Garbage Collection Tuning

Memory Constrained:
Performance Critical:

Performance Monitoring

Track these metrics to validate tuning: Video:
  • Glass-to-glass latency < 50ms
  • Encoder latency < 5ms
  • Frame drops < 1%
  • Bitrate stability (±10% variance)
Audio:
  • One-way latency < 40ms
  • Packet loss < 2%
  • No buffer underruns
  • Queue depth < 2.0 average
Capture:
  • Frame time consistency (low jitter)
  • GPU copy time < 1ms
  • Queue never reaches maxQueueDepth
Network:
  • RTT < 50ms
  • Jitter < 5ms
  • ICE connection via host/srflx (not relay)

Next Steps