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.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS 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.
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 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 is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
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 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
- RTMP/RTMPS Push/Play
- GOP cache
Roadmap
- HTTP-API
- Authentication
- Notification
- Record and Playback
- Rtmp Proxy
Supported clients
Client | H.264 | HEVC | VP9 | AV1 |
---|---|---|---|---|
OBS_29.1+ | â | â | â | â |
FFmpeg/FFplay_6.1+ | â | â | â | â |
NodePlayer.js_1.0+ | â | â | â | â |
NodeMediaClient_3.0+ | â | â | â | â |
Usage
- obs_29.1 or above is required
- ffmpeg_6.1 or above is required
Push Streaming
ffmpeg -re -i test_265.mp4 -c copy -f flv rtmp://localhost/live/test_265
ffmpeg -re -i test_av1.mp4 -c copy -f flv http://localhost:8000/live/test_av1.flv
Play Streaming
ffplay http://localhost:8000/live/test_265.flv
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.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS 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