Location>code7788 >text

FFmpeg development notes (fifty-four) using EasyPusher to achieve the mobile RTSP live broadcast

Popularity:454 ℃/2024-09-22 11:40:54
The previous article "Using RTMP protocol to build a computer and cell phone live Demo" describes how to use RTMP Streamer to achieve a complete RTMP live streaming process, another article "Using SRT protocol to build a cell phone APP live streaming Demo" describes how to use SRT Streamer to achieve a complete SRT live streaming process, and the next article describes how to use the EasyPusher-Android to realize the complete RTSP live streaming process.

I. Comparison of four common streaming media transmission protocols

Common streaming media transmission protocols are mainly the following four categories: RTSP protocol, RTMP protocol, SRT protocol and RIST protocol, on the detailed description of these four protocols see the previous article, "Using RTMP protocol to build a computer and cell phone live Demo", here will not repeat.
Among the above four streaming protocols, RTSP appeared the earliest, and in the PC Internet era, RTSP live broadcast was once the mainstream means of live video. The following is an example of how to do RTSP live streaming to a streaming media server via EasyPusher-Android with RTSP protocol.

Second, the computer side through the OBS Studio RTSP live push streaming

OBS Studio doesn't support RTSP protocol by default, you need to install OBS-RTSPServer plugin before you can realize RTSP push streaming. If you are interested, you can configure OBS Studio by yourself to realize RTSP live streaming on your computer.

Third, the cell phone through the EasyPusher-Android RTSP live push streaming

Since EasyPusher only supports RTSP push streaming and SRS does not support RTSP protocol, the server side can only use ZLMediaKit. first start the streaming server ZLMediaKit on the cloud service, deploying and starting ZLMediaKit on the cloud server is more troublesome, which is impossible to be explained in a few words. If you want to figure out how to operate ZLMediaKit on the cloud server, see the previous article "Linux environment to install ZLMediaKit to realize the video push streaming" for detailed steps.
Then start the cell phone on the live recording software EasyPusher-Android, the specific operation steps see the previous article "mobile domestic live recording tool EasyPusher". In the debugging process, found that EasyPusher-Android can not normally parse the shape of "rtsp://124.70.***. ***/live/test", we need to modify EasyPusher-Android's app code to make it support common RTSP push stream address. The modification is described below:
Open the EasyPusher-Android project and put the following lines of RTSP link parsing code:

String ip = (this);
String port = (this);
String id = (this);

Change to the following RTSP link parsing code for the purpose of properly parsing the server IP, port number, and service name in the RTSP link:

String regex = "^rtsps?://([^/:]+)(?::(\\d+))*/([^/]+)/?([^*]*)$";
Pattern pattern = (regex);
Matcher matcher = (url);
boolean matches = ();
(TAG, "matches = " + matches);
String ip = (1);
String port = (2)!=null?(1):"554";
String id = (3) + "/" + (4);

Then open it up and put the following line

private static final String DEFAULT_SERVER_URL = "rtsp://:554/" + ((int) (() * 1000000 + 100000));

Replace it with the following line:

private static final String DEFAULT_SERVER_URL = "rtsp://124.70.***. ***/live/test"; // Be careful to replace it with your own RTSP server IP.

Save the code, recompile and run it again, install the app on the test phone, wait for EasyPusher-Android to start, click the "Push Stream" button at the bottom left corner of the screen, and let EasyPusher-Android to the rtsp address of ZLMediaKit. "rtsp://124.70.***. ***/live/test", the EasyPusher-Android recording interface of the pushing process is shown below.

Observing the ZLMediaKit logs on Huawei Cloud as follows, you can see that EasyPusher-Android is pushing live streams to the back-end streaming server:

[MediaServer] [119311-event poller 0] :517 emitEvent | Media Registration:rtsp://__defaultVhost__/live/test
[MediaServer] [119311-event poller 0] :161 emitAllTrackReady | All track ready use 270ms
[MediaServer] [119311-event poller 0] :517 emitEvent | Media Registration:fmp4://__defaultVhost__/live/test
[MediaServer] [119311-event poller 0] :551 onAllTrackReady | stream: rtsp://124.70.221.25:554/live/test , codec info: mpeg4-generic[8000/1/16] H264[720/1280/0]
[MediaServer] [119311-event poller 0] :517 emitEvent | Media Registration:rtmp://__defaultVhost__/live/test
[MediaServer] [119311-event poller 0] :517 emitEvent | Media Registration:ts://__defaultVhost__/live/test
[MediaServer] [119311-event poller 0] :517 emitEvent | Media Registration:hls://__defaultVhost__/live/test

Then start the streaming media player VLC media player on your computer, open the network stream "rtsp://124.70.***. ***/live/test", at this time the video playback interface of VLC media player is shown in the figure below.

Observing the ZLMediaKit logs on Huawei Cloud as follows, you can see that VLC media player is pulling live streams from the back-end streaming server:

[MediaServer] [119311-event poller 0] :413 getPortPair | got port from pool:34512-34513
[MediaServer] [119311-event poller 0] :413 getPortPair | got port from pool:33900-33901
[MediaServer] [119311-event poller 0] :819 handleReq_Play | 10-20(121.204.108.60:2247) rtsp seekTo(ms):0

Combining the live recording screen of EasyPusher-Android and the live viewing interface of VLC media player, it can be seen that EasyPusher-Android has successfully realized the live broadcast function of RTSP protocol.Can.

For more details on FFmpeg development seeFFmpeg Development in Action: From Zero Basics to Short Video OnlineA book.