rtsp://localhost:8554/stream
RTAP is a system for handling and processing live video streams over RTSP/RTMP. The project comprises a server that manages video stream ingestion, conversion, and distribution (via WebSocket) as well as client-side utilities. It integrates FFmpeg for media processing and uses Node.js with Express and WebSocket for stream handling and performance monitoring.
RTAP is designed to:
- Receive live video streams via RTSP/RTMP protocols
- Process streams using FFmpeg with options that optimize low latency and real-time performance
- Distribute processed video data over WebSocket connections to clients
- Monitor stream performance, log errors, and attempt automatic reconnections in case of failures
- Serve as a base for further modular development, improved error management, and enhanced security features
- Implements an Express HTTP server along with a WebSocket server
- Uses FFmpeg via the node-rtsp-stream package to ingest and re-encode video streams
- Contains error handling and reconnection logic – including switching between TCP and UDP transport
- Monitors performance and logs detailed stream data and errors using Winston
- Includes client-side code to connect to the RTSP/RTMP streams
- The test2/client.js connects via WebSocket, receives video frames, and then processes these frames (e.g., by extracting text via OCR with Tesseract)
- The webm module's README includes instructions on how to generate and play back WebM streams created by FFmpeg
- FFmpeg is used to probe and convert streams while providing low-latency and quality options
- The configuration options are customizable and allow switching network protocols on error
- Future refactoring will modularize the FFmpeg logic into a separate module
- Winston is used to log server activity (errors, stream stats, HTTP request details, etc.)
- The server gathers performance metrics (active streams, memory usage, etc.) and prints periodic stats
- Enhanced logging is planned with more detailed error and performance alerts
- Node.js (v12+ recommended)
- FFmpeg installed on your system and available on the command line
- (Optional) ffprobe for stream probing
- Clone the Repository:
git clone https://github.com/rtap/www.git
- Navigate to the project folder:
cd www
- Install dependencies:
npm install
- Configure environment (optional):
- Copy the example .env file and adjust settings as needed:
cp .env.example .env
- Adjust port and other parameters if necessary
- Copy the example .env file and adjust settings as needed:
- For development, simply launch:
npm start
- The server will start on port 5001 (or a port defined in your configuration) and serve HTTP endpoints along with WebSocket connections for stream distribution
- The main server (server.js) listens for RTSP stream setup requests from clients
- Clients can send a JSON-formatted message of type "SETUP" via a WebSocket connection with the RTSP URL
- Once the stream is successfully initialized (with FFmpeg handling), the server returns stream configuration information (e.g., the WebSocket endpoint and stream port)
- Additional commands such as "STOP" are implemented to halt streams and free up resources
The project includes scripts to generate test streams that can be used for development and testing:
-
RTSP Stream Setup:
-
Quick Start (Automated):
./start_rtsp_stream.sh
This script automatically installs the RTSP server if needed, starts it, and generates a test pattern stream at
rtsp://localhost:8554/stream
. -
Manual Setup:
- Install and configure the RTSP server:
./install_rtsp_server.sh
- Start the RTSP server:
mediamtx
- In a separate terminal, generate the RTSP stream:
This interactive script allows you to choose between a test pattern, a video file, or a webcam as the stream source.
./generate_rtsp_stream.sh
- Install and configure the RTSP server:
-
-
RTMP/HLS Stream Generation:
./generate_stream.sh
This versatile script allows you to:
- Generate either RTMP or HLS streams
- Choose between test patterns, video files, or webcam as sources
- Stream directly to the server for processing
The script provides interactive prompts to select your preferred stream type and source.
-
Testing Streams:
- For RTSP streams:
ffplay rtsp://localhost:8554/stream
- For RTMP streams:
ffplay rtmp://localhost:1935/live/stream
- For HLS streams:
ffplay http://localhost:8080/hls/stream.m3u8
You can also connect to these streams using the RTAP server by configuring the appropriate URL in your client application.
- For RTSP streams:
- All basic configuration constants (like FFmpeg options) are contained in the server file
- Future work will move configuration to separate external files and support environment variables
- Adjust logging levels and connection time-out parameters based on your deployment needs
The project roadmap calls for these enhancements:
- Separate FFmpeg handling into its own module/class
- Create dedicated modules for stream management and performance monitoring
- Implement more detailed exception handling with retries and timeouts
- Improve reconnection strategies for unstable RTSP connections
- Add JSDoc comments to all classes and methods
- Develop a complete API documentation with usage examples
- Add authentication for WebSocket connections
- Validate input data to prevent malformed requests and DoS attacks
- Implement unit tests and integration tests
- Add performance testing to monitor system load and reliability
- Ensure proper termination of FFmpeg processes
- Implement mechanisms to clean up temporary files and manage resource limits
- Expand logging system and implement performance metrics
- Create alerts for critical errors in production environments
Contributions are welcome! Please feel free to open issues or submit pull requests for improvements, new features, or bug fixes. Ensure that you follow code documentation standards (using JSDoc where applicable) and adapt tests to cover any code changes.
To ensure the security of the application:
-
Regularly update dependencies:
npm update
-
Check for vulnerabilities:
npm audit
-
Fix vulnerabilities when found:
npm audit fix
-
For vulnerabilities that cannot be fixed automatically:
npm audit fix --force
Note: Use
--force
with caution as it may introduce breaking changes.
The project is regularly maintained to address security vulnerabilities in dependencies.
This project is licensed under the ISC License. See the LICENSE file for details.