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.2.tar.gz (14.4 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.2-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vitesse_video_feed-0.1.2.tar.gz
  • Upload date:
  • Size: 14.4 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.2.tar.gz
Algorithm Hash digest
SHA256 b40e628065a4d8ecb73d59457b78eaa44cbf10f1ca7601fef5ac0e5e5af8a3a8
MD5 9c3279241b1e1ff17ca81f3624e58b77
BLAKE2b-256 9dcdc3d420c2e34a0fec9dc6787d1e82aef9f5a1cef1eb86c3f50fd85c70cc3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for vitesse_video_feed-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0350c986841ce48da562585524ba7ecec8a881b5e59f05445b100816783445f5
MD5 ccb43c3fac394d532db7073fe98e54ab
BLAKE2b-256 d11249e5b487e6c2e4dba317e756a45956662e5c2c4f94cea9bc8190ebd13217

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