Skip to main content

Cross platform multi-webcam video capture utility.

Project description

vidcontrol

PyPI version PyPI - Python Version PyPI - License

⚠️ This package is still under development and is not yet ready for production use. ⚠️

vidcontrol is a Python package for managing multi-webcam video capture. It is designed to be cross-platform and easy to use. Under the hood, we use imageio for video capture, which itself uses ffmpeg. This package offers various utility functions for listing and selecting available webcams, and for capturing video from multiple webcams simultaneously. We also provide an easy-to-use interface for resolving image resolutions and frame rates.

This package has been developed in conjunction with ctrlability together with the Prototype Fund.

Platform Status
MacOS Full support Tested and verified on macOS 12.0+
Linux Not yet, but planned
Windows Full support Tested and verified on Windows 11

Getting Started

Prerequisites

This package requires Python 3.8 or higher. We recommend using a virtual environment for development. You can create a virtual environment using venv or conda.

Additionally, you will need to install ffmpeg on your system. On macOS, you can install ffmpeg using Homebrew:

brew install ffmpeg

Installation

You can install the latest version of the package directly from this repository:

pip install git+https://github.com/inmotion-health/vidcontrol.git

Or install from source:

git clone https://github.com/inmotion-health/vidcontrol.git
cd vidcontrol
pip install .

Basic Usage

Generally, this package is constructed around two main classes: VideoManager and VideoSource. The VideoManager is used to manage all available webcams and to create new VideoSource instances. The VideoSource is used to capture video from a single webcam. The following example shows how to use these classes to capture video from a single webcam:

from vidcontrol import VideoManager

manager = VideoManager()

# List available webcams
manager.list_available_cameras()

# Set the height of the video capture
manager.set_preferred_height(480)

# Get a video source and start capturing
source = manager.get_video_source(0)
for frame in source:
    # Do something with the frame
    pass

To capture video from a webcam, you first need to request a VideoSource from the VideoManager. You can do this by calling get_video_source and passing the index of the webcam you want to use. The index is the same as the index returned by list_available_cameras. You can also pass a preferred_height and preferred_fps to get_video_source to set the height and frame rate of the video capture. If you do not pass these parameters, the VideoManager will use the default values.

The VideoManager will then try to find a webcam that supports the requested height and frame rate. If it cannot find a webcam that supports the requested height and frame rate, it will use the next best resolution and frame rate. By default, this fallback is disabled, but you can enable it by setting next_best to True when configuring the VideoManager.

If the VideoSource for a webcam is requested multiple times, the VideoManager will return the same VideoSource instance. This means that you can use the same VideoSource instance in multiple places in your code. This is useful if you want to capture video from a single webcam multiple times.

For more detailed examples, please see the examples folder.

Configuration

vidcontrol supports various options for configuring the video capture. You can set these options either when creating a new VideoManager or when creating a new VideoSource. The following table lists all available options:

Parameter Description Default Value
VideoManager
preferred_height The preferred height of the video capture. 480
preferred_fps The preferred frame rate of the video capture. 30
next_best Whether to use the next best resolution if the preferred resolution fails. False
VideoSource
color_format The color format of the video capture. rgb
Other options: bgr
mirror_frame Whether to mirror the frame vertically. True
flip_frame_horizontal Whether to flip the frame horizontally. False

These options are either passed as a dictionary to the VideoManager or VideoSource set_config, or via their respective functions in the form of set_<option>. See the basic usage or pass config example to see how to use some of these options.

Contributing and Issues

We welcome contributions and feedback. Please use GitHub issues to report bugs, discuss features, or ask questions. If you would like to contribute to the project, feel free to open a pull request. Please make sure to follow the PEP8 style guide.

Things we especially would appreciate help with:

  • Testing on different platforms and versions
  • Testing with different webcams

When contributing, please make sure to use conventional commits for your commit messages. This makes it easier to automatically generate a changelog. You can find more information about conventional commits here.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vidcontrol-0.1.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

vidcontrol-0.1.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file vidcontrol-0.1.2.tar.gz.

File metadata

  • Download URL: vidcontrol-0.1.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for vidcontrol-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a4bd73ddce9e954bdf3525dd350ae8274faa8e5bd146528fecf06f2ffd0b46ef
MD5 032a0062933533e112d80f473833ccb9
BLAKE2b-256 e6dad44cb68847e1d9d12480d483d7e579253fb1a8382ac7b0c06d0f664ad576

See more details on using hashes here.

File details

Details for the file vidcontrol-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: vidcontrol-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for vidcontrol-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 52fcb2318a033cc2982cab97ea266da37cd874e75ce07d9fd18358238c6ef20c
MD5 359218f379f1b1293d6a630cac0ba144
BLAKE2b-256 03d43283cb4667f02e01540c66895157589bd15a54a4ef37f3eb76a35f42b4a5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page