Skip to content

cegautreau-a11y/rstp2hls

Repository files navigation

RTSP Stream Converter

A powerful PowerShell-based solution for converting RTSP camera streams to web-compatible HLS (HTTP Live Streaming) format. This tool enables you to view multiple IP camera feeds directly in web browsers with automatic monitoring, recovery, email alerts, and a user-friendly management interface.

Version PowerShell

🌟 Features

Core Functionality

  • Multi-Camera Support: Manage and stream multiple IP cameras simultaneously
  • RTSP to HLS Conversion: Converts RTSP streams to web-compatible HLS format using FFmpeg
  • Web-Based Viewing: Stream cameras directly in any modern web browser
  • SSL/HTTPS Support: Secure streaming with Apache SSL configuration

Advanced Monitoring

  • Automatic Health Monitoring: Continuously monitors stream health and performance
  • Auto-Recovery: Automatically restarts failed streams without manual intervention
  • Real-Time Statistics: Track frame rates, memory usage, and stream quality
  • Comprehensive Logging: Detailed logs for troubleshooting and analysis

Email Alert System (NEW in v4.0.0)

  • SMTP Email Alerts: Receive email notifications when streams fail
  • Configurable Thresholds: Set restart count thresholds for alerts
  • Multi-Recipient Support: Send alerts to up to 5 email addresses
  • Smart Alert Logic: First alert on failure, final alert after 15 minutes without recovery
  • Recovery Notifications: Automatic alerts when streams recover
  • Per-Camera Alert Control: Enable/disable alerts for individual cameras

Security Enhancements (NEW in v4.0.0)

  • Password Encryption: RTSP and SMTP passwords are automatically encrypted
  • Secure Storage: Encrypted passwords stored in config.json
  • User-Specific Encryption: Passwords encrypted per Windows user account
  • Automatic Migration: Plain-text passwords automatically encrypted on first run

Configuration Management (NEW in v4.0.0)

  • Automatic Config Creation: config.json created automatically on first run
  • Configuration Validation: Comprehensive validation of all settings
  • Backward Compatibility: Automatic migration of older config formats
  • Default Values: Sensible defaults for all new configuration options

Management Interface

  • Interactive Menu System: Easy-to-use PowerShell interface for managing streams
  • Live Log Viewer: View logs from all cameras and services in real-time
  • Process Control: Start, stop, and restart individual cameras or all streams
  • Status Dashboard: Monitor all cameras and services at a glance

Performance & Reliability

  • Hardware Acceleration: NVIDIA GPU encoding support (h264_nvenc)
  • Scheduled Restarts: Automatic 24-hour restart cycle for stability
  • Log Compression: NTFS compression for efficient log storage
  • Configurable Timing: Fine-tune all delays and intervals for optimal performance

📋 Prerequisites

Required Software

  • Windows Server 2016+ or Windows 10/11
  • PowerShell 5.1 or higher
  • Administrator privileges for service management
  • NVIDIA GPU (optional, for hardware acceleration)

Required Downloads

Network Requirements

  • Access to IP cameras via RTSP protocol
  • Open ports: 80 (HTTP) and 443 (HTTPS)
  • Static IP or DNS name for the server
  • SMTP server access (optional, for email alerts)

🚀 Quick Start

1. Download and Extract

# Extract all files to a directory, e.g., C:\RTSPConverter

2. Install Dependencies

  • Install FFmpeg to C:\ffmpeg
  • Install Apache24 to C:\Apache24
  • See INSTALLATION.md for detailed instructions

3. First Run (Auto-Configuration)

NEW in v4.0.0: The script automatically creates config.json on first run!

# Run as Administrator
.\RTSPStreamConverter.ps1

The script will:

  • Create a default config.json file with all cameras disabled
  • Set up all required directories
  • Enable NTFS compression on log directories
  • Display the interactive menu

4. Configure Cameras

Edit config.json to add your camera details:

{
  "Cameras": {
    "Camera1": {
      "Name": "Front Door Camera",
      "Enabled": true,
      "RTSP": {
        "Username": "admin",
        "Password": "password",
        "IPAddress": "192.168.1.100",
        "Port": 554,
        "Suffix": "Streaming/Channels/101"
      }
    }
  }
}

Note: Passwords will be automatically encrypted on next run!

5. Configure Email Alerts (Optional)

{
  "EmailAlerts": {
    "Enabled": true,
    "SMTPServer": "smtp.gmail.com",
    "Port": 587,
    "UseSTARTTLS": true,
    "Username": "your-email@gmail.com",
    "Password": "your-app-password",
    "FromAddress": "your-email@gmail.com",
    "ToAddresses": ["admin@example.com", "alerts@example.com"],
    "RestartThreshold": 3
  }
}

6. Access Streams

Open your browser and navigate to:

  • https://your-domain.com/streaming.m3u8 (main camera)
  • https://your-domain.com/camera2/streaming.m3u8 (camera 2)
  • Or use the provided HTML viewer pages

📁 Project Structure

RTSPConverter/
├── RTSPStreamConverter.ps1    # Main PowerShell script
├── config.json                # Configuration file (auto-created)
├── httpd.conf                 # Apache main configuration
├── httpd-ssl.conf            # Apache SSL configuration
├── .htaccess                 # Access control file
├── stream.html               # Basic stream viewer
├── streamiframe.html         # Iframe-embedded viewer
├── streammobile.html         # Mobile-optimized viewer
├── streamfull.html           # Full-page viewer with title
├── README.md                 # This file
├── INSTALLATION.md           # Detailed installation guide
├── CONFIGURATION.md          # Configuration reference
├── TROUBLESHOOTING.md        # Common issues and solutions
└── RTSP-CAMERAS.md           # Camera-specific RTSP URLs

🎯 Use Cases

Home Security

  • Monitor multiple security cameras from any device
  • Receive email alerts when cameras go offline
  • Access cameras remotely via web browser
  • No need for proprietary software or apps

Business Surveillance

  • Centralized camera management for offices or retail
  • Email notifications for critical camera failures
  • Share camera feeds with authorized personnel
  • Integration with existing web infrastructure

Live Streaming

  • Stream events or locations to the web
  • Embed camera feeds in websites
  • Low-latency streaming with HLS

Remote Monitoring

  • Monitor remote locations or equipment
  • Email alerts for connection issues
  • Access cameras from anywhere with internet
  • Automatic recovery from network interruptions

🔧 Configuration

Camera Configuration

Each camera requires the following settings in config.json:

  • Name: Friendly name for the camera
  • Enabled: Set to true to activate the camera
  • RTSP Settings: Username, password, IP address, port, and URL suffix
  • HLS Settings: Bitrate, buffer size, and segment settings
  • Paths: Output directories and log file locations
  • AlertEnabled: Enable/disable email alerts for this camera (NEW)

Email Alert Configuration (NEW in v4.0.0)

Configure SMTP settings for email notifications:

  • Enabled: Enable/disable email alerts
  • SMTPServer: SMTP server address
  • Port: SMTP port (typically 587 for TLS, 465 for SSL)
  • UseSTARTTLS: Enable STARTTLS encryption
  • Username: SMTP authentication username
  • Password: SMTP authentication password (auto-encrypted)
  • FromAddress: Sender email address
  • ToAddresses: Array of up to 5 recipient addresses
  • RestartThreshold: Number of restarts before sending alert
  • EmailTimeoutSeconds: Timeout for email sending (default: 30)
  • RestartWindowMinutes: Time window for counting restarts (default: 5)
  • FinalAlertDelayMinutes: Delay before final alert (default: 15)
  • RecoveryStableMinutes: Stability period before recovery alert (default: 1)

Timing Configuration (NEW in v4.0.0)

Fine-tune all timing parameters:

"Timing": {
  "ProcessStartDelaySeconds": 2,
  "ProcessStopDelaySeconds": 2,
  "RestartDelaySeconds": 3,
  "WindowOpenDelayMilliseconds": 500,
  "ShortDelayMilliseconds": 100,
  "MonitoringLoopDelaySeconds": 1
}

FFmpeg Configuration (NEW in v4.0.0)

Global FFmpeg settings:

"FFmpeg": {
  "RTSPTransport": "tcp",
  "RTSPFlags": "prefer_tcp",
  "RTSPTimeoutMicroseconds": 5000000,
  "VideoCodec": "h264",
  "HLSSegmentTimeSeconds": 2,
  "HLSAllowCache": 0,
  "HLSFlags": "delete_segments"
}

Apache Configuration

Two configuration files need to be edited:

httpd.conf (C:\Apache24\conf\httpd.conf):

  • ServerAdmin: Your email address
  • ServerName: Your domain name

httpd-ssl.conf (C:\Apache24\conf\extras\httpd-ssl.conf):

  • ServerName: Your domain name with port
  • ServerAdmin: Your email address
  • SSLCertificateFile: Path to SSL certificate
  • SSLCertificateKeyFile: Path to SSL private key
  • SSLCertificateChainFile: Path to SSL chain file

HTML Viewer Configuration

Edit the HTML viewer files to point to your camera streams:

<source type="application/x-mpegURL" src="https://your-domain.com/streaming.m3u8">

Replace domain.ca with your actual domain or IP address.

📊 Monitoring and Management

Interactive Menu

The script provides an interactive menu with the following options:

  1. Start All Streams: Start Apache and all enabled cameras
  2. Stop All Streams: Stop all processes gracefully
  3. Restart All Streams: Restart everything
  4. View Status: Display current status of all services
  5. Open Log Viewer: View logs in real-time
  6. Configure Settings: Configure most settings for the script

Log Files

Logs are stored in C:\ffmpeg\logs\ and include:

  • Main script log: rtsp_converter_YYYYMMDD.log
  • Camera FFmpeg logs: ffmpeg_camera1_error.txt
  • Apache access log: C:\Apache24\logs\ssl\access.log

Statistics Tracking

The script monitors:

  • Frame rate for each camera
  • Memory usage per process
  • Stream health status
  • Uptime and restart counts
  • Email alert status

🔐 Security Considerations

Password Encryption (NEW in v4.0.0)

  • All passwords are automatically encrypted on first run
  • Encryption is user-specific (tied to Windows user account)
  • Encrypted passwords stored in config.json
  • Plain-text passwords automatically migrated to encrypted format

SSL/HTTPS

  • Always use HTTPS for production deployments
  • Obtain valid SSL certificates (Let's Encrypt, commercial CA)
  • Configure firewall rules to restrict access

Access Control

  • Use strong passwords for camera RTSP authentication
  • Implement Apache authentication for web access
  • Use .htaccess files to control access to streams
  • Secure SMTP credentials with encryption

Network Security

  • Place cameras on isolated VLAN
  • Use VPN for remote access
  • Regularly update Apache and FFmpeg
  • Monitor email alerts for security issues

🐛 Troubleshooting

Common Issues

Stream not loading in browser:

  • Check if Apache is running
  • Verify FFmpeg process is active
  • Check firewall settings
  • Review FFmpeg error logs

FFmpeg keeps restarting:

  • Verify RTSP URL is correct
  • Check camera credentials
  • Ensure camera is accessible on network
  • Review camera-specific RTSP suffix
  • Check email alerts for detailed error information

Email alerts not working:

  • Verify SMTP server settings
  • Check SMTP credentials
  • Ensure port 587/465 is not blocked
  • Review email timeout settings
  • Check ToAddresses are valid

High CPU/Memory usage:

  • Reduce bitrate in camera configuration
  • Disable hardware acceleration if causing issues
  • Limit number of concurrent streams
  • Adjust monitoring intervals

For detailed troubleshooting, see TROUBLESHOOTING.md

📚 Additional Documentation

🆕 What's New in Version 4.0.0

Major Features

  • Email Alert System: Comprehensive SMTP-based alerting for stream failures
  • Password Encryption: Automatic encryption of all sensitive credentials
  • Configuration Validation: Validates all settings on startup
  • Auto-Configuration: Creates default config.json automatically
  • Enhanced Timing Control: Fine-tune all delays and intervals
  • FFmpeg Global Settings: Centralized FFmpeg configuration

Improvements

  • Smarter alert logic with first and final notifications
  • Recovery alerts when streams stabilize
  • Per-camera alert enable/disable
  • Backward compatibility with v3.x configurations
  • Enhanced startup monitoring
  • Better error handling and logging

Removed Features

  • Automatic log archive cleanup (removed per user request)

👏 Credits

  • Christopher McGrath

🔗 Related Projects

⚠️ Disclaimer

This software is provided "as is" without warranty of any kind. Use at your own risk. Always ensure you have permission to access and stream from IP cameras.


Version: 4.0.0
Last Updated: 2025-10-10
Minimum PowerShell Version: 5.1
Tested On: Windows Server 2019, Windows 10/11