Introduction
Mediasoup is a WebRTC Selective Forwarding Unit (SFU) library for Node.js with a high-performance C++ media worker, recently rewritten in Rust. It routes media streams between participants without mixing or transcoding, enabling low-latency group video calls, live streaming, and broadcasting at scale.
What Mediasoup Does
- Routes audio and video streams between WebRTC peers via selective forwarding (no transcoding)
- Manages multiple workers, routers, and transports for horizontal scaling
- Supports simulcast and SVC so clients receive the quality layer matching their bandwidth
- Provides producer-consumer architecture for flexible media routing topologies
- Handles DTLS, ICE, RTP/RTCP, and SCTP protocols internally
Architecture Overview
Mediasoup runs a Node.js control plane that spawns native worker processes (C++ or Rust) for media handling. Each worker manages one or more routers, which define media routing scopes. Transports (WebRTC, plain RTP, or pipe) connect external endpoints to routers. Producers publish media into a router, and consumers subscribe to it. The worker handles all packet forwarding at near-kernel speed while the Node.js layer manages signaling logic and room orchestration. Inter-worker pipe transports enable multi-worker scaling on multi-core machines.
Self-Hosting & Configuration
- Install via npm; the native worker compiles automatically during installation
- Configure worker settings including RTC port ranges, log levels, and DTLS certificates
- Set media codecs per router to control which audio and video formats are negotiated
- Use plain RTP transports for integration with recording servers or external media processors
- Deploy behind a TURN server for NAT traversal in restrictive network environments
Key Features
- Near-zero latency forwarding without CPU-intensive transcoding or mixing
- Simulcast and SVC layer selection for adaptive bitrate delivery
- Multi-worker architecture scales across all CPU cores on a single machine
- Protocol-level flexibility with WebRTC, plain RTP, and pipe transport types
- Active protocol compliance tracking with regular updates for new WebRTC standards
Comparison with Similar Tools
- Janus — a C-based gateway with plugin architecture; Mediasoup is a library you embed into your Node.js application
- Pion — Go WebRTC building blocks; Mediasoup provides a higher-level SFU abstraction
- LiveKit — a turnkey SFU server; Mediasoup gives more control but requires building your own signaling
- Kurento — MCU-style media server with transcoding; Mediasoup is SFU-only for lower latency
- Ion SFU — a Go-based SFU built on Pion; Mediasoup's C++/Rust worker offers different performance characteristics
FAQ
Q: Does Mediasoup transcode video? A: No. It is a pure SFU that forwards packets without decoding. For transcoding, pipe media to an external processor like FFmpeg.
Q: How many participants can a single server handle? A: Depends on bandwidth and media settings. A typical server handles hundreds of participants in SFU mode since CPU load is minimal.
Q: Is there a client-side library? A: Yes. mediasoup-client for browsers and libmediasoupclient for native C++ applications handle the client-side WebRTC interaction.
Q: Can I record streams? A: Yes, by creating a plain RTP consumer and piping the stream to a recording tool like GStreamer or FFmpeg.