SRS is a domestic open source streaming media server, supports RTMP, SRT and other mainstream live protocols, its installation instructions see the previous article "Linux environment to install SRS to achieve video push streaming". Combined with SRS and ffmpeg to achieve RTMP protocol push stream function, has been in the "Linux environment to install SRS to achieve video push stream" article in detail, here alone explain how to SRS and ffmpeg to achieve SRT protocol push stream function.
SRS already supports SRT by default during compilation and startup. Check the configuration file dedicated to SRT service of SRS, and find the following configuration information in the srt section, which shows that SRS assigns port 10080 to SRT protocol by default.
In addition to this, add the following line inside the "vhost __defaultVhost__" node:
The role of this line of configuration is to enable the caching of keyframes, the actual application remember to set to on, otherwise the client pulls the stream to find keyframes can not be rendered on the screen.
Then run the following command to start the SRS streaming server dedicated to the SRT protocol.
After SRS starts, run the following ffmpeg commands to push stream video files to SRT address. Note, make sure FFmpeg on Linux server has integrated libsrt library, otherwise ffmpeg can't push stream to SRT address, for detailed integration steps, please refer to the previous article "Integrate libsrt and librist with FFmpeg in Linux environment".
Note that the second half of the srt address in the above command is "r=live/test,m=publish", where "r=live/test" means that the service name of SRT is called "live/test" and "m=publish" means that the address belongs to the publishing function, which is for the push streamer to use. live/test", and "m=publish" means that the address belongs to the publish function, which is for the push streamer to use.
SRS also has requirements on the encapsulation format of the video source file, not only the source file is required to be ts format, but also the push stream format is also required to be ts format, so ffmpeg added "-f mpegts" to the ffmpeg command to indicate that it is converted to mpeg ts stream format. If the source file is not in ts format, or not converted to mpegts format, subsequent playback of srt links via ffplay will report the following error.
After running the SRT Push Stream command of ffmpeg, SRS outputs the following log message, which shows that its SRT Push Stream function is running normally.
Then follow the introduction of "FFmpeg Development in Action: From Zero Basics to Online Short Video" book "1.3 Windows System Installation of FFmpeg", install FFmpeg on your PC and open the command line of MSYS, run the following ffplay command, expecting to pull the streams from the SRT address. play. Note, make sure the FFmpeg on your computer has integrated libsrt library, otherwise ffplay will not be able to play srt links, see the previous article "Windows environment to FFmpeg integration libsrt" for detailed integration steps.
The above SRT streaming address is similar to the previous streaming address, except that the IP address is changed to the IP address of the external network, that is, the "m=publish" at the end of the link is changed to "m=request", in which request indicates that the request is also used to pull the stream party.
ffplay runs and pops up the player window and plays the video screen and sound normally. Also observe the SRS service log as shown below:
As seen from the above logs, SRS has successfully implemented the SRT push-pull streaming feature for live video streaming via the SRT protocol.
For more details on FFmpeg development see