Skip to main content
Open In Colab

The Story

Tonight is the ICC World Cup finals between India and Pakistan. Millions are watching the match live, and the competition to post match highlights — sixes, wickets, and spectacular catches — on social media is fiercer than ever. In the usual workflow, someone watches the match, waits for a moment to happen, then clips the video manually and uploads it online — often several minutes too late. But we have a smarter way. What if AI could monitor the match for you, detect key moments in real-time, and instantly send alerts when something exciting happens — giving you a headstart on posting highlights while everyone else scrambles?

What You’ll Build

With VideoDB RTStream, you can build a system that:
  • Monitors live cricket feeds continuously
  • Detects key moments: sixes, fours, catches, and wickets
  • Sends real-time alerts when highlights happen
  • Provides instant video clips for social media sharing

Setup

Install Dependencies

pip install videodb

Connect to VideoDB

import videodb

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

Implementation

Step 1: Connect to the Cricket Stream

rtsp_url = "rtsp://samples.rts.videodb.io:8554/cricket"
cricket_stream = coll.connect_rtstream(
    name="Cricket Match Stream",
    url=rtsp_url,
)

Step 2: Index Scenes with Cricket Analysis

Create a scene index that analyzes the cricket match continuously. The batch config is tuned to capture the fast-paced nature of cricket - analyzing every 7 seconds with 7 frames for detailed action detection.
cricket_scene_index = cricket_stream.index_visuals(
    batch_config={
        "type": "time",
        "value": 7,
        "frame_count": 7,
    },
    prompt="""Identify and mention when a batsman hits a SIX (ball flying over the boundary rope),
              a FOUR (ball crosses boundary rope after bouncing), a CATCH OUT (fielder catches
              the ball mid-air before it touches ground) or a WICKET (when the wicket stumps
              are put down by the ball).""",
    name="Cricket_Highlights_Index",
)
The higher frame_count: 7 captures the rapid action of cricket, ensuring key moments aren’t missed.

Step 3: Define Four Highlight Events

Create events for each type of highlight that matches your indexing prompt:
# Six Hit
six_event_id = conn.create_event(
    event_prompt="Detect when a batsman hits a SIX - ball flying over the boundary rope.",
    label="six_hit",
)

# Four Hit
four_event_id = conn.create_event(
    event_prompt="Detect when a batsman hits a FOUR - ball crosses boundary rope after bouncing.",
    label="four_hit",
)

# Catch Out
catch_event_id = conn.create_event(
    event_prompt="Detect when a fielder takes a CATCH OUT - catching the ball mid-air.",
    label="catch_out",
)

# Wicket
wicket_event_id = conn.create_event(
    event_prompt="Detect when a WICKET occurs - wicket stumps are put down.",
    label="wicket",
)

Step 4: Attach Alerts for Each Highlight

Create alerts for all four events on the same webhook:
webhook_url = "https://your-webhook-url.com"

# Attach alerts for each event type
six_alert_id = cricket_scene_index.create_alert(six_event_id, callback_url=webhook_url)
four_alert_id = cricket_scene_index.create_alert(four_event_id, callback_url=webhook_url)
catch_alert_id = cricket_scene_index.create_alert(catch_event_id, callback_url=webhook_url)
wicket_alert_id = cricket_scene_index.create_alert(wicket_event_id, callback_url=webhook_url)
All alerts go to the same webhook, with the label field indicating which highlight was detected.

What You Receive

When a highlight is detected, your webhook receives an alert with the exact moment and video clip:
{
  "event_id": "event-3bfdd25d9239861b",
  "label": "four_hit",
  "confidence": 0.95,
  "explanation": "The ball is crossing the boundary after bouncing, indicating a FOUR has been scored.",
  "timestamp": "2025-05-29T00:11:09.256447+00:00",
  "start_time": "2025-05-29T05:40:32.544547+05:30",
  "end_time": "2025-05-29T05:40:39.730362+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019711db-1086-7750-ba79-8f47a4fed603/1748477432000000-1748477440000000.m3u8"
}

The Result

With this setup in place, broadcasters and content creators no longer have to wait, clip, and scramble. They can stay ahead of the crowd, instantly catching and sharing match-defining moments as they happen — turning every six, four, wicket, and catch into social media gold within seconds.

Explore the Full Notebook

Open the complete implementation with additional features and helper functions for match analysis.