A zero-dependency, ultra-low-latency threaded camera multiplexer for Python.
Project description
ThreadCam
A zero-lag, ultra-low-latency threaded camera multiplexer for Python.
Are you building a Flask app that streams video? Are you running a Machine Learning inference loop that drops frames or causes your UI to stutter?
ThreadCam completely eliminates OpenCV's VideoCapture IO bottleneck.
The Problem
When you call cap.read() in OpenCV, your Python script completely blocks while waiting for the USB hardware to compress and deliver the frame buffer. If you try to run multiple generators (like streaming to a Web UI and running an ML model), they fight for the camera lock, causing massive lag and crashes.
The Solution
ThreadCam opens your webcam exactly once in a dedicated, ultra-light background C-thread. It constantly maintains the absolute latest frame in RAM behind a thread-safe lock.
You can have infinite Python consumers reading .read() simultaneously. Because they are pulling from RAM instead of the hardware buffer, it executes in exactly 0.0000ms, completely unblocking your application loop.
Installation
pip install ThreadCam
Usage
from ThreadCam import ThreadCam
import cv2
# Initialize the hub (Starts the background thread)
hub = ThreadCam(src=0, target_fps=30)
while True:
# Read the absolute newest frame instantly from RAM
ret, frame = hub.read()
if not ret:
continue
cv2.imshow("ThreadCam", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
hub.stop()
Ideal Use Cases
- Flask / FastAPI MJPEG Streaming
- MediaPipe / YOLO Inference Engines
- PyGame / Tkinter UI Overlays
- Multi-threaded processing pipelines
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file threadcam-0.1.0.tar.gz.
File metadata
- Download URL: threadcam-0.1.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ac89a9c8be9dc0c5a16b86f972019862e06d8b10d7b9dd665aa9a2cc78dbe7d
|
|
| MD5 |
54ef3dca3abdad89451f6d609ec50872
|
|
| BLAKE2b-256 |
9d805368dec6a9345d55dd35e67ba5646c6d2c1b999c86a30748a52f6e5437f5
|
File details
Details for the file threadcam-0.1.0-py3-none-any.whl.
File metadata
- Download URL: threadcam-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa8c7145b4f507034acc71630ccf7203393f63cb4fc906adf8a2d4245f89a97
|
|
| MD5 |
b7672c77b974b15382ce8950f2120ba1
|
|
| BLAKE2b-256 |
e373a4f48b0933ecd844b61bd3c1c13f562e26d601b1cdd8c012dcfa2215b889
|