Skip to main content

Minimal, stateless toolkit to capture USB webcams and stream them over RTSP/WebRTC via MediaMTX.

Project description

pyezcams

v0.1.0 · PyPI

Minimal (stdlib-only) toolkit to run a node that captures USB webcams and streams them over RTSP/WebRTC via MediaMTX. A single command (pyezcams) starts MediaMTX and one ffmpeg per camera and keeps them alive.

No Python dependencies. Relies on three system binaries: ffmpeg, v4l2-ctl and mediamtx. Linux only (v4l2 capture).

Stateless: the library stores nothing and assumes no paths. All configuration is the match file, passed explicitly and required.

Prerequisites

Binary Install
ffmpeg sudo apt install ffmpeg
v4l2-ctl sudo apt install v4l-utils
mediamtx binary from releases onto the PATH

check_prerequisites() verifies them at startup and, if any is missing, says what to do.

Install

pip install pyezcams

Usage

pyezcams --config cameras.txt                       # defaults: 720p30
pyezcams --config cameras.txt --resolution 1920x1080 --fps 25

--config is required (no default path). The command checks prerequisites, detects the encoder, starts MediaMTX and launches one ffmpeg per camera, supervising them (relaunches any that die, clean shutdown on SIGINT/SIGTERM).

Defaults

Fixed 720p30 surveillance standard; everything works with no flags. Only --config is required; --resolution and --fps are optional overrides.

Parameter Default Applies to
resolution 1280x720 capture (both cases)
framerate 30 capture (both cases)
bitrate 4M re-encode (MJPG) only
GOP 60 (2s @30fps) re-encode (MJPG) only
RTSP output rtsp://localhost:8554/<alias> both cases

Per case:

  • H264 (copy) — captures at resolution/fps and copies the native stream (-c:v copy, ~0 CPU). Bitrate does not apply (nothing is re-encoded).
  • MJPG (re-encode) — captures at resolution/fps and re-encodes with the detected encoder at the given bitrate.

Bitrate and RTSP base are module constants in command.py; build_command also takes video_size, framerate and bitrate keyword args for per-camera overrides.

Match file

One camera per line, path = alias (blank lines and # comments ignored):

/dev/v4l/by-path/...-video-index0 = laser20w
/dev/v4l/by-path/...-video-index0 = cnc_a

Get the paths with ls -l /dev/v4l/by-path/.

API

from pyezcams import (
    parse_match, check_prerequisites, detect_encoder,
    detect_format, build_command, run,
)
  • parse_match(path) -> dict — read the match file into {alias: usb_path}.
  • check_prerequisites() -> None — verify the three binaries; RuntimeError if any is missing.
  • detect_encoder() -> str | None — first H.264 encoder that passes a real 1-frame test (h264_nvenc > h264_qsv > h264_vaapi > h264_v4l2m2m > libx264).
  • detect_format(usb_path) -> str | None"H264" (copy) or "MJPG" (re-encode), or None.
  • build_command(usb_path, alias, fmt, encoder, video_size=..., framerate=..., bitrate=...) -> list[str] — build (not run) the ffmpeg argv; the last three default to the 720p30/4M standard. ValueError if fmt is None.
  • run(config, video_size=..., framerate=...) -> None — orchestrate the node: prerequisites -> MediaMTX -> one ffmpeg per camera -> supervision -> clean shutdown.

License

MIT — see LICENSE.

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

pyezcams-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyezcams-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file pyezcams-0.1.0.tar.gz.

File metadata

  • Download URL: pyezcams-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pyezcams-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f19239523c1c6802ee51d3173bc754930a1fb8e4c2dd40e686aac4a655a4e301
MD5 6687da7a3e364bd98316ca4b9a2c9f0e
BLAKE2b-256 f9d1d8c5ed0d864e320063811c2df36841d278d4e8b90730ffc58006912b52b7

See more details on using hashes here.

File details

Details for the file pyezcams-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyezcams-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pyezcams-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef3ce65f204da804a505e088b83997bf57d69036f6854c2647651d3755dd1413
MD5 20aa059ce9a7ecf8ec4c7f2f03b1cc66
BLAKE2b-256 b53c74a3c17b6a5b6770e8babae9be3f6fec7141fa6ade4c049d249a7a18ed4b

See more details on using hashes here.

Supported by

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