Protocol introduction
- RTMP protocol
- Full name: Real Time Messaging Protocol, real-time messaging protocol
- Introduction: It is an open protocol developed by Adobe Systems for audio, video and data transmission between Flash players and servers.
- Protocol: Long connection TCP
- Principle: Data at each moment is forwarded immediately after receipt
- Delay: 1~3 seconds
- Advantages: Supported by mainstream CDNs and used by most live broadcast products on the market. The protocol is simple and easy to implement
- Disadvantages: Based on TCP protocol, high overhead. Adobe proprietary agreement.
- HLS protocol
- Full name: HTTP Live Streaming
- Protocol: Short connection HTTP
- Principle: Collect data for a period of time, generate ts slice files, and update m3u8
- Delay: greater than 10 seconds
- HTTP-FLV protocol
- Full name: RTMP over HTTP
- Protocol: Long connection HTTP
- Principle: Same as RTMP, using HTTP protocol
- Delay: 1~3 seconds
Streaming media server introduction
- red5(java) and FMS commercial
- crtmpserver
- Nginx + RTMP plugin
crtmpserver builds streaming media server
- Install
- cmake installation: apt-get install cmake
- SSL library installation: apt-get install libssl-dev
- crtmpserver download and installation
- Download: wget https://codeload.github.com/j0sh/crtmpserver/zip/centosinit
- Unzip: unzip centosinit
- Enter the crtmpserver-centosinit/builders/cmake directory and executecmake ., then executemake
- run
- Enter the crtmpserver-centosinit/builders/cmake/ directory and execute./crtmpserver/crtmpserver crtmpserver/crtmpserver.lua
- If it runs successfully, the following printout will appear:
- Note: Try to choose version 16 for Ubuntu, otherwise compilation errors may occur. Ubuntu can be downloaded from here
FFmpeg download and installation
- download link
- You can choose a version to download, I chose this one
- After decompression, you can configure the path of the executable program ffmpeg.exe into the path of the system environment variable.
Push streaming using FFMpeg
- Push command: ffmpeg.exe -i 001.mp4 -c copy -f flv rtmp://192.168.206.131/live/test1
- Parameter Description
- ffmpeg.exe: The FFmpeg executable program just installed
- 001.mp4: Video file, you can choose any one
- 192.168.206.131: This address is the address of the crtmpserver server we just built
Test using VLC player
- Download address: Just install it directly after downloading
- Open VLC, select play, and copy the URL here
- Execute the push command to play the pushed video.
Nginx download and installation
- Note: Install dependencies first, do not install nginx yet
- You can refer to my other article nginx download and installation
Nginx-rtmp download and install
- git clone https://github.com/arut/nginx-rtmp-module.git Note here that you need to use git to pull. Compiling the zip compressed package downloaded directly from the website may report an error.
- To install Nginx, enter the directory of the Nginx installation package, execute ./configure --add-module=[Nginx-rtmp path], and then execute make and make install
Nginx-rtmp configuration
- Add the following content to the outermost layer of the /usr/local/nginx/conf/nginx.conf configuration file
-
rtmp { server{ listen 10088; chunk_size 4096; application live { live on; } } }
- After configuring, start nginx
Push streaming
- ffmpeg.exe -i 001.mp4 -c copy -f flv rtmp://192.168.206.131:10088/live
play
Show push status on web page
- Add the following content to the http node in the /usr/local/nginx/conf/nginx.conf configuration file
-
server { listen 10010; location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # 你的nginx-rtmp包的路径 root //home/lingp/share/nginx-rtmp-module; } }
- Reload configuration ./nginx -s reload
- Re-visit this address http://192.168.206.131:10010/stat and you will see the push status
Use ffplay to play
- In the same directory as your ffmpeg program, execute ffplay.exe rtmp://192.168.206.131:10088/live -fflags nobuffer