Capture Module
This module contains screen and camera capture functionality.
Screen Capture
Screen capture functionality for FMUS-VID.
This module provides tools for capturing screenshots of the screen or specific regions.
- class fmusvid.capture.screen.Frame(frame_data)[source]
Simplified Frame class for captured screenshots.
- fmusvid.capture.screen.capture_screen(output_path=None)[source]
Capture a screenshot of the entire screen.
- Parameters:
output_path (
Union[str,Path,None]) – Optional path to save the screenshot. If None, returns a Frame object.- Return type:
- Returns:
Frame object if output_path is None, otherwise the Path to the saved image.
Example
>>> # Capture and get Frame object >>> frame = fmusvid.capture.capture_screen() >>> # Capture and save to file >>> path = fmusvid.capture.capture_screen("screenshot.png")
- fmusvid.capture.screen.capture_region(region, output_path=None)[source]
Capture a screenshot of a specific region of the screen.
- Parameters:
- Return type:
- Returns:
Frame object if output_path is None, otherwise the Path to the saved image.
Example
>>> # Capture region (100, 100, 500, 400) and get Frame object >>> frame = fmusvid.capture.capture_region((100, 100, 500, 400)) >>> # Capture region and save to file >>> path = fmusvid.capture.capture_region((100, 100, 500, 400), "region.png")
Camera Capture
Camera Capture Module
This module provides functionality for capturing video and images from webcams and other camera devices using OpenCV.
- class fmusvid.capture.camera.CameraCapture(camera_id=0, width=None, height=None, fps=30.0, backend=None, buffer_size=10, auto_start=False)[source]
Class for capturing video and images from webcams and camera devices.
This class provides an easy-to-use interface for webcam capture with features like device selection, resolution control, and both synchronous and asynchronous capture modes.
- __init__(camera_id=0, width=None, height=None, fps=30.0, backend=None, buffer_size=10, auto_start=False)[source]
Initialize the camera capture.
- Parameters:
camera_id (
int) – Camera device ID (typically 0 for built-in webcam)width (
Optional[int]) – Requested camera width (None uses default)height (
Optional[int]) – Requested camera height (None uses default)fps (
float) – Requested camera frame ratebackend (
Optional[int]) – OpenCV backend ID (None uses default)buffer_size (
int) – Size of the frame buffer for async captureauto_start (
bool) – Whether to start capturing immediately
- start()[source]
Start the camera capture.
- Return type:
- Returns:
True if successfully started, False otherwise
- get_frame()[source]
Capture a single frame from the camera.
- Return type:
Optional[ndarray]- Returns:
Frame as numpy array, or None if capture failed
- start_async_capture()[source]
Start asynchronous frame capture in a background thread.
- Return type:
- Returns:
True if async capture started successfully, False otherwise
- get_latest_frame()[source]
Get the latest frame from the async capture queue.
- Return type:
Optional[ndarray]- Returns:
Latest frame as numpy array, or None if no frames available
Recorder
Screen recording functionality for FMUS-VID.
This module provides tools for recording screen activity to video files.
- class fmusvid.capture.recorder.Video(path)[source]
Minimal Video class for screen recordings.
- property path
Return the path to the video file.
- fmusvid.capture.recorder.record_screen(output, duration=None, fps=30.0, quality=95, show_cursor=True, audio=False, progress_callback=None)[source]
Record full screen activity to a video file.
- Parameters:
duration (
Optional[float]) – Duration in seconds (None for manual stop)fps (
float) – Frames per secondquality (
int) – Video quality (0-100)show_cursor (
bool) – Whether to show mouse cursoraudio (
bool) – Whether to record audio (requires pyaudio)progress_callback (
Optional[Callable[[float],None]]) – Function to call with progress (0-1)
- Return type:
- Returns:
Video object for the recorded video
Example
>>> # Record for 10 seconds >>> video = fmusvid.capture.record_screen("recording.mp4", duration=10) >>> # Manual recording (press 'q' to stop) >>> video = fmusvid.capture.record_screen("recording.mp4")
- fmusvid.capture.recorder.record_region(output, region=None, duration=None, fps=30.0, quality=95, show_cursor=True, audio=False, progress_callback=None)[source]
Record a specific region of the screen to a video file.
- Parameters:
region (
Optional[Tuple[int,int,int,int]]) – Tuple of (left, top, right, bottom) coordinates (None to select interactively)duration (
Optional[float]) – Duration in seconds (None for manual stop)fps (
float) – Frames per secondquality (
int) – Video quality (0-100)show_cursor (
bool) – Whether to show mouse cursoraudio (
bool) – Whether to record audio (requires pyaudio)progress_callback (
Optional[Callable[[float],None]]) – Function to call with progress (0-1)
- Return type:
- Returns:
Video object for the recorded video
Example
>>> # Record specific region for 10 seconds >>> video = fmusvid.capture.record_region("region.mp4", (100, 100, 500, 400), duration=10) >>> # Interactively select region >>> video = fmusvid.capture.record_region("region.mp4")