> ## Documentation Index
> Fetch the complete documentation index at: https://docs.videodb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-Camera Public Safety Surveillance

> AI-powered 4-camera surveillance system for public safety monitoring with multi-angle alerting

<a href="https://colab.research.google.com/github/video-db/videodb-cookbook/blob/main/real_time_streaming/multicam/Multicam_Public_Surveillance.ipynb" target="_blank">
  <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" noZoom />
</a>

## The Challenge

Modern cities face growing challenges in ensuring public safety. From crowded metros to busy intersections, monitoring many locations in real-time is tough.

Traditional systems rely on humans watching multiple screens — costly, error-prone, and unable to correlate events across cameras.

What if AI could monitor all feeds, detect incidents instantly, and alert authorities automatically?

## What You'll Build

VideoDB RTStream brings AI-powered intelligence to multi-camera systems. In this guide, you'll build a surveillance network that:

* Connects 4 camera feeds across a public space
* Detects 3 types of security incidents simultaneously
* Monitors 12 event streams (4 cameras × 3 events)
* Generates 2×2 multi-angle evidence for forensic analysis
* Sends real-time alerts to security authorities

## 4-Camera Surveillance Network

```
🏙️ City Public Square - 4 Camera System

├── CAM 1: Plaza Overview (High Angle - East)
│   └── rtsp://samples.rts.videodb.io:8554/pub-cam1
│
├── CAM 2: Main Walkway (Close Up)
│   └── rtsp://samples.rts.videodb.io:8554/pub-cam2
│
├── CAM 3: Stairway Junction
│   └── rtsp://samples.rts.videodb.io:8554/pub-cam3
│
└── CAM 4: Central Plaza (Mid Angle)
    └── rtsp://samples.rts.videodb.io:8554/pub-cam4
```

## Setup

### Install Dependencies

```bash theme={null}
pip install videodb
```

### Connect to VideoDB

```python theme={null}
import videodb

api_key = "your_api_key"
conn = videodb.connect(api_key=api_key)
coll = conn.get_collection()
```

## Implementation

### Step 1: Define All 4 Camera Streams

```python theme={null}
cameras = {
    "plaza_overview": "rtsp://samples.rts.videodb.io:8554/pub-cam1",
    "main_walkway": "rtsp://samples.rts.videodb.io:8554/pub-cam2",
    "stairway_junction": "rtsp://samples.rts.videodb.io:8554/pub-cam3",
    "central_plaza": "rtsp://samples.rts.videodb.io:8554/pub-cam4",
}

# Connect all camera streams
rtstreams = {}
for cam_name, rtsp_url in cameras.items():
    rtstreams[cam_name] = coll.connect_rtstream(
        name=f"Surveillance: {cam_name.replace('_', ' ').title()}",
        url=rtsp_url,
        store=True,
    )
```

### Step 2: Create Shared Indexes on All Cameras

Define one comprehensive analysis prompt and create indexes on all 4 streams:

```python theme={null}
analysis_prompt = """Analyze this surveillance footage. Describe:
1. People with trolley bags, backpacks, or luggage
2. Crowd behavior (groups gathering, movement patterns)
3. Unusual objects (unattended items)
Be specific about location and appearance."""

scene_understandings = {}
for cam_name, rtstream in rtstreams.items():
    understanding = rtstream.understand(
        segmentation={"type": "time", "window": "10s"},
        analyzers=[{
            "type": "vlm",
            "name": "scene",
            "sampling": {"frame_count": 1},
            "config": {"prompt": analysis_prompt},
        }],
        store=True,
    )
    scene_understandings[cam_name] = {
        "understanding": understanding,
        "output": understanding.outputs.get("scene"),
    }

scene_indexes = {}
for cam_name, rtstream in rtstreams.items():
    scene = scene_understandings[cam_name]
    index = rtstream.index(
        source=scene["output"],
        name=f"Surveillance_{cam_name.upper()}",
        use_for=["semantic"],
    )
    scene_indexes[cam_name] = {
        "understanding": scene["understanding"],
        "output": scene["output"],
        "index": index,
        "index_id": index.id,
    }
```

### Step 3: Define 3 Shared Security Events

Create events that apply across all cameras:

```python theme={null}
# Unattended Luggage (High Priority)
luggage_event_id = conn.create_event(
    event_prompt="Detect luggage, backpacks, or packages left unattended.",
    label="unattended_luggage",
)

# Large Crowd Formation (Alert)
crowd_event_id = conn.create_event(
    event_prompt="Identify when >4 people gather quickly in a concentrated area.",
    label="large_crowd_formation",
)

# Person with Trolley (Tracking)
trolley_event_id = conn.create_event(
    event_prompt="Detect any person with trolley bag or rolling suitcase.",
    label="person_with_trolley",
)

```

### Step 4: Attach Alerts to All 4 Cameras

```python theme={null}
webhook_url = "https://your-security-center-webhook.com"

event_ids = {
    "luggage": luggage_event_id,
    "crowd": crowd_event_id,
    "trolley": trolley_event_id,
}

# Create alerts for all 3 events on all 4 cameras (12 total alerts)
for cam_name, scene_index in scene_indexes.items():
    for event_type, event_id in event_ids.items():
        scene_index["index"].create_alert(event_id, callback_url=webhook_url)
```

Now you have a comprehensive 4-camera × 3-event surveillance grid (12 alert streams).

## Illustrative Alert Envelopes

These examples show a possible live payload. Inspect the received alert before relying on optional fields.

### Unattended Luggage Alert (Critical Priority)

```json theme={null}
{
  "event_id": "event-luggage-001",
  "label": "unattended_luggage",
  "confidence": 0.96,
  "explanation": "A black backpack is detected on the plaza ground with no person visibly attached to it. Has been stationary for >1 minute.",
  "timestamp": "2025-09-10T17:02:15.811085+00:00",
  "start_time": "2025-09-10T22:31:50.886736+05:30",
  "end_time": "2025-09-10T22:32:05.886736+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019711db-1086-7750-ba79-8f47a4fed603/1757523710000000-1757523726000000.m3u8"
}
```

### Large Crowd Formation Alert

```json theme={null}
{
  "event_id": "event-crowd-001",
  "label": "large_crowd_formation",
  "confidence": 0.92,
  "explanation": "Multiple individuals (8+) rapidly gathering in central plaza area. Unusual congregation pattern.",
  "timestamp": "2025-09-10T17:15:42.123456+00:00",
  "start_time": "2025-09-10T22:45:30.000000+05:30",
  "end_time": "2025-09-10T22:45:45.000000+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019711db-1086-7750-ba79-8f47a4fed603/1757524530000000-1757524545000000.m3u8"
}
```

### Person with Trolley Alert (Tracking)

```json theme={null}
{
  "event_id": "event-trolley-001",
  "label": "person_with_trolley",
  "confidence": 0.95,
  "explanation": "Female with black rolling suitcase detected moving through plaza.",
  "timestamp": "2025-09-10T17:02:15.811085+00:00",
  "start_time": "2025-09-10T22:31:50.886736+05:30",
  "end_time": "2025-09-10T22:32:05.886736+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019711db-1086-7750-ba79-8f47a4fed603/1757523710000000-1757523726000000.m3u8"
}
```

## Synchronized Multi-Angle Evidence

When an incident is detected, you can retrieve clips from all 4 cameras for the same requested interval and arrange them in a 2×2 view:

```python theme={null}
# Extract incident timestamp from alert
incident_epoch = 1757523730  # from alert data

# Generate four clips for the same requested interval (±10 seconds)
time_window = 10
evidence_clips = {}

for cam_name, rtstream in rtstreams.items():
    rtstream.generate_stream(
        start=incident_epoch - time_window,
        end=incident_epoch + time_window
    )
    evidence_clips[cam_name] = rtstream.stream_url

# Compose the four HLS clips in a 2×2 layout for review.
```

Use clock-aligned camera sources before treating clips from the same requested interval as synchronized evidence.

## The Result

This demo shows how AI turns raw surveillance feeds into actionable intelligence for:

* **Public safety monitoring** across wide areas
* **Crowd management** and anomaly detection
* **Security threat detection** in real-time
* **Forensic investigation** with multi-angle evidence
* **Real-time incident response** with 2×2 multi-angle playback

Key capabilities:

* **12 Event Streams** - Coverage of 4 camera angles with 3 security events each
* **Sub-Second Alerts** - Instant notification when incidents occur
* **Multi-Angle Evidence** - Synchronized clips from all cameras for investigations
* **Scalability** - Pattern can extend to 10, 20, or 100+ cameras
* **24/7 Monitoring** - Fully automated, no human fatigue

<Card icon="notebook" title="Explore the Full Notebook" href="https://colab.research.google.com/github/video-db/videodb-cookbook/blob/main/real_time_streaming/multicam/Multicam_Public_Surveillance.ipynb">
  Open the complete implementation with webhook setup, ngrok integration, and forensic analysis.
</Card>

## Related Tutorials

<CardGroup cols={2}>
  <Card title="Property Intrusion Detection" icon="lock" href="/examples-and-tutorials/live-intelligence/intrusion-detection">
    Intelligent security system with tiered threat detection
  </Card>

  <Card title="Multi-Camera Basketball Analytics" icon="activity" href="/examples-and-tutorials/live-intelligence/multicam-basketball-analysis">
    Real-time sports analysis with synchronized playback
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.