Node.js RTSP Stream Proxy & WebSocket Broadcast Tutorial
Ingest RTSP streams in Node.js using FFmpeg subprocesses and relay MPEG-TS frames to browser clients via WebSockets.
Need a live RTSP stream link right now to test this setup in VLC or OpenCV?
#1Node.js FFmpeg RTSP Child Process
Spawn an FFmpeg process in Node.js to read RTSP over TCP and write MPEG-TS chunks directly to a WebSocket server:
const { spawn } = require('child_process');
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
const ffmpeg = spawn('ffmpeg', [
'-rtsp_transport', 'tcp',
'-i', 'rtsp://rtsplink.com/live/test?token=demo',
'-f', 'mpegts',
'-codec:v', 'mpeg1video',
'-b:v', '1000k',
'-r', '30',
'-'
]);
ffmpeg.stdout.on('data', (chunk) => {
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) client.send(chunk);
});
});
console.log('RTSP WebSocket broadcast proxy listening on ws://localhost:8080');Ready to test your live RTSP video stream?
Generate free authenticated RTSP links with unlimited bandwidth and inspect frame timestamps in seconds.
Related Tutorials & Setup Guides
View all 100+ guidesZero-Plugin HTML5 Canvas JSMPEG RTSP Video Player Guide
Learn how to integrate JSMPEG into vanilla JavaScript and React applications for low-latency video streaming without HLS delay.
codeHigh-Performance Python OpenCV RTSP Video Capture Tutorial
Master low-latency RTSP video ingestion in Python OpenCV. Avoid image tearing, fix frame buffer lag, and implement robust reconnect loops.
codeZero-Copy RTSP Video Ingestion with Python PyAV & PyTorch
Learn how to use Python PyAV bindings for low-overhead RTSP video decoding and direct tensor ingestion for PyTorch models.