Stream multiple RTMP IP Cameras with OBS and ffmpeg

1

I created a streaming server using Nginx and the RMTP module on a VPS running CentOS 7. I am trying to stream multiple IP cameras using OBS for broadcasting the stream. My question is how to create multiple m3u8 stream files for each camera, using different applications in the nginx.conf file. I tried using multiple instances of OBS in order to achieve that, but i am running out of CPU power. What i found is by using ffmpeg there is a way to stream multiple streams but i don't know the commands. My nginx.conf is the following:

    # RTMP configuration
    rtmp {


        server {
            listen 1935; # Listen on standard RTMP port
            chunk_size 4000;

    # Define the Application
            application camera1 {
                live on;
                exec ffmpeg -i rtmp://123.123.123.123/folder/$name -vcodec libx264 -vprofile
                baseline -x264opts keyint=40 -acodec aac -strict -2 -f flv rtmp://123.123.123.123/hls/$name;



                # Turn on HLS
                hls on;
                hls_path /mnt/hls/camera1;
                hls_fragment 3s;
                hls_playlist_length 60s;
                # disable consuming the stream from nginx as rtmp
                # deny play all;
            }


            application camera2 {
                live on;
                exec ffmpeg -i rtmp://123.123.123.123./$app/$name -vcodec libx264 -vprofile
                baseline -x264opts keyint=40 -acodec aac -strict -2 -f flv rtmp://123.123.1231.23/hls/$name;
                # Turn on HLS
                hls on;
                hls_path /mnt/hls/camera2;
                hls_fragment 3s;
                hls_playlist_length 60s;
                # disable consuming the stream from nginx as rtmp
                # deny play all;
            }
http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    server_tokens off;
    aio on;
    directio 512;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;


    server {
        listen 80;
        server_name  123.123.123.123;

        location / {

        root /var/www/html;
        index  index.html index.htm;
        }

        location /hls {
            # Disable cache
            add_header 'Cache-Control' 'no-cache';

            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length';

            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }

            types {
                application/dash+xml mpd;
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

            root /mnt/;
        }
    }
}

Using 2 instances of OBS with different stream name i was able to stream 2 cameras simultaneously but i want to stream over 50 cameras and with this method it is impossible. I think it could be done with ffmpeg. The format of the RTSP streams are rtsp://username:password@hostname:port but i want a little help with the commands. Any help would be appreciated. Thanks in advance.

Nck80

Posted 2020-02-15T23:15:15.337

Reputation: 11

No answers