CrabCamera 🦀
Production-ready desktop camera & audio plugin for Tauri applications.

CrabCamera is the first production-ready desktop camera + audio plugin for Tauri—unified camera and audio access across Windows, macOS, and Linux with professional controls, synchronized A/V recording, and zero-config setup.
Free forever. MIT license. No asterisks.
Quick Start
Installation
[]
= { = "0.9", = ["recording", "audio"] }
= { = "2.0" }
Register the plugin
// src-tauri/src/main.rs
Initialize and capture
import from '@tauri-apps/api/core';
// Initialize (no parameters needed—CrabCamera discovers cameras automatically)
await ;
// Capture a photo (device_id and format are optional; defaults to camera 0)
const frame = await ;
All commands use the
plugin:crabcamera|prefix when called viainvoke.
For vanilla JS (no bundler), enable withGlobalTauri: true in tauri.conf.json and use window.__TAURI__.core.invoke.
Using CrabCamera from Rust
CrabCamera is not Tauri-only. Three additional entry points exist for direct Rust usage:
// Direct platform camera (no Tauri required)
use ;
let camera = new?;
let frame = camera.capture_frame?;
// Headless session (server / CLI context)
use HeadlessSession;
let session = new?;
// CLI binary
// cargo run --bin crabcamera-cli -- --help
See examples/quick_test.rs to verify your hardware works before building anything else.
Examples
Every example runs with cargo run --example <name>.
Verify hardware
| Example | What it does |
|---|---|
quick_test |
List cameras, warm up, take a photo—start here |
hardware_audit |
Tests every CrabCamera command against real hardware |
functional_test |
Full capture + recording flow with proper warm-up |
visual_camera_test |
Saves actual frames so you can see what the camera sees |
Recording
| Example | What it does |
|---|---|
record_video |
Records 5 seconds of video to MP4 |
live_av_recording |
Full A/V recording with microphone sync |
live_audio_test |
Audio pipeline: enumerate device, capture PCM, encode Opus |
save_test_output |
Saves a raw frame, a CrabCamera frame, and a 3-second MP4 |
Advanced capture
| Example | What it does |
|---|---|
smart_capture_demo |
Smart Trigger—auto-captures when image quality is stable |
camera_preview |
Start/stop preview stream and capture a frame |
camera_warmup_analysis |
How long does your camera need before frames are valid? |
Low-level debugging
| Example | What it does |
|---|---|
direct_capture |
Raw nokhwa capture at native resolution (bypasses CrabCamera) |
raw_nokhwa_test |
Tests the nokhwa layer directly |
format_debug |
Inspects camera format negotiation |
reuse_debug |
Debugs camera handle reuse behavior |
audit_flow_debug |
Step-through trace of what hardware_audit does |
test_encoder_output |
Tests openh264 output format |
Features
Camera capture
- Device discovery—automatic enumeration with capability detection
- Format selection—resolution, FPS, and pixel format control
- Professional controls—auto/manual focus, exposure, white balance
- Quality retry—blur and exposure scoring; retries until threshold is met
- Smart Trigger—waits for quality to stabilize before capturing
A/V recording
- H.264 video via openh264
- Opus audio (primary) and AAC (fallback) via CPAL
- PTS-based sync—shared monotonic timebase, ±40ms max drift over a 60-minute recording
- MP4 container via Muxide
Focus stacking and HDR
- Focus stacking—capture focus-bracketed sequences, merge via Laplacian pyramid blending
- HDR sequences—exposure-bracketed burst capture
Reliability
- Invariant Superhighway— 40+ runtime correctness checks across all critical paths
- Feature Registry—every capability declared as
Implemented,Beta,Stub, orPlanned - 196/196 lib tests passing; property-based tests for encoder and sync invariants
- Platform transparency—hardware-unsupported controls log warnings; structural errors return
Err
Command Reference
Initialization
initialize_camera_system
Capture
// Consolidated capture command (preferred)
capture // modes: CaptureMode::Single | Sequence { count, interval_ms } | QualityRetry { max_attempts, min_quality_score }
// Granular commands (available for backward compatibility)
capture_single_photo
Camera controls
// Consolidated settings command (preferred)
apply_camera_settings // fields: focus_distance, exposure_time, iso_sensitivity, white_balance, controls
// Granular commands (available for backward compatibility)
get_camera_controls
Recording (recording feature)
start_recording
Quality analysis
analyze_frame_blur
Advanced / focus stacking
// Consolidated (preferred)
capture_focus_stack // Granular (available for backward compatibility)
capture_focus_brackets_command
Permissions
request_camera_permission
Platform support
| Platform | Camera capture | Controls | Audio | Recording |
|---|---|---|---|---|
| Windows | DirectShow / MediaFoundation | IAMCameraControl / IAMVideoProcAmp | WASAPI | ✅ |
| macOS | AVFoundation | AVFoundation | AVFoundation | ✅ |
| Linux | V4L2 | V4L2 | ALSA | ✅ |
Architecture
crabcamera/
├── src/commands/ Tauri command handlers (capture, recording, advanced, init)
├── src/platform/ Platform-specific camera backends (Windows, macOS, Linux)
├── src/quality/ Blur, exposure, and composition scoring; Smart Trigger
├── src/recording/ H.264 + Opus encoding; MP4 mux via Muxide
├── src/audio/ CPAL-based audio capture and encoding
├── src/focus_stack/ Laplacian pyramid blend for focus stacking
├── src/headless/ Non-Tauri HeadlessSession API
├── src/bin/ crabcamera-cli binary
├── src/invariant_ppt.rs Runtime invariant assertion framework
└── src/registry.rs Feature status registry
Cargo features:
recording—enables MP4 recording commands (openh264 + Muxide)audio—enables audio capture and encoding (Opus via CPAL)headless—enables HeadlessSession API for server/CLI usage
Testing
# Core library (196 tests)
# With recording feature (196 tests)
# Integration tests
# Compile check, all features
License
MIT—forever.
If CrabCamera saves you time, sponsoring keeps it moving forward.
Made with Rust 🦀