Top Related Projects
SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181, with codec support for H.264, H.265, AV1, VP9, AAC, Opus, and G.711.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
Ant Media Server — Ultra-low latency streaming engine with WebRTC (~0.5s), SRT, RTMP, HLS, CMAF, adaptive bitrate, transcoding & scaling
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
Secure, Reliable, Transport
Quick Overview
Node-Media-Server is an open-source Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH media server. It provides a lightweight and efficient solution for streaming live audio and video content over various protocols, making it suitable for building live streaming applications and services.
Pros
- Easy to set up and use with minimal configuration
- Supports multiple streaming protocols (RTMP, HTTP-FLV, WebSocket-FLV, HLS, DASH)
- Lightweight and efficient, suitable for both small and large-scale deployments
- Active development and community support
Cons
- Limited documentation, especially for advanced features
- May require additional components for a complete streaming solution (e.g., front-end player)
- Performance may vary depending on the specific use case and server resources
- Some features may require additional configuration or plugins
Code Examples
- Basic server setup:
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 30,
ping_timeout: 60
},
http: {
port: 8000,
allow_origin: '*'
}
};
var nms = new NodeMediaServer(config)
nms.run();
- Adding authentication:
const config = {
// ... other config options
auth: {
play: true,
publish: true,
secret: 'nodemedia2017privatekey'
}
};
nms.on('prePublish', (id, StreamPath, args) => {
let session = nms.getSession(id);
let username = args.username;
let password = args.password;
if (username !== 'admin' || password !== 'secret') {
session.reject();
}
});
- Handling events:
nms.on('postPublish', (id, StreamPath, args) => {
console.log('[NodeEvent on postPublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.on('donePublish', (id, StreamPath, args) => {
console.log('[NodeEvent on donePublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
Getting Started
-
Install Node-Media-Server:
npm install node-media-server -
Create a new JavaScript file (e.g.,
app.js) and add the following code:const NodeMediaServer = require('node-media-server'); const config = { rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 }, http: { port: 8000, allow_origin: '*' } }; var nms = new NodeMediaServer(config) nms.run(); -
Run the server:
node app.js -
The server is now running and ready to accept RTMP streams on port 1935 and serve HTTP-FLV streams on port 8000.
Competitor Comparisons
SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181, with codec support for H.264, H.265, AV1, VP9, AAC, Opus, and G.711.
Pros of SRS
- Written in C++, offering better performance and lower resource usage
- Supports a wider range of protocols, including RTMP, HLS, WebRTC, and SRT
- More extensive documentation and active community support
Cons of SRS
- Steeper learning curve due to C++ codebase
- Less straightforward to extend or modify compared to Node.js-based solutions
- May require more complex deployment and configuration
Code Comparison
SRS (C++):
SrsRtmpConn* conn = new SrsRtmpConn(this, skt, ip);
if ((err = conn->start()) != srs_success) {
srs_freep(conn);
return srs_error_wrap(err, "start conn");
}
Node-Media-Server (JavaScript):
let session = new NodeRtmpSession(config, socket);
session.run();
SRS offers more granular control and error handling, while Node-Media-Server provides a simpler, more concise API. The C++ code in SRS may be more efficient but requires more careful memory management. Node-Media-Server's JavaScript implementation is easier to read and modify but may not achieve the same level of performance as SRS.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
Pros of mediamtx
- Written in Go, offering better performance and lower resource usage
- Supports more protocols, including WebRTC and SRT
- More actively maintained with frequent updates
Cons of mediamtx
- Less mature project with potentially fewer community resources
- May have a steeper learning curve for JavaScript developers
Code Comparison
Node-Media-Server (JavaScript):
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 },
http: { port: 8000, allow_origin: '*' }
};
var nms = new NodeMediaServer(config);
nms.run();
mediamtx (Go):
package main
import "github.com/bluenviron/mediamtx/mediamtx"
func main() {
mediamtx.Run()
}
Summary
Both Node-Media-Server and mediamtx are media streaming servers, but they differ in implementation and features. Node-Media-Server is JavaScript-based and may be more familiar to web developers, while mediamtx is written in Go, offering potentially better performance. mediamtx supports more protocols and is more actively maintained, but it might have a steeper learning curve for those not familiar with Go. The choice between the two depends on specific project requirements, performance needs, and developer expertise.
Ant Media Server — Ultra-low latency streaming engine with WebRTC (~0.5s), SRT, RTMP, HLS, CMAF, adaptive bitrate, transcoding & scaling
Pros of Ant-Media-Server
- More comprehensive feature set, including WebRTC support and adaptive bitrate streaming
- Better scalability for enterprise-level applications
- Active development with frequent updates and community support
Cons of Ant-Media-Server
- Steeper learning curve due to its complexity
- Requires more system resources compared to Node-Media-Server
- Some advanced features are only available in the paid Enterprise Edition
Code Comparison
Ant-Media-Server (Java):
@RestController
public class StreamsSourceRestService {
@GetMapping("/streams/{streamId}")
public ResponseEntity<?>getStream(@PathVariable String streamId) {
// Implementation
}
}
Node-Media-Server (JavaScript):
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 },
http: { port: 8000, allow_origin: '*' }
};
var nms = new NodeMediaServer(config);
nms.run();
Both servers provide APIs for stream management, but Ant-Media-Server offers a more structured, Java-based approach with RESTful endpoints. Node-Media-Server uses a simpler JavaScript configuration and setup process, making it easier to get started for developers familiar with Node.js. Ant-Media-Server's code structure reflects its more extensive feature set, while Node-Media-Server focuses on simplicity and ease of use.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
Pros of mediamtx
- Written in Go, offering better performance and lower resource usage
- Supports more protocols, including WebRTC and SRT
- More actively maintained with frequent updates
Cons of mediamtx
- Less mature project with potentially fewer community resources
- May have a steeper learning curve for JavaScript developers
Code Comparison
Node-Media-Server (JavaScript):
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 },
http: { port: 8000, allow_origin: '*' }
};
var nms = new NodeMediaServer(config);
nms.run();
mediamtx (Go):
package main
import "github.com/bluenviron/mediamtx/mediamtx"
func main() {
mediamtx.Run()
}
Summary
Both Node-Media-Server and mediamtx are media streaming servers, but they differ in implementation and features. Node-Media-Server is JavaScript-based and may be more familiar to web developers, while mediamtx is written in Go, offering potentially better performance. mediamtx supports more protocols and is more actively maintained, but it might have a steeper learning curve for those not familiar with Go. The choice between the two depends on specific project requirements, performance needs, and developer expertise.
RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
Pros of media-server
- Written in C++, potentially offering better performance for resource-intensive tasks
- Supports a wider range of protocols, including RTMP, RTSP, RTP, and HLS
- More comprehensive media handling capabilities, including transcoding and adaptive streaming
Cons of media-server
- Less active community and fewer contributors compared to Node-Media-Server
- May require more complex setup and configuration due to its C++ nature
- Limited documentation and examples available, which could make it harder for beginners
Code Comparison
Node-Media-Server (JavaScript):
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 },
http: { port: 8000, allow_origin: '*' }
};
var nms = new NodeMediaServer(config);
nms.run();
media-server (C++):
#include "media-server.h"
int main(int argc, char* argv[])
{
media_server_t* server = media_server_create(NULL);
media_server_run(server);
media_server_destroy(server);
return 0;
}
Both examples show basic server setup and initialization, but media-server's C++ implementation may require additional configuration and setup not shown in this simplified example.
Secure, Reliable, Transport
Pros of SRT
- Designed for low-latency streaming over unreliable networks
- Supports encryption and forward error correction
- Widely adopted in professional broadcasting industry
Cons of SRT
- More complex to set up and configure
- Primarily focused on transport protocol, not a full media server solution
- May require additional components for complete streaming infrastructure
Code Comparison
SRT (C++):
srt_startup();
SRTSOCKET sock = srt_create_socket();
srt_connect(sock, "127.0.0.1", 9000, 1000);
srt_send(sock, buffer, len);
srt_close(sock);
srt_cleanup();
Node-Media-Server (JavaScript):
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 },
http: { port: 8000, allow_origin: '*' }
};
var nms = new NodeMediaServer(config);
nms.run();
Node-Media-Server is a more comprehensive media server solution written in JavaScript, offering easier setup for web developers. It provides RTMP and HTTP-FLV streaming out of the box. SRT, on the other hand, is a C++ library focused on reliable, low-latency transport protocol, which can be integrated into various streaming solutions but requires more setup and additional components for a complete streaming system.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Node-Media-Server v4
Introduction
Node-Media-Server is a high-performance/low-latency/open-source Live Streaming Server developed based on Nodejs.
v4 is design to implement enhanced RTMP FLV v1 support for native HEVC, VP9, AV1.
v4 is no longer compatible with the cn_cdn extension id flv_265 standard.
v4 is no longer compatible with flashplayer's rtmp protocol.
v4 is incompatible with v2. Do not upgrade across major versions.
Installation
npm install node-media-server -g
or run directly
npx node-media-server
Features
- HTTP/HTTP2-flv Push/Play
- WS/WSS-flv Push/Play
- RTMP/RTMPS Push/Play
- GOP cache
- Notification
- Authentication
- Static file server
- Record to flv file
- REST API System (New in v4.2.0)
- JWT-based Authentication (New in v4.2.0)
- Real-time Monitoring & Statistics (New in v4.2.0)
- Session Management (New in v4.2.0)
- Session Deletion (New in v4.2.0)
- Advanced Health Monitoring (New in v4.2.0)
Static file services
Node-Media-Server can provide static file services for a directory.
"static": {
"router": "/",
"root": "./html"
}
Record to flv file
Node-Media-Server can record live streams as FLV files.
When the static file server is enabled and recordings are saved in its directory.
It can provide video-on-demand services.
"record": {
"path": "./html/record"
}
http://server_ip:8000/record/live/stream/unix_time.flv
or
https://server_ip:8443/record/live/stream/unix_time.flv
REST API System (New in v4.2.0)
Node-Media-Server v4.2.0 introduces a comprehensive REST API system for server management and monitoring.
Authentication
The API system uses JWT-based authentication with the following endpoints:
Login
POST /api/v1/login
Content-Type: application/json
{
"username": "your_username",
"password": "your_password"
}
Response:
{
"success": true,
"data": {
"token": "your_jwt_token",
"expiresIn": "24h"
},
"message": "Login successful"
}
Using the API
Include the JWT token in your requests:
Authorization: Bearer your_jwt_token
API Endpoints
Health Check
GET /api/v1/health
Returns server health status, including CPU usage, memory consumption, and uptime.
Server Information
GET /api/v1/info
Returns server configuration, version information, and system details.
Stream Management
GET /api/v1/streams
List all active streams with detailed information including codecs, bitrate, and connected clients.
Session Management
GET /api/v1/sessions
Monitor all connected clients (publishers and players) with session details.
DELETE /api/v1/sessions/{sessionId}
Terminate a specific session by ID. This will disconnect the associated client and stop their stream or playback.
Response:
{
"success": true,
"data": {
"id": "sessionId",
}
"message": "Session deleted successfully",
}
Server Statistics
GET /api/v1/stats
Real-time server performance metrics including:
- CPU usage percentage
- Memory consumption (RSS, heap total, heap used)
- Process uptime
- Active stream count
- Connected client count
Configuration
The API system is configured through the bin/config.json file:
"auth": {
"play": false,
"publish": false,
"secret": "nodemedia2017privatekey",
"jwt": {
"expiresIn": "24h",
"refreshExpiresIn": "7d",
"algorithm": "HS256",
"users": [
{
"username": "admin",
"password": "admin123"
}
]
}
},
Security Features
Password Hashing
Passwords are securely stored using MD5 hashing. To generate a hashed password:
const crypto = require('crypto');
const hashedPassword = crypto.createHash('md5').update('your_password').digest('hex');
JWT Configuration
- Configurable secret key for token signing
- Support for different algorithms (HS256, HS384, HS512)
- Configurable token expiration times
- Refresh token support for extended sessions
Example Usage
Using curl
# Login
curl -X POST http://localhost:8001/api/v1/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password": md5("password")}'
# Get server stats
curl -X GET http://localhost:8001/api/v1/stats \
-H "Authorization: Bearer your_jwt_token"
# Get active streams
curl -X GET http://localhost:8001/api/v1/streams \
-H "Authorization: Bearer your_jwt_token"
# Get all sessions
curl -X GET http://localhost:8001/api/v1/sessions \
-H "Authorization: Bearer your_jwt_token"
# Delete a specific session
curl -X DELETE http://localhost:8001/api/v1/sessions/abc123-def456-ghi789 \
-H "Authorization: Bearer your_jwt_token"
Using JavaScript
// Login and get streams
const response = await fetch('http://localhost:8001/api/v1/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'admin', password: md5('password') })
});
const { token } = await response.json();
// Get streams
const streamsResponse = await fetch('http://localhost:8001/api/v1/streams', {
headers: { 'Authorization': `Bearer ${token}` }
});
const streams = await streamsResponse.json();
console.log('Active streams:', streams);
// Get all sessions
const sessionsResponse = await fetch('http://localhost:8001/api/v1/sessions', {
headers: { 'Authorization': `Bearer ${token}` }
});
const sessions = await sessionsResponse.json();
console.log('Active sessions:', sessions);
// Delete a specific session
if (sessions.length > 0) {
const sessionIdToDelete = sessions[0].id; // Get first session ID
const deleteResponse = await fetch(`http://localhost:8001/api/v1/sessions/${sessionIdToDelete}`, {
method: 'DELETE',
headers: { 'Authorization': `Bearer ${token}` }
});
const deleteResult = await deleteResponse.json();
console.log('Session deletion result:', deleteResult);
}
Supported clients
| Client | H.264 | HEVC | VP9 | AV1 |
|---|---|---|---|---|
| OBS_29.1+ | â | â | â | â |
| FFmpeg/FFplay_6.1+ | â | â | â | â |
| NodePlayer.js_1.0+ | â | â | â | â |
| NodeMediaClient_3.0+ | â | â | â | â |
QLive
Free Android Live Streaming App
NodePlayer.js pure javascript implementation live streaming player
- ASM.js, WASM, SIMD, WebWorker, WebCodecs, MediaSource multiple technical implementations
- H.264/H.265+AAC/G711 software and hardware decoder
- Ultra-low latency, Under extreme conditions less than 100 milliseconds
- Enhanced HTTP/WS-FLV Protocol, Natively support h.265
- Android/iOS/HarmonyOS/Chrome/Edge/Firefox/Safari, All modern browsers or platforms
NodePublisher.js pure javascript implementation live streaming publisher
- WebSocket-FLV Protocol
- H.264+AAC hardware encoder
- Only chrome or chromium based browsers are supported at the moment
- wss is required
NodeMediaClient-iOS iOS live streaming player and publisher SDK
- Objective-C/Swift
- RTMP/HTTP-FLV/RTSP
- H.264/H.265+AAC/OPUS/G711
- Ultra-low latency, Under extreme conditions less than 100 milliseconds
- Enhanced RTMP/FLV Protocol, Natively support H.265/OPUS
- Built-in beauty filter
NodeMediaClient-Android Android live streaming player and publisher SDK
- JAVA/Kotlin
- armv7/arm64/x86/x86_64
- RTMP/HTTP-FLV/RTSP
- H.264/H.265+AAC/OPUS/G711
- Ultra-low latency, Under extreme conditions less than 100 milliseconds
- Enhanced RTMP/FLV Protocol, Natively support H.265/OPUS
- Built-in beauty filter
expo-nodemediaclient Expo module for NodeMediaClient
- iOS and Android
- player and publisher
License
Apache 2.0
Top Related Projects
SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181, with codec support for H.264, H.265, AV1, VP9, AAC, Opus, and G.711.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
Ant Media Server — Ultra-low latency streaming engine with WebRTC (~0.5s), SRT, RTMP, HLS, CMAF, adaptive bitrate, transcoding & scaling
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS / MPEG-TS / RTP media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
Secure, Reliable, Transport
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot