I have been working on a project where I need to be able to push dynamically to 2 or 3 other channels. I tested a couple of scenarios, my last attempt is as following:
Stream Server
worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
application live {
live on;
hls on;
hls_path /www/tmp/hls;
hls_fragment 10s; # default is 5s
hls_playlist_length 5m; # default is 30s
# once playlist length is reached it deletes the oldest fragments
# authentication
# on_publish => some other server
# on_done => some other server
}
}
}
http {
server {
listen 8080;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
application/octet-stream ts;
}
root /www/tmp;
add_header Cache-Control no-cache;
# To avoid issues with cross-domain HTTP requests (e.g. during development)
add_header Access-Control-Allow-Origin *;
}
}
}
and then force another server to read from the hls content created by this server. I tried with node-media-server and nginx but neither had a real solution on this, here is my attempt on the nginx one:
events {}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# ping 30s;
# notify_method get;
# This application is to accept incoming stream
application live {
live on; # Allows live input
deny play all; # disable consuming the stream from nginx as rtmp
hls on; # Enable HTTP Live Streaming
hls_fragment 3;
hls_playlist_length 10;
hls_path /www/tmp/hls; # hls fragments path
# MPEG-DASH
dash on;
dash_path /mnt/dash/; # dash fragments path
dash_fragment 3;
dash_playlist_length 10;
push => another rtmp server;
}
}
}
http {
server {
listen 8080;
location / {
root /www;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
application/octet-stream ts;
}
root /tmp;
add_header Cache-Control no-cache;
# To avoid issues with cross-domain HTTP requests (e.g. during development)
add_header Access-Control-Allow-Origin *;
}
}
}
If you know any other options please let me know or have any other suggestions, thank you
2
Answers
The solution mentioned above by @Winlin for Nginx will work, and since the question was about Nginx I marked that as the approved answer,
In general the ffmpeg is the key, I also tried with Node-Media-Server and there ffmpeg was the recommended way.
Link to the package: https://github.com/illuspas/Node-Media-Server
Sample configuration for my setup:
Do you want to do this as bellow:
You should never let another server to read
Stream 2
from Nginx, intead you should use aFFmpeg
as a client to do this:To do this, please run command like this:
So you can read any stream from Nginx to another server.