Live broadcast for cows Part 3

1. Preface

The previous article Live Broadcasting for Milk Part 2   mainly talked about using RTMP to build an on-demand server. The live broadcast has not started for a long time. I won’t talk too much about theory today. The cow is on holiday today and will not show up, so I will go on the live broadcast in person. The first show, see the picture below, if you are interested, you can contact me, I will open the live broadcast and brag with you.

The left side of the picture is recording and the right side is playing. Next, let’s take a look at how to build a live broadcast service.

2. Nginx RTMP live broadcast server configuration

Add application live configuration

rtmp{
  server{
    listen 1935;
    chunk_size 4096;
    application vod{
      play /opt/vod;
    }
    application live{
      live on;
    }
  }
}

http server plus

location /stat{
  rtmp_stat all;
  rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl{
    root /opt/nginx-rtmp-module-master/;
}

Restart Nginx and enter http://118.31.5.244/stat. This page can monitor some parameter data of the live broadcast. If there is Live, it means that your configuration is successful. You can also see in the picture that Video and Audio are separated, and the audio stream is Encoded with AACLC, the video stream is encoded with our  The H264 encoding mentioned in one of the live broadcasts for cows .

Note: Please pay attention when configuring. The address pointed to by nginx-rtmp-module-master nginx should not be placed in the root directory, otherwise there will be permission problems. The previous live video file should also not be placed under the root.

3. Data collection terminal and playback

1. Install the OBS live broadcast software on your Mac and set the push address.

Then click to start streaming.

2. Playback end

Use VCL player, OPEN NETWORK to enter the streaming address rtmp://118.31.5.244/live to play.

4. Some concepts of RTMP protocol

1. RTMP is an application layer protocol, using port number 1935 by default. The network layer relies on TCP to ensure reliable transmission.

2. RTMP requires the client and server to establish a connection through a handshake. The rough handshake process is as follows

  • client-->server: Send a request to create a stream (C0, C1)

  • server-->client: Returns the index number of a stream (S0, S1, S2)

  • client--> server: start sending (C2)

  • client--> server: send audio and video data

After the handshake is completed, the message is transmitted in blocks. Each message block has an ID. Only after one message block is sent can the next message block be sent. After the server receives it, it is combined into a message based on the message block ID. The general message block size is 128 bytes. Therefore, there is generally a 3 or 4 second delay in loading using the RTMP protocol.

Note: The principle of the protocol is still quite complicated. I will briefly understand it without going into details. Today I started the experiment by wanting to use the mobile phone to do push streaming, but I couldn’t find a tool. I will use Android to make a push tool myself next time I have time (I just bought it). Android phone), we will introduce other concepts such as HLS protocol later.

Guess you like

Origin blog.csdn.net/2301_76787421/article/details/133443345