Skip to content

Automated Traffic Violation Reporter

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.
This embedded link can't be shown.

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.
Webhook Trigger: Receives the raw event payload from the VideoDB Safety Agent immediately upon violation detection.
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.
Report Formatting: A code node generates a high-contrast, professional HTML email template that maps the AI observations to a formal report structure.
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.
image.png
No more manual reporting. Just set it and forget it.

Email received via N8N Automation

image.png

Try It Yourself

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!
JSON125 lines
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.