Skip to main content
as
All posts

A Second Pair of Eyes: Teaching CCTV to Spot Smoke and Fire

Turning passive CCTV into a wildfire early-warning system: YOLO detects smoke and fire, MediaMTX re-streams the video over Tailscale to a server, and alerts land in Telegram for the field team to check.

4 min read Read in Bahasa Indonesia

Forest and land fires are a real challenge where I work, especially in the dry season. CCTV cameras were already installed from the start, pointed at high-risk areas. The problem is that CCTV is passive: the footage is there, but nobody is watching the screen all the time. A thin wisp of smoke in the distance is easy to miss, and by the time someone notices, the fire has often grown.

So the question wasn’t “do we need more cameras?” but how do we make the cameras we already have report on their own, whether it’s smoke during the day or flames at night?

The system at a glance

The idea is simple: let a model “watch” the CCTV around the clock, and only bring people in when something needs checking.

NVR (RTSP)
  │
  ▼
CameraWorker
  ├─ capture thread ─────► live frame + overlay
  │        ▲                        │
  │        │ latest detections      ▼
  │        │                     FFmpeg
  │        │                        │
  │        │                        ▼
  │        │                     MediaMTX (RTSP · HLS · WebRTC)
  │        │                        │
  │        │                        ▼
  │        │                     Tailscale ─► App on the server
  │        │
  └─ inference thread (YOLO, 2 FPS)
           │
           ▼
        Telegram bot ─► Alert channel ─► Field team

FastAPI :8000 ─► health, status, and worker control only

How it works

Video straight from the NVR

Every camera is already recorded by the NVR, so the system simply pulls RTSP streams from one place. No new cameras were installed, and nothing changed on the cameras themselves.

YOLO for smoke and fire

The YOLO model is trained to recognise two things: smoke and fire. They cover for each other. Smoke is the earliest sign during the day, visible from far away before any flames are. At night, smoke is almost invisible, but flames stand out, even after the camera switches to infrared.

Video and detection run separately

Each camera is handled by one worker with two lanes. The first passes the live video through as-is, so it stays smooth. The second runs YOLO twice a second, and its latest detections are drawn on the video as an overlay: a box around the smoke or fire, the camera name, and the confidence. For slow-moving smoke and fire, twice a second is plenty, and it keeps the load on the machine much lighter.

Re-streamed through MediaMTX and Tailscale

The overlaid video is sent to MediaMTX, which serves it back out as RTSP, HLS, and WebRTC, so the stream can be opened in an app, in VLC, or straight in a browser. The app on the server reaches it over Tailscale, a private network that links the on-site machine to the server without opening any ports to the internet.

Telegram alerts

Whenever smoke or fire is detected, a Telegram bot sends a photo along with the camera name, object type, confidence, and time to a channel. To keep the channel from flooding during a single event, alerts for the same camera and object are spaced out.

Built to survive outages

Field networks are not always stable. If the NVR stream drops or the media server isn’t ready, the system doesn’t go down with it. The camera is marked offline and automatically tries to reconnect every few seconds. FastAPI is only used to check the system’s health, see each camera’s status, and start or stop workers. The video itself never goes through FastAPI.

The result

This is what an alert looks like in the channel. During the day, the orange box marks smoke detected in the distance:

Telegram alert with a CCTV frame from CAM-04 Kintap, a 67% smoke detection box, and the camera, object, confidence, and time

The alert text is in Indonesian because that is what the team reads (Kamera = camera, Objek = object, Waktu = time). In the channel, alerts for the same camera arrive several times a few minutes apart (67–74% confidence). That pattern is actually useful: smoke that keeps showing up at the same spot is a much stronger signal than a single detection.

Night is a different story. The same camera has switched to infrared, and this time it is fire that gets detected: two glowing spots on the hillside at 53% and 42% confidence, marked with red boxes:

Night-time Telegram alert from CAM-04 Kintap in infrared mode, with two fire detection boxes at 53% and 42%

Confidence tends to be lower at night because the image is black-and-white and short on detail. Yet this is exactly where alerts pay off most: at that hour, chances are nobody is watching the screens.

Ground check by the field team

The model is not the decision-maker; it is an early-warning system. The flow is:

  1. An alert lands in the Telegram channel.
  2. The team opens the stream to see the current view from that camera.
  3. If it is still unclear, or smoke or fire is visible, the field team heads out to ground check the location.
  4. What they find decides the next step.

That shifts people’s role from “staring at screens all day” to “responding when something needs checking”.

Things to watch out for

  • False positives will happen. Morning fog, low clouds, road dust, or smoke from burning rubbish can look like a fire. At night, house lights and vehicle headlights can be mistaken for flames.
  • Camera conditions change. Morning, midday, and night light all differ, not to mention dirty lenses. Test the model under all of them.
  • A system that silently dies is more dangerous than one that is occasionally wrong. Automatic reconnects and status monitoring matter as much as model accuracy.
  • Keep a history of detections. Frames plus the ground-check outcome (real smoke/fire or not) are the best material for retraining the next model.

Closing

CCTV that is already installed can become far more useful without replacing any hardware. Add a pair of eyes that never gets tired, day or night (YOLO), a media server to re-stream the video (MediaMTX), a safe path to carry it (Tailscale), and a fast way to call people in (Telegram). With wildfires, a few minutes earlier can decide whether a fire is still easy to put out or has already spread.

Share

Discussion

Questions or thoughts? Continue the conversation on GitHub.

Search this site