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.1.tar.gz (14.2 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.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vitesse_video_feed-0.1.1.tar.gz
  • Upload date:
  • Size: 14.2 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.1.tar.gz
Algorithm Hash digest
SHA256 b241e765451a80de8ee8d7c7d6691a143549ad7d12a4b18e316a7fcad3aac30e
MD5 6d9a3280aa66ebf3a225342a3153d800
BLAKE2b-256 806c958756f7a79e1f1556ddbc580ae3d72d0253008dffad9d573f6606b0db27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for vitesse_video_feed-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a906d0c544da4c38a6e9056b7971466e896a1f991510e10b974e8b916abd11da
MD5 aad54257aef2eeb11505c17de79509ed
BLAKE2b-256 9f7fc04b809b7e4fd220d3b6abb50d564a2aaac8ae4e78a9f38c3bb81b4e1a18

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