Open source Loom alternative. Beautiful, shareable screen recordings.
cap-camera-directshow
Ergonomic Rust wrapper around Windows DirectShow API for legacy camera capture, providing safe abstractions over COM interfaces while maintaining compatibility with older camera devices and drivers that don't support Media Foundation. Aims to mirror how Chromium consumes DirectShow.
Purpose
Provides safe access to Windows camera devices through DirectShow's filter graph architecture, handling COM initialization, device enumeration through monikers, format negotiation via IAMStreamConfig, and synchronous frame delivery through custom sink filters.
Key Features
- Device Discovery:
VideoInputDeviceIteratorfor enumerating video capture devices via COM monikers - Format Enumeration: Access to
AM_MEDIA_TYPEformats and frame rates throughIAMStreamConfig - Synchronous Capture: Callback-based frame delivery via custom
SinkFilterimplementation - Memory Safety: RAII COM object management with automatic cleanup and proper reference counting
- Legacy Support: Compatibility with older cameras that lack Media Foundation support
- Video Format Support: Built-in support for I420, RGB24, YUY2, MJPG, NV12, and other common formats
Core APIs
Device Management
initialize_directshow()- Initialize DirectShow COM subsystemVideoInputDeviceIterator::new()- Enumerate available cameras via system device enumeratorVideoInputDevice::name(),VideoInputDevice::id(),VideoInputDevice::model_id()- Device metadataVideoInputDevice::media_types()- Iterator over supportedAMMediaTypeformats
Capture Pipeline
VideoInputDevice::start_capturing(format, callback)- Begin sync capture with specified formatCaptureHandle::stop_capturing()- Stop capture session and disconnect filter graphSinkCallback- Frame processing callback receivingIMediaSampleand media type
Format Processing
AMMediaType- Safe wrapper aroundAM_MEDIA_TYPEwith automatic memory managementAM_MEDIA_TYPEExt::subtype_str()- Convert format GUIDs to readable stringsAM_MEDIA_TYPEVideoExt::video_info()- Access video format details and dimensions
Filter Graph Extensions
IBaseFilterExt::get_pin()- Find pins by direction, category, and media typeIAMStreamConfigExt::media_types()- Enumerate supported capture formatsIPinExt::matches_category()- Pin category matching for capture pin discovery
Architecture
Bridges DirectShow's COM-based filter graph model to Rust's ownership system using custom sink filter implementation, RAII for COM resource management, and comprehensive trait extensions for ergonomic API access. Designed for maximum compatibility with legacy camera hardware while maintaining memory safety.
Error Handling
Comprehensive StartCapturingError enum covering:
- NoInputPin - Sink filter pin creation failures
- CreateGraph - Filter graph builder instantiation errors
- ConfigureGraph - Filter connection and configuration issues
- Run - Media control execution failures
- Other - General DirectShow COM errors
The crate provides robust error propagation while maintaining the callback-based architecture required for real-time video capture scenarios.