2

Our Approach

Set up ngnix rtmp webserver on AWS EC ubuntu 16.04. Successfully completed single client(RPi Camera) streaming. Now we want to send multiple Pi Cameras live Feed on this server which will be displayed on the Android client app.

Problem we are facing

We are not able to stream multiple Pi cameras with different raspberry pi 3 on nginx rtmp server. We are not able to detach camera websocket when it's not in use(When camera streaming is closed).We want to assign this available websocket to another camera which has to make a new connection request for streaming upon nginx webserver.

Our Expectations

We want to setup nginx rtmp server with multiple clients (Raspberry Pi /Android APP user) at the same time.

Our Setup

Our setup configuration file on linux based nginx rtmp server is as mentioned below:-

Server Side

#user  nobody;
worker_processes  1;

error_log  logs/rtmp_error.log debug;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
      keepalive_timeout 60s;
      server {
        listen       80;
        server_name  0.0.0.0;
         location /stat.xsl {
                  root /var/www/;
               }
        location /rtmpstat {
             rtmp_stat all;
             rtmp_stat_stylesheet stat.xsl;
         }
    }
}

rtmp {
      server {
                listen 1935;
                buflen 1ms;
                application 000000002c23b846 {
                         live on;
                }
                application LaoD6Ga59p3qvCTRR5D {
                         live on;
                }
                #next
      }
}

Client Side

    #!/bin/sh

    YELLOW='\033[1;33m'
    RED='\033[0;31m'
    SET='\033[0m'
    echo "${RED}RTMP${SET}"
    echo "${RED}RESOLUTION ${SET}"
    read size
    else
       sudo ssh -i camera_nginx.pem [email protected] "sed -r -i 's|#next|\t\tapplication $1 {\
                           \n\t\t\t live on;\ 
       \n\t\t}\n\t\t#next|g' /usr/local/nginx/conf/nginx.conf"
fi

 if [ $size -eq 1 ]; then
        raspivid -n -o - -t 0 -vf -hf -w 1920 -h 1080  -fps 20 -b 6000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h2$
    elif [ $size -eq 2 ]; then
      elif [ $size -eq 2 ]; then
    raspivid -n -o - -t 0 -vf -hf -w 1920 -h 1080  -fps 20 -b 4000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h2$
elif [ $size -eq 3 ]; then
    raspivid -n -o - -t 0 -vf -hf -w 640 -h 480  -fps 20 -b 1000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264$
elif [ $size -eq 4 ]; then
    raspivid -n -o - -t 0 -vf -hf -w 640 -h 360  -fps 20 -b 500000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 $
else
    echo "Improper resolution"
fi

We play video streaming with the below rtmp URL:

rtmp://server-ip/cam_id/live

1 Answer 1

0

Please Use 'exec_kill_signal' command of rtmp as below.

rtmp {
         server {
                listen 1935;
                chunk_size 4096;
                buflen 1ms;
                application cam_id {
                        live on;
                         allow publish 127.0.0.1;
                        allow publish all;
                        allow play all;
                        record all;
                        record_path /home/video_recordings;
                        record_unique on;
                        hls on;
                        hls_nested on;
                        hls_path /home/hls;
                        hls_fragment 10s;
                        dash on;
                        dash_path /home/dash;
                        dash_nested on;
                        exec_kill_signal closeStreaming;
        }

    }
}

Integrate below code in client program/App to close the streaming .

on_die () {  
   # kill all children  
   pkill -KILL -P $$  
 }  
 trap 'on_die' closeStreaming
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .