skip to Main Content

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


  1. Chosen as BEST ANSWER

    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:

    
    const config = {
        rtmp: {
          port: 1937,
          chunk_size: 60000,
          gop_cache: true,
          ping: 30,
          ping_timeout: 60,
        },
      
        relay: {
          ffmpeg: "/bin/ffmpeg",
          tasks: [
            {
              name: "XXXXX",
              app: "live",
              mode: "static",
              edge: "rtmp://rtmp_server:1935/live/test", // my other server
            },
            {
              app: "live",
              name: "XXXXX",
              mode: "push",
              edge: "rtmp://live.twitch.tv/app", // twitch server
            },
          ],
        },
      };
    

  2. Do you want to do this as bellow:

    Client -----> Nginx -------> Server
             (Stream 1/2/3)    (Stream 2)
    

    You should never let another server to read Stream 2 from Nginx, intead you should use a FFmpeg as a client to do this:

    Client -----> Nginx -----> FFmpeg  --> Server
             (Stream 1/2/3)             (Stream 2)
    

    To do this, please run command like this:

    ffmpeg -f flv -i rtmp://ip/live/stream2 -c copy -f flv rtmp://server/live/stream2
    

    So you can read any stream from Nginx to another server.

    If you want the Server to do this, you can use SRS/Ingest, which fork a FFmpeg process to pull the stream to SRS

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search