Skip to main content
Open In Colab

The Viral Inspiration

You’ve seen the post. A guy got so fed up with daily traffic chaos that he automated his helmet camera to snap violations and send them straight to the traffic police - no manual intervention needed.

View the inspiration

Check out the original post that sparked this idea
The internet loved it. And we thought - why not make this accessible to everyone? With VideoDB RTStream, you can do exactly this. Connect your dashcam or helmet cam, let AI monitor for violations, and auto-report them. Let’s see how it works.

How It Works

Helmet Cam / Dashcam

🔗 RTSP Stream → VideoDB RTStream

🤖 AI Scene Analysis (every 5 sec, 5 frames)

🚨 Violation Detected? → Webhook Alert

📧 n8n Workflow → Email to Traffic Police
Simple pipeline. Powerful impact.

The Setup

1. Connect Your Stream

import videodb

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

rtsp_url = "rtsp://your-camera-stream-url"
roadcam_stream = coll.connect_rtstream(
    name="RoadCam Violation Stream",
    url=rtsp_url,)

2. Create the Violation Detection Index

This is where the magic happens. We tell the AI exactly what to look for:
from videodb import SceneExtractionType

violation_prompt = """
Focus on vehicles visible on the road and monitor them for the following traffic rule violations:

1. NO HELMET: Two-wheeler rider or pillion not wearing a helmet
2. MOBILE PHONE USE: Driver using mobile phone while operating the vehicle
3. WRONG SIDE DRIVING: Vehicle traveling against the designated traffic flow
4. RED LIGHT VIOLATION: Vehicle crossing when traffic signal is red
5. TRIPLE RIDING: More than two people on a single two-wheeler
6. NO SEATBELT: Driver or front passenger not wearing seatbelt

If you detect a violation, respond in this format:

Traffic Rule Violated
Vehicle: [vehicle type and color]
Plate Number: [license plate if visible, otherwise "Not Visible"]
Violation: [specific violation from the list]
Description: [brief description]

If NO violation is detected, respond ONLY with:
No Traffic Rule Violation Detected
"""

violation_scene_index = roadcam_stream.index_scenes(
    extraction_type=SceneExtractionType.time_based,
    extraction_config={
        "time": 5,
        "frame_count": 5,
    },
    prompt=violation_prompt,
    name="Traffic_Violation_Index")

3. Set Up Event & Alert

# Create the violation event
violation_event_id = conn.create_event(
    event_prompt="""
    Detect when a traffic rule violation occurs, such as no helmet, mobile phone use, wrong side driving, red light violation, triple riding, or no seatbelt.
    Your 'explanation' should not include any commentary, and should clearly mention the following things:
    Traffic Rule Violated
    Vehicle: [vehicle type and color, e.g., "Black motorcycle", "White sedan"]
    Plate Number: [license plate number if visible, otherwise "Not Visible"]
    Violation: [specific violation(s) from the list above]
    Description: [brief description of what you observed]
    """,
    label="traffic_violation")

# Attach webhook alert
violation_alert_id = violation_scene_index.create_alert(
    violation_event_id,
    callback_url="https://your-webhook-url.com")

What You Get

When a violation is caught, your webhook receives:
{
  "event_id": "event-3fd4174feceb6162",
  "label": "traffic_violation",
  "confidence": 0.95,
  "explanation": """
    Traffic Rule Violated: NO HELMET
    Vehicle: Orange scooter
    Plate Number: DL 3S CW 4952
    Violation: NO HELMET
    Description: The rider and the pillion rider on the orange scooter are not wearing helmets.
    """,
  "timestamp": "2026-01-07T04:57:44.081850+00:00",
  "start_time": "2026-01-07T10:27:20.432151+05:30",
  "end_time": "2026-01-07T10:27:27.742309+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019b929e-e004-72b0-94d6-b7582510934f/1767761840000000-1767761848000000.m3u8",
  "player_url": "https://console.videodb.io/player?url=https://rt.stream.videodb.io/manifests/rts-019b929e-e004-72b0-94d6-b7582510934f/1767761840000000-1767761848000000.m3u8"
}
The stream_url is a direct link to the violation clip - ready to attach to your report.

Automated Enforcement Pipeline: From Video to Inbox

This n8n workflow acts as the Digital Dispatch Center, transforming raw AI detections into professional traffic reports in real-time.
  1. Webhook Trigger: Receives the raw event payload from the VideoDB Safety Agent immediately upon violation detection.
  2. AI Data Extraction: A dedicated VideoDB node parses the unstructured explanation string into a structured JSON object containing the License Plate, Vehicle Description, and Violation Type.
  3. Report Formatting: A code node generates a high-contrast, professional HTML email template that maps the AI observations to a formal report structure.
  4. Official Delivery: The finalized report - complete with the dynamic subject line and a direct link to the video evidence - is dispatched instantly via the Gmail node to the Traffic Control Room.
N8N workflow automation showing the steps for traffic violation detection and email delivery No more manual reporting. Just set it and forget it.

Email received via N8N Automation

Email received via N8N automation showing the professional report format

Try It Yourself

Open the Notebook

Run the complete implementation in Google Colab with step-by-step examples
n8n workflow JSON attached below, simply copy the code and paste in your N8N instance, and set up the credentials to get the automation running!
{
  "nodes": [
    {
      "parameters": {
        "path": "traffic-violation-webhook",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [0, 80],
      "id": "34895f49-bcde-43cd-9112-60bbee8147a0",
      "name": "Webhook"
    },
    {
      "parameters": {
        "operation": "generateText",
        "prompt": "=You are a data extraction specialist. Your task is to parse a raw traffic violation string into a strict JSON format.|INPUT: \"{{ $json.explanation }}\" TASK:Extract the following fields. If a field is missing or unclear, use \"N/A\" as the value.1. vehicle_details2. license_plate: (The alpha-numeric plate number)3. violation_type: (The specific rule broken like no helmet, mobile phone use, wrong side driving, red light violation, triple riding, or no seatbelt)4. observation: (A short, clean summary of the evidence)STRICT RULES:- Output ONLY valid JSON.- No markdown formatting, no backticks, no preamble.- If the input is empty or invalid, return an object with all values set to \"Unknown\".JSON STRUCTURE:{  \"vehicle_type\": \"\",  \"license_plate\": \"\",  \"violation_type\": \"\",  \"observation\": \"\"}",
        "response_type": "json"
      },
      "type": "@videodb/n8n-nodes-videodb.videoDb",
      "typeVersion": 1,
      "position": [224, 80],
      "id": "5a16a040-9ab9-4001-9281-8e6963cf5d6b",
      "name": "VideoDB"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [448, 80],
      "id": "d04dff57-2b8b-4d5f-b96f-364349623c49",
      "name": "Wait"
    },
    {
      "parameters": {
        "url": "={{ $('VideoDB').item.json.data.output_url }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "videoDBApi",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [672, 0],
      "id": "0048b380-50ac-4da0-a949-35d7ae0f3fe3",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "0ab68efa-a4ba-4235-b3e8-6c3967880aef",
              "leftValue": "={{ $json.status }}",
              "rightValue": "complete",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [896, 80],
      "id": "74645a4a-4ab0-4efe-84e9-052457fb2cb2",
      "name": "If"
    },
    {
      "parameters": {
        "sendTo": "={{ $json.to }}",
        "subject": "={{ $json.subject }}",
        "message": "={{ $json.html }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1344, 80],
      "id": "17d26012-f389-40e9-be75-dcce6640d0dc",
      "name": "Send a message"
    },
    {
      "parameters": {
        "jsCode": "const webhookData = $('Webhook').first().json;\nconst llmResult = $input.first().json.response.data.output;\n\nconst eventDate = new Date(webhookData.start_time).toLocaleString('en-IN', {\n  timeZone: 'Asia/Kolkata',\n  dateStyle: 'long',\n  timeStyle: 'medium'\n});\n\nconst htmlBody = `<div style=\"max-width:500px;margin:20px auto;border:2px solid #000;font-family:Arial,sans-serif;color:#000;padding:0;\"><div style=\"padding:20px;border-bottom:2px solid #000;text-align:center;\"><h2 style=\"margin:0;text-transform:uppercase;\">Traffic Violation Alert</h2><p style=\"margin:5px 0 0 0;font-size:14px;\">Automated Detection Report</p></div><div style=\"padding:20px;\"><table style=\"width:100%;border-collapse:collapse;color:#000;\"><tr><td style=\"padding:10px 0;border-bottom:1px solid #eee;\"><strong>Detected Violation</strong></td><td style=\"padding:10px 0;border-bottom:1px solid #eee;text-align:right;\">${llmResult.violation_type}</td></tr><tr><td style=\"padding:10px 0;border-bottom:1px solid #eee;\"><strong>Vehicle Description</strong></td><td style=\"padding:10px 0;border-bottom:1px solid #eee;text-align:right;\">${llmResult.vehicle_type}</td></tr><tr><td style=\"padding:10px 0;border-bottom:1px solid #eee;\"><strong>License Plate</strong></td><td style=\"padding:10px 0;border-bottom:1px solid #eee;text-align:right;\"><code style=\"font-size:16px;font-weight:bold;\">${llmResult.license_plate}</code></td></tr><tr><td style=\"padding:10px 0;border-bottom:1px solid #eee;\"><strong>Incident Time</strong></td><td style=\"padding:8px 0;border-bottom:1px solid #eee;text-align:right;\">${eventDate}</td></tr></table><div style=\"margin-top:20px;padding:15px;border:1px solid #000;background-color:#fcfcfc;\"><p style=\"margin:0;font-size:14px;\"><strong>AI Observation:</strong> ${llmResult.observation}</p></div><div style=\"margin-top:30px;text-align:center;\"><a href=\"${webhookData.player_url}\" style=\"display:inline-block;padding:12px 30px;border:2px solid #000;color:#000;text-decoration:none;font-weight:bold;text-transform:uppercase;font-size:14px;\">Click to View Evidence Clip</a></div></div></div>`;\n\nreturn {\n  to: \"[email protected]\",\n  subject: `Violation Alert: ${llmResult.violation_type} [${llmResult.license_plate}]`,\n  html: htmlBody\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1120, 80],
      "id": "342feeb0-a5b6-4e20-a4eb-e4e962539439",
      "name": "Format Report"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [[{"node": "VideoDB","type": "main","index": 0}]]
    },
    "VideoDB": {
      "main": [[{"node": "Wait","type": "main","index": 0}]]
    },
    "Wait": {
      "main": [[{"node": "HTTP Request","type": "main","index": 0}]]
    },
    "HTTP Request": {
      "main": [[{"node": "If","type": "main","index": 0}]]
    },
    "If": {
      "main": [
        [{"node": "Format Report","type": "main","index": 0}],
        [{"node": "Wait","type": "main","index": 0}]
      ]
    },
    "Format Report": {
      "main": [[{"node": "Send a message","type": "main","index": 0}]]
    }
  }
}
Small cameras. Smart AI. Big change. Built with VideoDB