> ## 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.

# RTSP Ingest

> Connect any RTSP/RTMP video source to VideoDB. Cameras, encoders, and live feeds become instantly searchable and actionable.

## Quick Example

<CodeGroup>
  ```python Python theme={null}
  import videodb

  conn = videodb.connect()
  coll = conn.get_collection()

  # Connect a live stream
  rtstream = coll.connect_rtstream(
      name="Lobby Camera",
      url="rtsp://user:pass@192.168.1.100:554/stream"
  )
  print(rtstream.id)  # rts-xxx
  ```

  ```javascript Node.js theme={null}
  import { connect } from 'videodb';

  const conn = await connect();
  const coll = await conn.getCollection();

  // Connect a live stream
  const rtstream = await coll.connectRtstream({
      name: "Lobby Camera",
      rtspUrl: "rtsp://user:pass@192.168.1.100:554/stream"
  });
  console.log(rtstream.id);  // rts-xxx
  ```
</CodeGroup>

***

## Connection Methods

### RTSP URL Format

```
rtsp://[username:password@]host[:port]/path
```

**Examples:**

```
rtsp://admin:pass123@192.168.1.100:554/live
rtsp://camera.example.com:554/stream1
rtsp://user:pass@10.0.0.50/cam/realmonitor
```

### Connect from Camera

<CodeGroup>
  ```python Python theme={null}
  # IP Camera
  rtstream = coll.connect_rtstream(
      name="Warehouse Camera 1",
      url="rtsp://admin:password@192.168.1.50:554/live"
  )

  # Encoder/NVR
  rtstream = coll.connect_rtstream(
      name="NVR Channel 3",
      url="rtsp://admin:admin@nvr.local:554/ch3"
  )
  ```

  ```javascript Node.js theme={null}
  // IP Camera
  const rtstream = await coll.connectRtstream({
      name: "Warehouse Camera 1",
      rtspUrl: "rtsp://admin:password@192.168.1.50:554/live"
  });

  // Encoder/NVR
  const rtstreamNVR = await coll.connectRtstream({
      name: "NVR Channel 3",
      rtspUrl: "rtsp://admin:admin@nvr.local:554/ch3"
  });
  ```
</CodeGroup>

***

## RTStream Object

After connecting, you receive an RTStream object:

| Attribute       | Type  | Description                  |
| :-------------- | :---- | :--------------------------- |
| `id`            | str   | Unique identifier (rts-xxx)  |
| `name`          | str   | Label you supplied           |
| `collection_id` | str   | Parent collection            |
| `status`        | str   | `connected`, `stopped`, etc. |
| `sample_rate`   | float | Frame rate (default: 1 fps)  |
| `audio`         | bool  | Audio ingestion enabled      |

***

## Retrieve Existing Streams

### Get by ID

<CodeGroup>
  ```python Python theme={null}
  rtstream = coll.get_rtstream("rts-xxx")
  ```

  ```javascript Node.js theme={null}
  const rtstream = await coll.getRtstream("rts-xxx");
  ```
</CodeGroup>

### List All Streams

<CodeGroup>
  ```python Python theme={null}
  rtstreams = coll.list_rtstreams(
      limit=10,
      offset=0,
      status="connected",
      name="Lobby",
      ordering="-created_at"
  )
  ```

  ```javascript Node.js theme={null}
  const rtstreams = await coll.listRtstreams({
      limit: 10,
      offset: 0,
      status: "connected",
      name: "Lobby",
      ordering: "-created_at"
  });
  ```
</CodeGroup>

| Parameter  | Description                            |
| :--------- | :------------------------------------- |
| `limit`    | Number of results                      |
| `offset`   | Skip N results                         |
| `status`   | Filter by status                       |
| `name`     | Filter by name                         |
| `ordering` | Sort field (prefix `-` for descending) |

***

## Playback URLs

Generate HLS/MP4 URLs for any time range using Unix timestamps:

<CodeGroup>
  ```python Python theme={null}
  import time

  # Get playback URL for last 60 seconds
  now = int(time.time())
  start = now - 60
  stream_url = rtstream.generate_stream(start=start, end=now)
  ```

  ```javascript Node.js theme={null}
  // Get playback URL for last 60 seconds
  const now = Math.floor(Date.now() / 1000);
  const start = now - 60;
  const streamUrl = await rtstream.generateStream({ start, end: now });
  ```
</CodeGroup>

<Note>
  The `start` and `end` parameters expect Unix timestamps (seconds since epoch), not relative time offsets.
</Note>

***

## Supported Sources

| Source            | Format    | Notes                          |
| :---------------- | :-------- | :----------------------------- |
| IP Cameras        | RTSP      | Most common, H.264/H.265       |
| NVR/DVR           | RTSP      | Per-channel streams            |
| Encoders          | RTSP/RTMP | OBS, FFmpeg, hardware encoders |
| Streaming Servers | RTSP      | Wowza, nginx-rtmp              |

***

## Connection Notes

* **Secure Storage** - All video feeds are securely stored and accessible anytime
* **Default Sample Rate** - Streams are ingested at 1 fps by default
* **Network** - Ensure your RTSP source is accessible from VideoDB's servers

***

## What You Can Build

<CardGroup cols={2}>
  <Card title="Baby Crib Monitoring" icon="baby" href="/examples-and-tutorials/live-intelligence/baby-crib-monitoring">
    Real-time infant monitoring with AI-powered alerts
  </Card>

  <Card title="Intrusion Detection" icon="shield" href="/examples-and-tutorials/live-intelligence/intrusion-detection">
    Detect unauthorized access to restricted areas
  </Card>

  <Card title="Traffic Violations" icon="car" href="/examples-and-tutorials/live-intelligence/traffic-violations">
    Monitor traffic cameras for red light and stop sign violations
  </Card>
</CardGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card icon="zap" title="Real-time APIs" href="/pages/ingest/live-streams/realtime-apis">
    Index, transcribe, and set up alerts
  </Card>

  <Card icon="link" title="Stream Lifecycle" href="/pages/ingest/live-streams/stream-lifecycle">
    Start, stop, and reconnect patterns
  </Card>
</CardGroup>
