This guide expands the earlier quick start examples with a deeper look at the RTStream, RTStreamSceneIndex, and Event APIs.
It also summarises how you can tune scene extraction and frame sampling so that your real‑time pipelines stay both cost‑efficient and semantically rich.
1 Connecting a live stream
# assume you already have `conn = videodb.connect(api_key="...")`
coll = conn.get_collection()
rtstream = coll.connect_rtstream(
name="Mumbai CCTV",
rtsp_url="rtsp://user:pass@1.1.1.1:554/mystream"
)
The returned RTStream object represents the persistent ingest pipeline from your camera or encoder.
2 Indexing scenes in real time
scene_index = rtstream.index_scenes(
extraction_type=SceneExtractionType.time_based, # or shot_based
extraction_config={"time": 2, "frame_count": 5},
prompt="Describe the scene and highlight congestion",
name="traffic_monitor"
)
3 Working with RTStreamSceneIndex
The object returned by index_scenes() exposes real‑time analytics utilities.
4 Defining reusable Events
conn.create_event() registers a server‑side rule that can be reused across multiple streams or indices.
event_id = conn.create_event(
event_prompt="Detect pedestrians crossing the zebra",
label="human_detection"
)
5 End‑to‑end sample
rtstream = coll.connect_rtstream("Mumbai CCTV", rtsp_url=RTSP_URL)
scene_idx = rtstream.index_scenes(prompt="Summarise traffic")
# Generic pedestrian detector, reused in multiple places
ped_event = conn.create_event("Detect pedestrians", label="pedestrian")
alert_id = scene_idx.create_alert(ped_event, callback_url="https://api.example.com/webhooks/ped")
① ingests frames → ② generates per‑scene embeddings + text → ③ evaluates pedestrian rule → ④ fires a webhook in <1 s.
6 Next steps & notebooks
For deeper, domain‑specific recipes clone or run the published Colab notebooks: