Location>code7788 >text

FFmpeg development notes (forty-five) using SRT Streamer to open the app live push streaming

Popularity:321 ℃/2024-08-10 11:58:41
SRT Streamer is an Android mobile open source SRT protocol live push streaming framework , can be used for RTMP live and SRT live . SRT Streamer supports video encoding , including H264, H265, etc., support for audio encoding , including AAC, OPUS, etc., can be said to be a powerful APP live broadcast framework .

In contrast, another APP live streaming framework RTMP Streamer supports RTMP live streaming and RTSP live streaming, and does not support SRT protocol live streaming. And this article about SRT Streamer supports RTMP live streaming and SRT live streaming, and does not support RTSP protocol live streaming. For instructions about RTMP Streamer see the previous article "Use RTMP Streamer to enable APP live push streaming", the following describes how to use SRT Streamer to enable APP live push streaming on your phone.

I. Download SRT Streamer

SRT Streamer takes full Kotlin coding, needs to be compiled and run on Android Studio Jellyfish (small jellyfish version), and relies on the latest JDK17, the running environment and the developer's skill requirements are relatively high. The blogger spent a long time to find the available SRT Streamer source code, if you need this set of source code, you can buy the book "FFmpeg Development in Action: From Zero Basis to Short Video Online" from Jingdong Self-Provisioning, and contact the author to get the SRT Streamer source code.
The SRT Streamer source code found by the blogger is written in Kotlin, not Java, and needs to be opened with the Jellyfish version of AS. So you need to install the Jellyfish version of AS, that is, Android Studio Jellyfish, the download address of this version of AS is https://redirector./edgedl/android/studio/ide-zips/2023.3.1.18/android-studio -2023.3.1....

II. Loading SRT Streamer

The downloaded SRT Streamer source code is a complete AS project, start the small jellyfish version of Android Studio, select the menu: File → Open, in the pop-up file dialog box, select the decompressed SRT Streamer source code directory. android Studio will start to automatically download the relevant components, and perform the gradle synchronization and other operations. To speed up the loading of the SRT Streamer project, you can open the project level and add the following configuration inside the repositories node:

// The following four lines add the AliCloud repository address, so that domestic developers can download the relevant plugins
maven { url '/repository/jcenter'}
maven { url '/repository/google'}
maven { url '/repository/gradle-plugin'}
maven { url '/repository/public'}
// Add the Huawei repository address below
maven { url '/repo/'}

The purpose of adding the above configuration is to introduce the domestic repository address in order to speed up the download of related dependency packages.
Waiting for the SRT Streamer project to finish loading successfully and viewing the navigation chart on the left side of Android Studio, you can see that the SRT Streamer project consists of the following five modules:
core module: this is the module that SRT Streamer uses to encode audio and video streams separately.
demo-camera module: this is the live camera demo module of SRT Streamer and the main entrance of APP project.
demo-screenrecorder module: this is the live screen recording demo module for SRT Streamer.
extension-rtmp module: this is the module for SRT Streamer to handle RTMP protocol communication.
extension-srt module: this is the module that SRT Streamer uses to handle SRT protocol communication.

III. Launching SRT Streamer

After Android Studio successfully loads SRT Streamer, you can install the demo app of SRT Streamer on your phone. For the detailed steps of compiling and installing the app, please refer to "2.1.1 App Running Environment" in Chapter 2 of the book "Android Studio Development: From Zero Basis to App Launch (3rd Edition)", and we will not repeat the steps here.
SRT Streamer's demo app is installed on your phone, and the initial interface after launch looks like the following.

Note that the first time you use SRT Streamer you need to configure the SRT server information first, click the three-point settings button in the upper left corner of the interface to open the server settings page as shown below.

The following four SRT server configurations are modified here:

1. Type field in the Endpoint area: click and drop down to select SRT device, indicating that SRT protocol is used to push the flow.
2. IP field of SRT Server area: fill in the IP of the streaming server.
3. Port field of SRT Server area: fill in the open port of the streaming media server for SRT protocol. For example, the default SRT port number for SRS is 10080 and the default SRT port number for ZLMediaKit is 9000.
4. Stream ID field of SRT Server area: fill in "#! ::r=live/test,m=publish".
It can be seen that SRT Streamer provides a rich variety of live forms, both through the cell phone camera live, but also on the screen operation of the phone live. Specific live protocols include RTMP and SRT two, can meet the majority of scenarios live demand, and SRT Streamer is an open source software, provides a complete APP live recording a full set of code, very suitable for developers to learn and research.

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