# RTSP + AI: Turn Any Camera Stream into Agent-Readable Events

> Turn any RTSP camera stream into AI-readable events: continuous understanding, plain-language alerts, and searchable history. No CV pipeline to build.

Category: Tutorials
Published: 2026-08-09

---

RTSP stream AI analysis means connecting a live camera feed to infrastructure that continuously understands it. You get rolling-window analysis of what's happening, a live index you can search, and events you define in plain language that push alerts the moment they occur. No frame-grabbing loops, no training a classifier per event, no pipeline babysitting.

## The DIY wall

The do-it-yourself version is OpenCV frame grabs + YOLO or a VLM call per frame + your own event logic. Three problems never go away. Frames aren't events, because events live in time windows. Streams misbehave, and keeping a pipeline alive 24/7 is an SRE job. And there's no history unless you also build storage and indexing.

## Connect a stream, define an event, get alerts

```python
import asyncio
import videodb

RTSP_URL = "rtsp://samples.rts.videodb.io:8554/intruder"  # public test stream

async def main():
    conn = videodb.connect()
    coll = conn.get_collection()

    # 1. Ingest the live stream (store=True keeps searchable history)
    rtstream = coll.connect_rtstream(url=RTSP_URL, name="Dock Cam", store=True)

    # 2. Continuous understanding in rolling windows
    understanding = rtstream.understand(
        segmentation={"type": "time", "window": "5s"},
        analyzers=[{
            "type": "vlm",
            "name": "scene",
            "sampling": {"frame_count": 2},
            "config": {"prompt": "Describe the people, vehicles, movement, and activity."}
        }],
        store=True
    )

    # 3. A live index - queryable while the stream runs
    index = rtstream.index(name="dock-scenes",
                           source=understanding.outputs["scene"],
                           use_for=["semantic"])

    # 4. Define the event in plain language
    event_id = conn.create_event(
        event_prompt="Detect when a person appears in the monitored area.",
        label="person_appears"
    )

    # 5. Get pushed alerts (webhook and/or websocket)
    websocket = conn.connect_websocket(coll.id)
    await websocket.connect()
    alert_id = index.create_alert(event_id=event_id,
                                  callback_url="https://your-app.example.com/hooks/camera",
                                  ws_connection_id=websocket.connection_id)

    async for message in websocket.receive():
        if message.get("channel") == "alert":
            alert = message["data"]
            print(alert["label"], alert["confidence"])
            print(alert["explanation"])
            print(alert["stream_url"])
            break

asyncio.run(main())
```

The event definition is a sentence, not a trained model. "Detect water pooling on the floor." "Detect a vehicle blocking the fire lane." Changing what you monitor for is editing a prompt.

Every alert arrives with an explanation and a playable clip of the exact moment. With `store=True`, questions work backwards too: search "delivery truck at the dock" against last week.

## Production notes

Stop resources deliberately (`index.stop()`, `understanding.stop()`, `rtstream.stop()`). Rolling windows and frame sampling are your cost dial. Fleets scale to thousands of concurrent feeds. Sensitive footage runs in your own cloud (AWS/GCP/Azure), VPC, or edge, with Zero Data Retention options and SOC 2 Type II.

## FAQ

**What is RTSP, and will my camera work?** RTSP is the standard streaming protocol spoken by virtually every IP camera, NVR, and drone gateway. If your device exposes an RTSP URL, it connects. No vendor SDK needed.

**Do I need to train a model?** No. Analyzers are prompt-driven VLMs. Events are natural language. Custom CV models are supported when needed.

**How fast are alerts?** Understanding runs in rolling windows you configure (e.g. 5s). Alerts push over WebSocket/webhook as events are detected, so awareness is seconds-scale.

**Can I search past footage?** Yes. With storage enabled, stream history is indexed and searchable, and results return playable clips.

---

Runnable demos (intrusion, flood, baby monitor): https://github.com/video-db/videodb-cookbook · Fleet scale: https://videodb.io/live-camera-intelligence
