OASEES: Rust Detection Dataset for Critical Infrastructure And Instructions On How To Locally Deploy It

In today’s privacy-conscious world, running video streaming and AI inference locally has become increasingly important. Whether you’re building a security system, monitoring industrial processes, or just experimenting with computer vision, having full control over your data pipeline is crucial. This guide will walk you through setting up MediaMTX for local RTSP streaming and integrating it with YOLOv5 for real-time object detection.

What is MediaMTX?

MediaMTX is a powerful, lightweight media server that supports multiple protocols including RTSP, RTMP, HLS, and WebRTC. It’s perfect for creating local streaming solutions without relying on cloud services, giving you complete control over your video streams and ensuring your data stays private.

Prerequisites

Before we begin, make sure you have:

  • A Raspberry Pi (or any Linux machine) with network access
  • Python 3.7+ installed
  • Basic familiarity with SSH and terminal commands
  • A camera or video source to stream from

Step-by-Step Setup Guide

1. Connect to Your Raspberry Pi via SSH

First, establish an SSH connection to your Raspberry Pi from your local machine:

ssh pi@<RaspberryPi_IP_Address>

Replace <RaspberryPi_IP_Address> with your Raspberry Pi’s actual IP address. You can find this by running hostname -I on your Pi or checking your router’s admin panel.

When prompted, enter your password to complete the connection.

2. Locate and Configure the MediaMTX Configuration File

Once connected via SSH, navigate to your MediaMTX installation directory:

cd /path/to/mediamtxDIR
ls

You should see the mediamtx.yml configuration file in the directory listing. This YAML file contains all the settings for your RTSP server, including stream sources, authentication, and network configurations.

To start the MediaMTX server with your configuration:

./mediamtx mediamtx.yml

If MediaMTX is installed globally on your system, you can also use:

mediamtx /path/to/mediamtxDIR/mediamtx.yml

At this point, your RTSP server should be running and ready to accept connections.

3. Set Up the YOLOv5 Inference EnvironmentOpen a second terminal window (you can SSH again or use a local terminal) and navigate to your YOLOv5 directory:

cd /path/to/yolov5

Activate your Python virtual environment. The exact command depends on your setup:

# For venv users
source venv/bin/activate

# For conda users
conda activate your_yolo_env

If you haven’t installed the required dependencies yet, do so now:

pip install -r requirements.txt

This will install PyTorch, OpenCV, and other necessary packages for YOLOv5 inference.

4. Run YOLOv5 Inference on the RTSP Stream

Now comes the exciting part – connecting your AI model to the video stream. Run your YOLOv5 inference script that’s configured to read from the RTSP stream:

python detect.py --source rtsp://localhost:8554/your_stream_name --weights yolov5s.pt --conf 0.25

Your inference script should:

  • Connect to the MediaMTX RTSP stream
  • Process each frame through the YOLOv5 model
  • Log detection results and confidence scores
  • Optionally save annotated frames or send results to a web interface

5. View Results in Your Browser

If your setup includes a Flask web interface for visualizing detections, you can access it through your browser:

http://<InferenceMachine_IP>:5000

Replace <InferenceMachine_IP> with the IP address of the machine running your YOLOv5 inference server.

Benefits of This Local Setup

Privacy and Security: Your video data never leaves your local network, ensuring complete privacy and compliance with data protection regulations.

Low Latency: Direct local processing eliminates network delays, providing near real-time inference results.

Cost Effective: No cloud processing fees or bandwidth costs for uploading video streams.

Customization: Full control over your pipeline allows for custom models, preprocessing, and post-processing logic.

Reliability: No dependency on internet connectivity or third-party services.

Troubleshooting Tips

Connection Issues: Ensure your firewall allows traffic on the RTSP port (default 8554) and web interface port (5000).

Performance Problems: If inference is slow, consider using a smaller YOLOv5 model (yolov5n.pt) or reducing input resolution.

Stream Not Found: Verify that MediaMTX is running and the stream name in your inference script matches your configuration.

Next Steps

Once you have this basic setup working, consider these enhancements:

  • Add multiple camera streams
  • Implement custom detection classes for your specific use case
  • Set up automated alerts based on detection results
  • Create a database to store detection history
  • Add authentication to your web interface

Conclusion

Setting up MediaMTX locally with YOLOv5 provides a powerful foundation for privacy-first video analytics. This combination gives you professional-grade streaming capabilities with state-of-the-art AI inference, all running on your own hardware.

The flexibility of this setup makes it suitable for everything from home security systems to industrial monitoring applications. Best of all, you maintain complete control over your data and can customize every aspect of the pipeline to meet your specific needs.

Download Custom Trained Weights

To help you get started quickly, we’re providing a zip folder containing custom-trained YOLOv5 weights specifically designed for detecting particular patterns and objects in video streams. These weights have been created through customized training processes to recognize specific use cases and image types that are commonly encountered in local video analytics setups.

Download Custom Weights Package →

The custom weights included in this package will enhance your detection accuracy for specialized scenarios beyond the standard COCO dataset objects. Simply replace the --weights best.pt parameter in step 4 with the path to your downloaded custom weights folder.

Links

MediaMTX on Github: https://github.com/bluenviron/mediamtx

YOLOv5 on Github: https://github.com/ultralytics/yolov5

References

DOI: 10.5281/zenodo.16679949

Categories

,

About me

Read also…

  • OASEES: Rust Detection Dataset for Critical Infrastructure And Instructions On How To Locally Deploy It