Live broadcast for milk part 2

I. Introduction

One of the live broadcasts for cows  mainly talks about video encoding and decoding. Today we will continue to talk about the network application layer protocol of video streaming. First, we will briefly talk about the video file format and encoding. There are many video file formats, such as the previous ones. There are countless types of AVI, RMVB, MP4, etc. The video file format and the video encoding mentioned in the previous article are two different things. The video file format can be understood as a container, which contains the video stream and audio stream. Video encoding is to encode the video in the container. Streaming data is compressed mainly through the two series MPEG and H.26X mentioned in the previous article.

2. HTTP protocol

1. Download the video files on the server progressively through the HTTP protocol, and then decode and play them on the player.

2. The principle of fast forwarding in video playback: The header of the video file stores the position of the corresponding frame, so that the video can jump to the undownloaded part. This is because the HTTP1.1 protocol begins to support Range. See the figure below to specify the starting point. Which byte should start downloading and playing? Note: This feature of Range is also used for resumed downloading.

3. HTTP is used for on-demand playback. Video files mainly include MP4 or the old Flash FLV. This kind of video is easy to be downloaded by users, and there are copyright issues, but because it uses port 80, there is no need to solve the problem of penetration of firewalls in the network.

3. RTMP protocol

RTMP, Real-Time Messging Protocol, is Adobe's proprietary protocol. It generally transmits Flv and mp4 format streams.

Build an RTMP server, connect to the server in real time during playback, and play files on the server. Video files will not be cached on the client, and copyrights are safer.

1. Set up the environment and install Nginx and Nginx rtmp module

OS:Ubuntu 16.04 64
wget http://nginx.org./download/nginx-1.8.1.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/refs/heads/master.zip
apt-get update
apt-get install libpcre3 libpcre3-dev
apt-get install openssl libssl-dev
tar -zxvf nginx-1.8.1.tar.gz
unzip master.zip
cd nginx-1.8.1/
./configure --add-module=../nginx-rtmp-module-master
make && make install

2. Configure on-demand service

nginx.conf

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

Just put the video file vanmilk.mp4 in the /opt/vod directory. Use the VLC player Open Network to open the address rtmp://118.31.5.244/vod/vanmilk.mp4. Of course, it can also be supported by your player on the web page. Play directly.

2. Configure live broadcast service

To be continued, I wanted to set up the live broadcast environment today, but I was so busy that I didn’t have any time. I will work on it tomorrow and the day after tomorrow. I plan to finish this piece of content in 5 or 6 short articles. .

Guess you like

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