Skip to content

rstkit/crabcamera

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦€ CrabCamera: The Desktop Camera Plugin for Tauri πŸ“·

     __________________________
    < Hello fellow Rustaceans! >
     --------------------------
            \
             \
                _~^~^~_
            \) /  o o  \ (/
              '_   -   _'
              / '-----' \

Crates.io License: MIT Rust Sponsor

πŸ¦€ CrabCamera will be free forever. πŸ¦€ No asterisks. No "free for now." No pivot to paid.

πŸ¦€ What is CrabCamera?

πŸ¦€ CrabCamera is the first production-ready desktop camera plugin for Tauri applications. It provides unified camera access across Windows, macOS, and Linux with professional controls and zero-config setup. It's designed to be the invisible infrastructure that makes desktop camera apps just work.

Feature CrabCamera Web APIs Other Plugins
Desktop Native Windows/macOS/Linux πŸ† Limited browser Mobile-only
Hardware Access Direct camera control πŸ† Browser restricted Basic access
Professional Controls Auto-focus, exposure πŸ† Limited Basic
Cross-Platform Unified API πŸ† Platform dependent Single platform
Production Ready 278 comprehensive tests πŸ† No guarantees Proof-of-concept
Memory Safety Zero unsafe code πŸ† N/A Manual management

🎯 Perfect for Desktop Applications πŸ¦€

  • Photography: Photo booth apps, image editors, content creation tools
  • Security: Surveillance systems, access control, monitoring dashboards
  • Medical: Imaging interfaces, patient documentation, diagnostic tools
  • Industrial: Quality control, inspection systems, documentation cameras
  • Education: Interactive learning tools, virtual labs, presentation software
  • Communication: Video chat apps, streaming tools, conference software

BONUS: Professional camera controls with platform-optimized settings for maximum image quality.

πŸ¦€ Quick Start (30 seconds) πŸ“·

Installation

[dependencies]
crabcamera = "0.5.0"
tauri = { version = "2.0", features = ["protocol-asset"] }

Tauri Integration

// src-tauri/src/main.rs
use crabcamera;

fn main() {
    tauri::Builder::default()
        .plugin(crabcamera::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
// tauri.conf.json
{
  "plugins": {
    "crabcamera": {}
  }
}

Frontend Usage

import { invoke } from '@tauri-apps/api/tauri';

// Initialize camera system
await invoke('initialize_camera_system');

// Get available cameras
const cameras = await invoke('get_available_cameras');
console.log('Available cameras:', cameras);

// Get recommended format for high quality
const format = await invoke('get_recommended_format');

// Capture a photo
const photo = await invoke('capture_single_photo', {
  deviceId: cameras[0].id,
  format: format
});

πŸ“¦ Professional Camera Features πŸ¦€

πŸ”§ Hardware Control πŸ¦€

  • Device Enumeration: Automatic discovery of all connected cameras
  • Format Negotiation: Resolution, FPS, and color format selection
  • Professional Settings: Auto-focus, auto-exposure, white balance
  • Multi-camera Support: Switch between multiple cameras seamlessly
  • Error Recovery: Robust handling of device disconnection and errors

πŸ–₯️ Cross-Platform Native πŸ¦€

  • Windows: DirectShow/MediaFoundation with advanced camera controls
  • macOS: AVFoundation with Metal acceleration support
  • Linux: V4L2 with comprehensive device support
  • Unified API: Same code works across all platforms
  • Professional Controls: Focus, exposure, white balance on all platforms

⚑ Performance & Memory πŸ¦€

  • Zero-Copy Operations: Minimal memory allocations where possible
  • Async/Await: Non-blocking operations throughout
  • Resource Management: Automatic cleanup and device release
  • Memory Safety: Built with Rust's memory safety guarantees
  • Thread Safety: Concurrent access with proper synchronization

πŸ”§ Available Commands πŸ¦€

Initialization & Discovery

// Initialize the camera system
initialize_camera_system() -> Result<String>

// Get all available cameras with capabilities
get_available_cameras() -> Result<Vec<CameraDeviceInfo>>

// Get platform-specific information
get_platform_info() -> Result<PlatformInfo>

// Test camera system functionality
test_camera_system() -> Result<SystemTestResult>

Camera Operations

// Check if specific camera is available
check_camera_availability(device_id: String) -> Result<bool>

// Get supported formats for a camera
get_camera_formats(device_id: String) -> Result<Vec<CameraFormat>>

// Get recommended settings for quality photography
get_recommended_format() -> Result<CameraFormat>
get_optimal_settings() -> Result<CameraInitParams>

Capture & Streaming

// Single photo capture
capture_single_photo(device_id: String, format: CameraFormat) -> Result<CameraFrame>

// Photo sequence for burst mode
capture_photo_sequence(params: SequenceParams) -> Result<Vec<CameraFrame>>

// Real-time streaming
start_camera_preview(device_id: String) -> Result<()>
stop_camera_preview() -> Result<()>

// Save frames to disk
save_frame_to_disk(frame: CameraFrame, path: String) -> Result<()>

Professional Camera Controls

// Apply camera controls (focus, exposure, white balance, etc.)
apply_camera_controls(device_id: String, controls: CameraControls) -> Result<()>

// Get current camera control values
get_camera_controls(device_id: String) -> Result<CameraControls>

// Test what controls are supported by camera
test_camera_capabilities(device_id: String) -> Result<CameraCapabilities>

// Get performance metrics
get_camera_performance(device_id: String) -> Result<CameraPerformanceMetrics>

Permissions & Security

// Handle camera permissions properly
request_camera_permission() -> Result<bool>
check_camera_permission_status() -> Result<PermissionStatus>

πŸ¦€ Why CrabCamera Will Always Be Free πŸ“·

I built CrabCamera because desktop applications deserve native camera access without the limitations of web APIs or mobile-only plugins.

This is my commitment: CrabCamera stays MIT licensed, forever. If you want to support development, sponsor it. If you don't, just build something incredible with it.

πŸ¦€ CrabCamera saves developers weeks of cross-platform camera integration. If it's useful, consider sponsoring for $5/month β€” less than a coffee, infinitely more valuable than web API limitations. πŸ¦€

πŸ“Š Performance Comparison πŸ¦€

Metric CrabCamera Web APIs Mobile Plugins
Desktop Support Full native Browser dependent None
Camera Access Direct hardware getUserMedia limited N/A
Image Quality Professional controls Basic settings Basic
Cross-Platform Windows/macOS/Linux Browser variation iOS/Android only
Performance Native speed Browser overhead N/A
Reliability 278 tests passing No guarantees Varies

πŸ—οΈ Technical Architecture πŸ¦€

Hybrid Capture + Controls Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   nokhwa        β”‚    β”‚ Platform Controlsβ”‚    β”‚  CrabCamera     β”‚
β”‚   (Capture)     β”‚    β”‚ (Advanced)       β”‚    β”‚  (Unified API)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Frame capture β”‚    β”‚ β€’ Focus control  β”‚    β”‚ β€’ Generic types β”‚
β”‚ β€’ Resolution    β”‚    β”‚ β€’ Exposure       β”‚    β”‚ β€’ Error handlingβ”‚
β”‚ β€’ Format        β”‚    β”‚ β€’ White balance  β”‚    β”‚ β€’ Cross-platformβ”‚
β”‚ β€’ Start/Stop    β”‚    β”‚ β€’ Brightness     β”‚    β”‚ β€’ Thread safety β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Platform-Specific Implementations

  • Windows: nokhwa capture + MediaFoundation controls
  • macOS: AVFoundation for both capture and controls
  • Linux: nokhwa capture + V4L2 controls
  • Unified API: Same control interface across all platforms

Key Technologies

  • Rust + Tokio: Memory-safe, async performance
  • Tauri 2.0 Plugin: Modern plugin architecture
  • Platform Backends: MediaFoundation, AVFoundation, V4L2
  • COM Interface Management: Thread-safe Windows controls
  • Zero unsafe code: Memory safety guaranteed (except platform COM interfaces)

πŸ“š API Reference πŸ¦€

Core Types

pub struct CameraDeviceInfo {
    pub id: String,
    pub name: String,
    pub description: String,
    pub is_available: bool,
    pub supports_formats: Vec<CameraFormat>,
}

pub struct CameraFormat {
    pub width: u32,
    pub height: u32,
    pub fps: f32,
    pub format_type: String, // "RGB8", "JPEG", etc.
}

pub struct CameraFrame {
    pub data: Vec<u8>,
    pub width: u32,
    pub height: u32,
    pub format: String,
    pub timestamp: DateTime<Utc>,
}

pub struct CameraControls {
    pub auto_focus: Option<bool>,
    pub focus_distance: Option<f32>,     // 0.0 = infinity, 1.0 = closest
    pub auto_exposure: Option<bool>,
    pub exposure_time: Option<f32>,      // seconds
    pub white_balance: Option<WhiteBalance>,
    pub brightness: Option<f32>,         // -1.0 to 1.0
    pub contrast: Option<f32>,           // -1.0 to 1.0
    pub saturation: Option<f32>,         // -1.0 to 1.0
}

pub struct CameraCapabilities {
    pub supports_auto_focus: bool,
    pub supports_manual_focus: bool,
    pub supports_auto_exposure: bool,
    pub supports_manual_exposure: bool,
    pub supports_white_balance: bool,
    pub focus_range: Option<(f32, f32)>,
    pub exposure_range: Option<(f32, f32)>,
}

Platform Detection

pub enum Platform {
    Windows,
    MacOS,
    Linux,
    Unknown,
}

// Automatic platform detection
let platform = Platform::current();

πŸ¦€ Community & Support πŸ“·

Governance

CrabCamera is open source, not open contribution. The code is freely available under the MIT license, but pull requests are not accepted by default. See CONTRIBUTING.md for details.

This model ensures consistent quality across all platforms and clear project direction.

Sponsors

See our amazing sponsors who make πŸ¦€ CrabCamera possible! πŸ™

Sponsorship Tiers:

  • $5/month: Coffee tier - My eternal gratitude + sponsor badge
  • $25/month: Developer supporter - Priority support + name in SPONSORS.md
  • $100/month: Corporate backer - Logo on README + monthly office hours
  • $500/month: Enterprise partner - Direct support + feature requests

Companies: Need invoicing? Email michaelallenkuykendall@gmail.com

πŸš€ Production Usage πŸ¦€

βœ… Ready for production:

  • Memory-safe Rust implementation
  • 278 comprehensive tests passing
  • Zero unsafe code
  • Comprehensive error handling
  • Async/await throughout
  • Cross-platform compatibility verified
  • Real hardware validation (OBSBOT Tiny 4K)

βœ… Use cases in production:

  • Desktop photography applications
  • Security and surveillance systems
  • Medical imaging interfaces
  • Industrial inspection tools
  • Educational software platforms
  • Communication and streaming apps

πŸ’‘ Examples & Integration πŸ¦€

Photo Booth Application

// Simple photo booth with camera selection
const cameras = await invoke('get_available_cameras');
const selectedCamera = cameras[0];
const format = await invoke('get_recommended_format');

// Take photo when user clicks
document.getElementById('capture').onclick = async () => {
    const photo = await invoke('capture_single_photo', {
        deviceId: selectedCamera.id,
        format: format
    });
    // Display photo in UI
    displayPhoto(photo);
};

Multi-Camera Security System

// Monitor multiple cameras
const cameras = await invoke('get_available_cameras');
for (const camera of cameras) {
    await invoke('start_camera_preview', { deviceId: camera.id });
    // Set up streaming handlers for each camera
    setupCameraStream(camera);
}

πŸ“œ License & Philosophy πŸ¦€

MIT License - forever and always.

Philosophy: Desktop applications deserve native camera access. πŸ¦€ CrabCamera is camera infrastructure. πŸ“·

πŸš€ What's New in v0.5.0

🎬 v0.5.0: Audio Recording & A/V Sync (December 2025)

  • Audio Recording: Full audio capture with Opus encoding
  • A/V Sync: Shared PTS clock ensures Β±40ms audio/video synchronization
  • Audio Device Enumeration: list_audio_devices() with sample rate, channels, default status
  • Integrated Recording: start_recording() now accepts audioDeviceId parameter
  • Fuzz Testing: 8 proptest-based fuzz tests for encoder robustness
  • Benchmark Suite: Criterion benchmarks for H264 and Opus encoding
  • 278 Tests: Up from 157, with live OBSBOT Tiny 4K validation
  • Critical Fix: PTS double-counting bug in audio encoder

πŸŽ‰ v0.4.1: Bug Fixes, Performance & DX

  • Critical Fix: Mock camera was incorrectly used during cargo run
  • PNG Save Fixed: save_frame_to_disk() now properly encodes PNG/JPEG
  • Performance: Camera warmup reduced from 10 frames to 5 frames
  • macOS Fixed: Objective-C block syntax and nokhwa API compatibility

πŸŽ‰ v0.4.0: Quality Intelligence & Configuration

  • Quality Validation: Automatic blur/exposure detection with retry
  • TOML Configuration: Full runtime config with hot-reload
  • Focus Stacking: Computational photography for macro shots
  • Device Monitoring: Hot-plug detection for camera connect/disconnect

πŸŽ‰ v0.3.0: Windows MediaFoundation Camera Controls

  • Professional Windows Controls: Full focus, exposure, white balance control
  • Hybrid Architecture: nokhwa capture + MediaFoundation controls
  • Thread-Safe COM: Proper Windows COM interface management

Forever maintainer: Michael A. Kuykendall
Promise: This will never become a paid product
Mission: Making desktop camera development effortless

"πŸ¦€ Native performance. Cross-platform compatibility. Zero hassle. πŸ“·"

       πŸ¦€πŸ¦€πŸ¦€ Happy Coding! πŸ¦€πŸ¦€πŸ¦€
          Made with ❀️ and Rust
           πŸ“· Capture the moment πŸ“·

About

Professional desktop camera plugin for Tauri with WebRTC live preview, automated quality validation, and advanced hardware controls. Zero-config cross-platform solution for photography apps, surveillance systems, and automated capture workflows.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • HTML 55.6%
  • Rust 43.8%
  • Other 0.6%