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.

__init__(frame_data)[source]

Initialize a Frame with numpy array data.

save(path)[source]

Save the frame to a file.

to_numpy()[source]

Return the frame as a numpy array.

to_pil()[source]

Convert to PIL Image.

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:

Union[Frame, Path]

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:
  • region (Tuple[int, int, int, int]) – Tuple of (left, top, right, bottom) coordinates

  • output_path (Union[str, Path, None]) – Optional path to save the screenshot. If None, returns a Frame object.

Return type:

Union[Frame, Path]

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")
fmusvid.capture.screen.select_region()[source]

Interactive tool to select a region of the screen.

Return type:

Tuple[int, int, int, int]

Returns:

Tuple of (left, top, right, bottom) coordinates

Example

>>> # Select a region interactively
>>> region = fmusvid.capture.select_region()
>>> # Capture the selected region
>>> frame = fmusvid.capture.capture_region(region)

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 rate

  • backend (Optional[int]) – OpenCV backend ID (None uses default)

  • buffer_size (int) – Size of the frame buffer for async capture

  • auto_start (bool) – Whether to start capturing immediately

start()[source]

Start the camera capture.

Return type:

bool

Returns:

True if successfully started, False otherwise

stop()[source]

Stop the camera capture.

Return type:

None

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:

bool

Returns:

True if async capture started successfully, False otherwise

stop_async_capture()[source]

Stop asynchronous frame capture.

Return type:

None

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

capture_image(path)[source]

Capture a single image and save it to disk.

Parameters:

path (Union[str, Path]) – Output path for the captured image

Return type:

bool

Returns:

True if image was successfully captured and saved, False otherwise

record_video(path, duration=None, codec='mp4v', fps=None)[source]

Record video from camera and save to disk.

Parameters:
  • path (Union[str, Path]) – Output path for the video file

  • duration (Optional[float]) – Recording duration in seconds (None for indefinite)

  • codec (str) – FourCC codec code (default is mp4v)

  • fps (Optional[float]) – Frame rate (None uses camera’s frame rate)

Return type:

bool

Returns:

True if video was successfully recorded, False otherwise

__enter__()[source]

Context manager entry.

__exit__(exc_type, exc_val, exc_tb)[source]

Context manager exit.

__del__()[source]

Destructor to ensure resources are released.

fmusvid.capture.camera.list_cameras(max_cameras=10)[source]

List available camera devices.

Parameters:

max_cameras (int) – Maximum number of cameras to check

Return type:

List[Dict[str, Any]]

Returns:

List of camera info dictionaries with ‘id’, ‘working’, and ‘name’ keys

fmusvid.capture.camera.get_camera_backends()[source]

Get available OpenCV camera backends.

Return type:

Dict[int, str]

Returns:

Dictionary mapping backend IDs to names

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.

__init__(path)[source]

Initialize with a path to the video file.

property path

Return the path to the video file.

__str__()[source]

Return string representation.

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:
  • output (Union[str, Path]) – Path to save the video file

  • duration (Optional[float]) – Duration in seconds (None for manual stop)

  • fps (float) – Frames per second

  • quality (int) – Video quality (0-100)

  • show_cursor (bool) – Whether to show mouse cursor

  • audio (bool) – Whether to record audio (requires pyaudio)

  • progress_callback (Optional[Callable[[float], None]]) – Function to call with progress (0-1)

Return type:

Video

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:
  • output (Union[str, Path]) – Path to save the video file

  • 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 second

  • quality (int) – Video quality (0-100)

  • show_cursor (bool) – Whether to show mouse cursor

  • audio (bool) – Whether to record audio (requires pyaudio)

  • progress_callback (Optional[Callable[[float], None]]) – Function to call with progress (0-1)

Return type:

Video

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")