Equipped with rtmp live server

        This time, we set up a rtmp live server to push the live video from computer or mobile phone to the server, and then other terminals such as computer or mobile phone can watch the live video. We use computer screen recording software to broadcast the real-time recorded computer screen to others. A total of three parts are required. First, the screen recording software records the computer screen and transmits the screen to the server; Second, the server rtmp should be set up to receive the images uploaded from the screen recording software; Third, the video player client can connect to the rtmp server and receive the video stream pushed by the rtmp server, so as to watch the real-time picture of the first part of the screen recording software in real time. The core here is the second part, building rtmp server.

one   Download nginx

nginx is a server software, similar to tomcat, which is used to publish server programs

(1) Download address: execute under linux   wget http://nginx.org/download/nginx-1.15.3.tar.gz Command to download the compressed package.

(2) Unzip, using the tar command:    tar xvf nginx-1.15.3.tar.gz

two   Download nginx rtmp module

​      wget https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/v1.2.1 Also unzip tar xvf v1.2.1  

3. Compile nginx

./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1

4. Modify the conf file in nginx RTMP module

cd   nginx-rtmp-module-1.2.1 open the folder, cd test folder, and modify the contents of nginx.conf file as follows:

worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application myapp {
            live on;

            #record keyframes;
            #record_path /tmp;
            #record_max_size 128K;
            #record_interval 30s;
            #record_suffix .this.is.flv;

            #on_publish http://localhost:8080/publish;
            #on_play http://localhost:8080/play;
            #on_record_done http://localhost:8080/record_done;
        }
    }
}

http {
    server {
        listen      8080;

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root /path/to/nginx-rtmp-module/;
        }

        location /control {
            rtmp_control all;
        }

        #location /publish {
        #    return 201;
        #}

        #location /play {
        #    return 202;
        #}

        #location /record_done {
        #    return 203;
        #}

        location /rtmp-publisher {
            root /path/to/nginx-rtmp-module/test;
        }

        location / {
            root /path/to/nginx-rtmp-module/test/www;
        }
    }
}

The streaming address will be     rtmp://IP:PORT/myapp/{abc}, where abc in {abc} is optional. It is generally a streaming password. When pushing or receiving video streams to the server, you can fill in a password, such as abc. The default server port of RTMP is 1935. If this port is occupied, the process occupying this port can be killed. Use the following command:

kill -9   pid   (where PID is the process id).

Then replace nginx.conf under nginx-1.15.3/bin/conf with this conf,

Use the mv nginx.conf nginx.conf.bak command to rename the original nginx.conf without deleting the original file.

5. Start nginx

cd nginx-1.15.3  

Open nginx folder

/root/nginx-1.15.3/bin/sbin/nginx 

start nginx

6. Verify whether nginx rtmp streaming media is successfully deployed

After startup, visit 122.112.220.253:8080 from the browser.

If it doesn't open,
one   Establish security rules on the server, develop entry rules, and open the 19358080 ports. The protocol is TCP
two   Modify the user at the top of nginx.conf under nginx-1.15.3/bin/conf:   user root;

    At this time, the content of nginx.conf is as follows:

user  root;
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application myapp {
            live on;
	    drop_idle_publisher 5s;
        }
    }
}

http {
    server {
        listen      8082;

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root /root/nginx-rtmp-module-1.2.1/;
        }

        location /control {
            rtmp_control all;
        }

    

        location /rtmp-publisher {
            root /root/nginx-rtmp-module-1.2.1/test;
        }

        location / {
            root /root/nginx-rtmp-module-1.2.1/test/www;
        }
    }
}


3. Restart nginx and visit 122.112.220.253:8082 again. Success.

Next time, we will use a screen recording software to record the computer screen, use the rtmp protocol to push the computer screen to the server, and use the player to play the rtmp live stream on the server.

   

Tags: Linux Nginx NDK

Posted on Mon, 11 Oct 2021 14:27:38 -0400 by dukeu03