Back to All Guides
codeAugust 16, 20267 min readRTSPLink Dev Team

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.

#Node.js#WebSockets#FFmpeg#JSMPEG#TypeScript
Live Stream Workbench

Need a live RTSP stream link right now to test this setup in VLC or OpenCV?

Test Live Stream

#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:

Node.js WebSocket RTSP 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.

Generate Free RTSP Link

Related Tutorials & Setup Guides

View all 100+ guides