Skip to main content

Stream video feeds to a Vitesse Gateway with WebRTC

Project description

Vitesse Video Feed

Stream video feeds to a Vitesse Gateway with WebRTC. Handles connection management, codec negotiation, and transport lifecycle automatically.

Installation

pip install vitesse-video-feed

Dependencies: aiortc, aiohttp, pymediasoup, numpy

Quick Start

import asyncio
from vitesse_video_feed import VideoFeedClient, VideoFeedConfig, CameraInfo

# 1. Implement your camera source
class MyCameraSource:
    def get_frame(self):
        # Return RGB numpy array (height, width, 3)
        return my_frame

    def is_active(self):
        return True

    @property
    def info(self):
        return CameraInfo(name="My Camera", resolution=(640, 480), framerate=15)

# 2. Connect and stream
async def main():
    config = VideoFeedConfig(gateway_url="192.168.1.100", use_https=True)
    client = VideoFeedClient(client_id="my-app", config=config)

    await client.connect()
    await client.add_camera("cam-1", MyCameraSource())

    # Stream until interrupted (cleanup is automatic)
    await asyncio.sleep(3600)

asyncio.run(main())

CameraSource Protocol

Your camera source must implement three things:

class CameraSource(Protocol):
    def get_frame(self) -> Optional[np.ndarray]:
        """Return RGB numpy array of shape (height, width, 3), or None."""
        ...

    def is_active(self) -> bool:
        """Return True if actively producing frames."""
        ...

    @property
    def info(self) -> CameraInfo:
        """Return camera metadata."""
        ...

CameraInfo

CameraInfo(
    name="Front Camera",           # Display name
    resolution=(1920, 1080),       # Width x Height
    framerate=30,                  # Target FPS
    description="Entrance cam",    # Optional description
    tags=["outdoor", "hd"],        # Optional tags
    location="Building A"          # Optional location
)

Configuration

VideoFeedConfig(
    gateway_url="192.168.1.100",   # Host/IP (or full URL)
    use_https=True,                # True = https://:7901, False = http://:7900
    priority_gateway_url=None,     # Optional internal URL to try first
    retry_attempts=3,              # Retries per URL
    retry_interval_s=2.0,          # Delay between retries
    reconnect_interval_s=10.0,     # Delay before full reconnection cycle
    max_reconnect_cycles=0,        # 0 = infinite reconnection
)

Event Callbacks

from vitesse_video_feed import FeedClientCallbacks

class MyCallbacks(FeedClientCallbacks):
    def on_connected(self):
        print("Connected!")

    def on_disconnected(self, reason: str):
        print(f"Disconnected: {reason}")

    def on_camera_added(self, camera_id: str):
        print(f"Camera {camera_id} streaming")

    def on_camera_removed(self, camera_id: str):
        print(f"Camera {camera_id} removed")

client = VideoFeedClient(client_id="app", config=config, callbacks=MyCallbacks())

Adapter for Existing Cameras

If you have an existing camera that doesn't match the protocol:

from vitesse_video_feed import CameraSourceAdapter, CameraInfo

source = CameraSourceAdapter(
    get_frame_fn=my_camera.read,
    is_active_fn=my_camera.is_open,
    camera_info=CameraInfo(name="Existing Cam", resolution=(640, 480))
)

await client.add_camera("cam-1", source)

Thread-Safe Scheduling

For use from synchronous code:

client.set_event_loop(loop)
client.schedule_add_camera("cam-1", source, callback=lambda ok: print(ok))
client.schedule_remove_camera("cam-1")

Automatic Cleanup

The client registers handlers for SIGINT, SIGTERM, and atexit. Resources are freed automatically even if disconnect() is not called.

License

MIT

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

vitesse_video_feed-0.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

vitesse_video_feed-0.1.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vitesse_video_feed-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45e5ed78d15ad3f021996499d43c49b8f229e418f4a3bff917e8024c6a8f6a1d
MD5 0d97b51fe243745a2e2b0c1e00ef3a8e
BLAKE2b-256 ebbcb96f54bb422ee40a1e5a6f5265e1b7675966b985361953034d103a76ac39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for vitesse_video_feed-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 837b2c9a9e35a02cd521697f738ceffe080613ddc4be46514fbf8aaea730d1f9
MD5 389ef3eef231d14dc81a5fe17a05589f
BLAKE2b-256 8c5dc5d51a29bb443a00e5491dd6b4d32e56025be45db9deb0f29432044ad80f

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