rtsp push-pull streaming learning 2 for audio and video learning (streaming media server zlmedia Kit)

The company's project needs to implement a business mechanism that only pushes and pulls rtsp streams. It is said that zlmedia kit can meet the related businesses of rtsp push and pull streams.

Install and understand zlmedia kit streaming media server.

0: learn about its functions from the open source library Readme

Simply know zlmedia kit and understand the basic functions that zlmedia kit can achieve. My understanding is that it is a streaming media server.

1: Zlmedia kit environment construction

Use the linux virtual machine environment to build the environment and start:

#Zlmedia kit adopts the syntax and Library of C++11, and requires the compiler to hold the complete C++11 standard.
sudo apt-get install cmake
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit.git
cd ZLMediaKit/
#Be sure to implement
git submodule update --init
mkdir build
sudo cmake ..
make -j4

#Related dependent libraries here, test the basic functions first, and only install the openssl library
sudo apt-get install libssl-dev
 #In addition to openssl, others can not be installed
#sudo apt-get install libssl-dev
#sudo apt-get install libsdl-dev
#sudo apt-get install libavcodec-dev
#sudo apt-get install libavutil-dev
#sudo apt-get install ffmpeg

#Generate relevant executable files in the release directory. For the time being, as a test, only focus on the MediaServer main process file
hlp@ubuntu:~/ZLMediaKit/release/linux/Debug$ pwd
/home/hlp/ZLMediaKit/release/linux/Debug
./MediaServer -h	#View related parameters
sudo ./MediaServer -d &	#start-up 
#Observe the log and the startup logic is normal

2: Test rtsp, rtmp, rtp push flow and pull flow

As a streaming media server, zlmedia kit uses ffmpeg/obs, ffplay/vlc and other tools as the streaming end or pull end to test the basic functions.

2.1: Test rtsp streaming and pulling: use ffmpeg streaming and vlc/ffplay streaming to test

2.1.1: push the stream with ffmpeg and pull the stream with vlc for testing

Start zlmedia kit and use ffmpeg streaming command:

ffmpeg -re -i "time.mp4" -vcodec h264 -acodec aac -f rtsp -rtsp_transport tcp rtsp://192.168.0.110/live/test
#tcp for rtsp streaming

vlc pulls the stream for verification, and it will be found that the playback is normal:

2.1.2: if ffplay is used for testing, try rtsp/rtmp streaming.

Use ffplay to pull flow related commands:

#The default port that should be used here
ffplay -rtsp_transport tcp rtsp://192.168.0.110/live/test
ffplay -rtsp_transport udp rtsp://192.168.0.110/live/test
ffplay rtmp://192.168.0.110/live/test

The related phenomena of streaming are shown in the figure below. It can be found that there is a certain difference in real-time performance between rtsp and rtmp streaming.

2.2: push and pull flow tests using rtmp:

2.2.1: ffmpeg uses rtmp streaming command

-re Indicates that the file is read by timestamp
-vcodec vedio Coding format
-acodec audio Coding format
-f  Represents the output format
#Streaming command using rtmp
ffmpeg -re -i "time.mp4" -vcodec h264 -acodec aac -f flv rtmp://192.168.0.110/live/test

Using vlc to simply test the streaming, the playback is successful. At the same time, it is found that using rtmp,rtsp (udp, tcp rtp mode), the timestamp difference also varies greatly:

2.2.2: if ffmpeg is used for streaming, ffplay is used for streaming test.

#Streaming command using rtmp
ffmpeg -re -i "time.mp4" -vcodec h264 -acodec aac -f flv rtmp://192.168.0.110/live/test
#ffplay streaming playback command
ffplay -rtsp_transport tcp rtsp://192.168.0.110/live/test
ffplay -rtsp_transport udp rtsp://192.168.0.110/live/test
ffplay rtmp://192.168.0.110/live/test

Briefly compare the timestamp:

2.3: push pull flow test using rtp

2.3.1 rtp streaming using ffmpeg

rtp's push stream and pull stream have some blind spots of personal knowledge, which are temporarily left here

#The command of streaming using rtp: but I didn't test how to play
ffmpeg -re -i "time.mp4" -vcodec h264 -acodec aac -f rtp_mpegts rtp://192.168.0.110:10000

#A logic for passing the test: 
#Logic of rtp streaming with ffmepg and playing based on ffplay: (no server)
ffmpeg -re -i time.mp4 -vcodec copy -f rtp rtp://127.0.0.1:1234>test.sdp
ffplay -protocol_whitelist "file,udp,rtp" -i test.sdp    #You will find that the playback is successful

#The following command failed to play successfully, leaving a problem temporarily
#ffplay -protocol_whitelist "file,udp,rtp" -i rtp://127.0.0.1:1234

3: Grab the package with wireshark and get familiar with the process:

Simply grasp the package and get familiar with the learning process. Here, rtsp udp is used to push the stream and rtsp tcp is used to pull the stream:

ffmpeg -re -i "time.mp4" -vcodec h264 -acodec aac -f rtsp -rtsp_transport udp rtsp://192.168.0.110/live/test
ffplay -rtsp_transport tcp rtsp://192.168.0.110/live/test

3.1: when using ffmpeg for streaming, packet capture is as follows:

OPTION: query the server-side executable method

ANNOUNCE: send media description information

SETUP: create RTSP session

RECORD: request to transfer data

RTP: data push

TEARDOWN: close the session and exit

3.2: the analysis of flow capture process is as follows:

OPTION: query the server-side executable method

DESCRIBE: get the server media description information, usually sdp information

SETUP: create RTSP session

PLAY: request to start data transfer

RTP: data transmission playing

TEARDOWN: close the session and exit

3.3: rtsp push flow and pull flow process summary

Step 1: query the available method option s on the server side
Step 2: interactive media information SDP, streaming: ANNOUNCE; Pull flow: DESCRIBE
Step 3: request to establish a session. Here, tcp based and udp based differential SETUP,
Step 4: trigger to start pushing or pulling. Pushing: RECORD; Pull flow: PLAY,
Step 5: data transmission, but in the opposite direction, the real push stream or pull stream rtp
Step 6: close the session: TEARDOWN

4: Summary

To understand rtsp push-pull flow, practice first and prepare for the future

Test the zlmedia kit streaming server and related push-pull streams.

Next step plan: basic use of obs software (obs is a powerful software. I wanted to try to operate it, but I found it difficult)

Audio and video related theoretical learning and practical reference: Recommended free subscription

Added by ecco on Thu, 13 Jan 2022 12:10:21 +0200