2019-02-02 09:00:48 +00:00
# SRT (GStreamer command-line cheat sheet)
2022-08-26 20:59:12 +00:00
SRT is a means of sending AV between to servers.
2019-02-02 09:00:48 +00:00
SRT has a client-server relationship. One side must be the server, the other the client.
The server can either be the side that is sending the audio/video (pushing) or the side that is
receiving (pulling). The server must have started exist before the client.
2022-08-26 20:59:12 +00:00
## Pre-requisites
2019-02-02 09:00:48 +00:00
2022-08-26 20:59:12 +00:00
If on MacOS, ensure the SRT library is installed:
2019-02-02 09:00:48 +00:00
2022-08-26 20:59:12 +00:00
```
brew install srt
```
Then at the time of writing, the default Homebrew build does not include SRT, so build from scratch:
```
brew install --build-from-source gst-plugins-bad
```
## Client receiving from server
The most common usage is that the server has the video, and a client reads from it.
To create a sender server, use `srtsink` (or alternatively, `srtserversink` ):
```
gst-launch-1.0 -v videotestsrc ! video/x-raw, height=360, width=640 ! videoconvert ! x264enc tune=zerolatency ! video/x-h264, profile=high ! mpegtsmux ! srtsink uri=srt://:8888
```
And then recieve with `srtsrc` (or alternatively, `srtclientsrc` ):
```
gst-launch-1.0 -v srtsrc uri="srt://127.0.0.1:8888" ! decodebin ! autovideosink
```
Don't forget, the amazing `playbin` can show anything - including SRT streams. This is useful for debugging:
2019-02-02 09:00:48 +00:00
```
2022-08-26 20:59:12 +00:00
gst-launch-1.0 playbin uri=srt://127.0.0.1:8888
2019-02-02 09:00:48 +00:00
```
2022-08-26 20:59:12 +00:00
By default, `srtsink` will wait for a clilent connection before allowing the stream to start. If you'd prefer this not to happen, set `wait-for-connection=false` :
2019-02-02 09:00:48 +00:00
```
2022-08-26 20:59:12 +00:00
gst-launch-1.0 -v videotestsrc ! video/x-raw, height=360, width=640 ! \
videoconvert ! clockoverlay font-desc="Sans, 48" ! x264enc tune=zerolatency ! \
video/x-h264, profile=high ! mpegtsmux ! srtsink uri=srt://:8888 wait-for-connection=false
2019-02-02 09:00:48 +00:00
```
2022-08-26 20:59:12 +00:00
## Client sending to server
The alternative way round is to have the producer sending the AV to the receiving server.
2019-02-02 09:00:48 +00:00
To have the server receiving, rather than sending, swap 'srtclientsrc' for 'srcserversrc'.
Likewise, to have the client sending rather than receiving, swap 'srtserversink' for 'srtclientsink'.
Create a receiver server like this:
```
2022-08-26 20:59:12 +00:00
gst-launch-1.0 -v srtserversrc uri="srt://127.0.0.1:8889" ! decodebin ! autovideosink
2019-02-02 09:00:48 +00:00
```
And a sender client like this:
```
2022-08-26 20:59:12 +00:00
gst-launch-1.0 -v videotestsrc ! video/x-raw, height=360, width=640 ! \
videoconvert ! clockoverlay font-desc="Sans, 48" ! x264enc tune=zerolatency ! \
video/x-h264, profile=high ! mpegtsmux ! srtclientsink uri=srt://:8889
```