Back to Cap

Cap Playback Benchmark Results

crates/editor/PLAYBACK-BENCHMARKS.md

latest7.2 KB
Original Source

Cap Playback Benchmark Results

This document tracks performance benchmarks for Cap's playback and decoding system over time. Each benchmark run is timestamped, enabling comparison across different versions, configurations, and hardware.

Quick Reference

Performance Targets

MetricTargetTolerance
Decoder Init<200ms-
Decode Latency (p95)<50ms-
Effective FPS≥30 fps±2 fps
Decode Jitter<10ms-
A/V Sync (mic↔video)<100ms-
A/V Sync (system↔video)<100ms-
Camera-Display Drift<100ms-

Test Categories

  • Decoder Tests: Init time, hardware acceleration detection, fallback handling
  • Playback Tests: Sequential decode, frame retrieval, latency percentiles
  • Audio Sync Tests: Mic-video sync, system audio-video sync
  • Camera Sync Tests: Camera-display drift, frame count alignment
  • Decode Benchmark: Creation, sequential, seek, and random access performance

Supported Formats

FormatExtensionHardware AccelNotes
MP4 (H.264).mp4✅ VideoToolbox (macOS), MediaFoundation (Win)Primary format
Fragmented MP4init.mp4 + .m4sSegmented recording
MP4 (HEVC/H.265).mp4Higher compression
WebM (VP9).webm⚠️ Software fallbackWeb compatibility

Running Benchmarks

Playback Validation (uses recording test outputs)

bash
# Run full playback validation on recordings from real-device-test-runner
cargo run -p cap-recording --example playback-test-runner -- full

# Run specific test categories
cargo run -p cap-recording --example playback-test-runner -- decoder
cargo run -p cap-recording --example playback-test-runner -- playback
cargo run -p cap-recording --example playback-test-runner -- audio-sync
cargo run -p cap-recording --example playback-test-runner -- camera-sync

# Test a specific recording
cargo run -p cap-recording --example playback-test-runner -- --recording-path /path/to/recording full

# List available recordings
cargo run -p cap-recording --example playback-test-runner -- list

Decode Performance Benchmark

bash
# Benchmark decode performance on a video file
cargo run -p cap-editor --example decode-benchmark -- --video /path/to/video.mp4

# With custom FPS and iterations
cargo run -p cap-editor --example decode-benchmark -- --video /path/to/video.mp4 --fps 60 --iterations 50

Combined Workflow (Recording → Playback)

bash
# Step 1: Create test recordings with outputs kept
cargo run -p cap-recording --example real-device-test-runner -- full --keep-outputs

# Step 2: Validate playback of those recordings
cargo run -p cap-recording --example playback-test-runner -- full

Benchmark History

<!-- PLAYBACK_BENCHMARK_RESULTS_START --> <!-- PLAYBACK_BENCHMARK_RESULTS_END -->

Detailed Metric Definitions

Decoder Metrics

MetricDescriptionHow Measured
Init TimeTime to create and initialize decoderspawn_decoder() latency
Decoder TypeBackend used (AVAssetReader, FFmpeg, MediaFoundation)Reported by decoder
Hardware AccelWhether GPU decoding is activeDecoder capability check
Fallback ReasonWhy software decoding was used (if applicable)Decoder error chain

Playback Metrics

MetricDescriptionHow Measured
Frames DecodedSuccessfully retrieved framesCount of non-None results
Failed FramesFrames that failed to decodeCount of None results
Avg Decode TimeMean frame retrieval latencyAvg of all frame times
Min/Max Decode TimeLatency rangeMin/max of frame times
P50/P95/P99Latency percentilesSorted distribution
Effective FPSActual decode throughputframes / elapsed_time
JitterDecode time variance (std dev)sqrt(variance)

Audio Sync Metrics

MetricDescriptionHow Measured
Mic DurationTotal mic audio lengthsample_count / sample_rate
System Audio DurationTotal system audio lengthsample_count / sample_rate
Video DurationTotal video lengthFFmpeg duration query
Mic-Video DiffAudio/video duration mismatch
System-Video DiffSystem audio/video mismatch
Detected Sync OffsetCross-correlation sync analysisSyncAnalyzer result
Sync ConfidenceReliability of sync detection0.0 - 1.0 score

Camera Sync Metrics

MetricDescriptionHow Measured
Camera Start TimeRecorded start timestampMetadata
Display Start TimeDisplay recording startMetadata
DriftCamera vs display timing offset
Camera Frame CountFrames decoded from cameraTest loop count
Display Frame CountFrames decoded from displayTest loop count

Analysis Guidelines

When analyzing benchmark results, focus on:

  1. Hardware Acceleration: Verify decoder is using GPU when available
  2. Latency Spikes: Check P95/P99 for outlier decode times
  3. Format Comparison: Compare MP4 vs fragmented performance
  4. A/V Sync Drift: Identify recordings with sync issues
  5. Regression Detection: Compare against historical baselines

Common Issues & Solutions

IssuePossible CausesInvestigation Steps
High Init TimeCodec probe delay, HW initCheck decoder type, try software fallback
Low Effective FPSSlow decode, I/O boundProfile decode times, check disk speed
High JitterThread contention, GCCheck system load, memory pressure
A/V Sync DriftTimestamp mismatch, sample rateVerify audio metadata, check recording
Camera DriftStart time alignmentCheck segment start_time values
Decoder FallbackMissing codec, HW unavailableCheck codec support, permissions

Resolution-Specific Expectations

ResolutionTarget Decode (p95)Notes
1080p (1920x1080)<30msStandard target
1440p (2560x1440)<40msHigh DPI displays
4K (3840x2160)<60msMay need HW accel
5K (5120x2880)<80msApple displays

Decoder Implementation Details

macOS (AVAssetReader)

  • Primary decoder using VideoToolbox hardware acceleration
  • Automatic fallback to FFmpeg for unsupported formats
  • Best performance for H.264/HEVC on Apple Silicon

Windows (MediaFoundation)

  • Primary decoder using DXVA2/D3D11 hardware acceleration
  • Automatic fallback to FFmpeg for unsupported formats
  • Best performance for H.264/HEVC with compatible GPU

FFmpeg (Software Fallback)

  • Cross-platform software decoding
  • Supports widest format range
  • Used when hardware acceleration unavailable or fails