Real-time RTSP video stream processor with motion detection, object recognition, and analysis capabilities. Built with Python and OpenCV.
Project description
RTSP Stream Processor
Real-time RTSP video stream processor with motion detection, object recognition, and analysis capabilities. Built with Python and OpenCV.
Author
Tom Sapletta
Repository
https://github.com/mediainspect/rtsp.git
๐ Features
-
RTSP Stream Handling
- Secure credential management
- Automatic reconnection
- Buffer management
- Support for TCP/UDP protocols
-
Video Processing
- Motion detection
- Object recognition
- Frame analysis
- Real-time statistics
-
Monitoring
- Performance metrics
- Health checks
- Processing statistics
- Docker integration
๐ Prerequisites
- Python 3.7+
- FFmpeg
- OpenCV dependencies
- Docker (optional)
๐ ๏ธ Makefile Usage
The Makefile provides convenient commands for common tasks. Run make help to see all available targets.
Project Management
make installโ Install dependenciesmake testโ Run testsmake lintโ Lint codemake runโ Run the main applicationmake cleanโ Remove caches
Network Scanning
make scan-networkโ Scan the default network for common servicesmake scan-camerasโ Scan for cameras and related servicesmake scan-camera IP=192.168.1.100โ Scan a specific camera IPmake scan-quickโ Quick scan of common portsmake scan-fullโ Comprehensive scanmake scan-localโ Scan common local network ranges
Printer Management
make scan-printersโ List all available printers
Shell & Interactive Clients
make shellโ Start a Python shell in the package context (now inscripts/)make interactiveโ Start the interactive command-line client (now inscripts/)
Help
make helpโ Show all available targets
๐ Shell Client
Start an interactive Python shell with project context:
make shell
(Uses scripts/shell_client.py)
๐ฅ๏ธ Interactive CLI
Launch the interactive command-line interface:
make interactive
(Uses scripts/interactive_client.py)
๐ Network Scanning & Printing
mediainspect includes powerful network scanning capabilities to discover devices like cameras and printers on your local network.
Scan for Network Devices
Scan your local network for various devices and services:
make scan-network
Discover Cameras
Find RTSP cameras on your network:
make scan-cameras
Discover Printers
List all available printers on your system:
make scan-printers
Print a Test Page
Send a test page to your default printer:
make print-test
Using the Network Scanner in Python
You can also use the network scanner directly in your Python code:
from mediainspect.scanner import NetworkScanner
import asyncio
async def scan_network():
scanner = NetworkScanner()
# Scan for all services
services = await scanner.scan_network()
# Or scan for specific service types
cameras = await scanner.scan_network(service_types=['rtsp'])
for service in services:
print(f"{service.ip}:{service.port} - {service.service} ({service.banner})")
# Run the scan
asyncio.run(scan_network())
๐จ๏ธ Printing Support
mediainspect includes basic printing capabilities using the CUPS (Common Unix Printing System) interface.
๐ง Installation
Using pip
# Clone the repository
git clone https://github.com/mediainspect/rtsp.git
cd rtsp
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: .\venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
start
python main.py
Using Docker
# Build and run using docker-compose
docker-compose up -d
# View logs
docker-compose logs -f
โ๏ธ Configuration
- Create environment file:
cp .env.template .env
- Configure your settings:
# RTSP Credentials
RTSP_USER=your_username
RTSP_PASSWORD=your_password
# RTSP Stream Configuration
RTSP_HOST=stream_host_ip
RTSP_PORT=554
RTSP_PATH=/stream
# Processing Configuration
MOTION_THRESHOLD=25.0
BLUR_SIZE=21
๐ป Usage
Basic Usage
from rtsp_client import RTSPClient
# Initialize client
client = RTSPClient()
# Connect to stream
if client.connect():
try:
while True:
frame = client.read_frame()
# Process frame here
finally:
client.disconnect()
With Custom Processing
from video_processor import VideoProcessor
processor = VideoProcessor(
motion_threshold=25.0,
blur_size=21,
min_object_size=1000
)
def process_frame(frame):
processed_frame, stats = processor.process(frame)
return processed_frame
๐ฆ Python Package Information
- Package name: mediainspect-rtsp
- PyPI: https://pypi.org/project/mediainspect-rtsp/
- Source: https://github.com/mediainspect/rtsp
- License: Apache 2.0
- Author: Tom Sapletta
- Description: Real-time RTSP video stream processor with motion detection, object recognition, and analysis capabilities. Built with Python and OpenCV.
Installation
pip install mediainspect-rtsp
Usage Example
from mediainspect_rtsp.video_processor_rtsp_class import VideoProcessor
processor = VideoProcessor(rtsp_url="rtsp://...", motion_threshold=25.0)
processor.run()
For more details, see the PyPI page and documentation.
๐ Monitor and Debug
Health Checks
Access health metrics at:
Prometheus & Grafana
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
๐ ๏ธ Development
Project Structure
rtsp-processor/
โโโ src/
โ โโโ rtsp_client.py # RTSP handling
โ โโโ video_processor.py # Video processing
โ โโโ config.py # Configuration management
โโโ tests/
โ โโโ test_*.py # Test files
โโโ docker/
โ โโโ Dockerfile # Container definition
โ โโโ docker-compose.yml
โโโ .env.template # Environment template
โโโ scripts/
โ โโโ shell_client.py # Shell client
โ โโโ interactive_client.py # Interactive client
โโโ README.md # This file
๐งช Running Tests
This project uses pytest for testing. To run all tests:
make test
Or directly with pytest:
pytest
All modules in mediainspect_rtsp/ are covered by basic import tests in tests/. Extend these with functional tests as needed.
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
๐ Versioning
We use SemVer for versioning. For available versions, see the CHANGELOG.md.
๐ Security
Credential Handling
- Credentials stored in .env file
- Passwords never logged
- URL encoding for special characters
- Secure connection handling
Best Practices
- Use environment variables
- Regularly update dependencies
- Follow security advisories
- Implement proper error handling
โ Common Issues
- OpenCV Import Error
# Install system dependencies
sudo ./install_opencv.sh
- RTSP Connection Failed
- Verify credentials
- Check network connectivity
- Confirm stream availability
- Performance Issues
- Adjust buffer size
- Modify processing parameters
- Check system resources
๐ Performance Tuning
Memory Usage
# Configure buffer size
client = RTSPClient(buffer_size=1024*1024)
Processing Speed
# Adjust processing parameters
processor = VideoProcessor(
skip_frames=2,
downscale_factor=0.5
)
๐ Documentation
๐ License
This project is licensed under the MIT License - see LICENSE file.
๐ Acknowledgments
- OpenCV community
- FFmpeg project
- Docker community
- All contributors
๐ Support
For support, please:
- Check documentation
- Search existing issues
- Create new issue if needed
๐ Changelog
See CHANGELOG.md for all changes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mediainspect_rtsp-0.1.3.tar.gz.
File metadata
- Download URL: mediainspect_rtsp-0.1.3.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.14.6-300.fc42.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b81d3357a8f827cfbc142f7dbf683a743cf11ac4ffe54fe4d0acab3187136ff
|
|
| MD5 |
e16ea647c6acbeeb6a5c35b881ee93b6
|
|
| BLAKE2b-256 |
eaa2eed3791e57fc072ec6122d7da355a50572c674a2ca58d34b5165f0ec6577
|
File details
Details for the file mediainspect_rtsp-0.1.3-py3-none-any.whl.
File metadata
- Download URL: mediainspect_rtsp-0.1.3-py3-none-any.whl
- Upload date:
- Size: 40.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.14.6-300.fc42.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1dcce46d69db8d409fa0478077135a53da74b9235987fa22690838f512ec2bd
|
|
| MD5 |
d8fedbd97c0354e3637ccd04d253d781
|
|
| BLAKE2b-256 |
1a092adcb41061740becfdabc896585c94243c498fe50153e989c930cec74b35
|