_rtsp-simple-server_ is a simple, ready-to-use and zero-dependency RTSP server and RTSP proxy, a software that allows multiple users to publish, read and proxy live video and audio streams over time. RTSP is a standard protocol that describes how to perform these operations with the help of a server, that is contacted by both publishers and readers and relays the publisher's streams to the readers.
_rtsp-simple-server_ is a simple, ready-to-use and zero-dependency RTSP server and RTSP proxy, a software that allows multiple users to publish, read and proxy live video and audio streams over time. RTSP is a standard protocol that describes how to perform these operations with the help of a server, that is contacted by both publishers and readers and relays the publisher's streams to the readers.
Features:
Features:
* Read and publish live streams with UDP and TCP
* Read and publish live streams with UDP and TCP
* Each stream can have multiple video and audio tracks, encoded with any codec (including H264, H265, VP8, VP9, MP3, AAC, Opus, PCM)
* Each stream can have multiple video and audio tracks, encoded with any codec (including H264, H265, VP8, VP9, MP3, AAC, Opus, PCM)
* Serve multiple streams at once in separate paths
* Serve multiple streams at once in separate paths
@ -23,31 +24,37 @@ Features:
1. Download and extract a precompiled binary from the [release page](https://github.com/aler9/rtsp-simple-server/releases).
1. Download and extract a precompiled binary from the [release page](https://github.com/aler9/rtsp-simple-server/releases).
2. Start the server:
2. Start the server:
```
```
./rtsp-simple-server
./rtsp-simple-server
```
```
3. Publish a stream. For instance, you can publish a video file with _FFmpeg_:
3. Publish a stream. For instance, you can publish a video file with _FFmpeg_:
docker run --rm -it --network=host aler9/rtsp-simple-server
docker run --rm -it --network=host aler9/rtsp-simple-server
```
```
The `--network=host` argument is mandatory since Docker can change the source port of UDP packets for routing reasons, and this makes RTSP routing impossible. This issue can be avoided by disabling UDP and exposing the RTSP port:
The `--network=host` argument is mandatory since Docker can change the source port of UDP packets for routing reasons, and this makes RTSP routing impossible. This issue can be avoided by disabling UDP and exposing the RTSP port:
```
```
docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server
docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server
To see or change the configuration, edit the `rtsp-simple-server.yml` file, that is:
To see or change the configuration, edit the `rtsp-simple-server.yml` file, that is:
* included the release bundle
* included the release bundle
* available in the root folder of the Docker image (`/rtsp-simple-server.yml`)
* available in the root folder of the Docker image (`/rtsp-simple-server.yml`)
* also [available here](rtsp-simple-server.yml).
* also [available here](rtsp-simple-server.yml).
Every configuration parameter can be overridden by environment variables, in the format `RTSP_PARAMNAME`, where `PARAMNAME` is the uppercase name of a parameter. For instance, the `rtspPort` parameter can be overridden in the following way:
Every configuration parameter can be overridden by environment variables, in the format `RTSP_PARAMNAME`, where `PARAMNAME` is the uppercase name of a parameter. For instance, the `rtspPort` parameter can be overridden in the following way:
```
```
RTSP_RTSPPORT=8555 ./rtsp-simple-server
RTSP_RTSPPORT=8555 ./rtsp-simple-server
```
```
Parameters in maps can be overridden by using underscores, in the following way:
Parameters in maps can be overridden by using underscores, in the following way:
@ -88,10 +100,12 @@ The configuration can be changed dinamically when the server is running (hot rel
### RTSP proxy mode
### RTSP proxy mode
_rtsp-simple-server_ is also a RTSP proxy, that is usually deployed in one of these scenarios:
_rtsp-simple-server_ is also a RTSP proxy, that is usually deployed in one of these scenarios:
* when there are multiple users that are receiving a stream and the bandwidth is limited; the proxy is used to receive the stream once. Users can then connect to the proxy instead of the original source.
* when there are multiple users that are receiving a stream and the bandwidth is limited; the proxy is used to receive the stream once. Users can then connect to the proxy instead of the original source.
* when there's a NAT / firewall between a stream and the users; the proxy is installed on the NAT and makes the stream available to the outside world.
* when there's a NAT / firewall between a stream and the users; the proxy is installed on the NAT and makes the stream available to the outside world.
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
```yml
paths:
paths:
proxied:
proxied:
@ -102,6 +116,7 @@ paths:
After starting the server, users can connect to `rtsp://localhost:8554/proxied`, instead of connecting to the original url. The server supports any number of source streams, it's enough to add additional entries to the `paths` section.
After starting the server, users can connect to `rtsp://localhost:8554/proxied`, instead of connecting to the original url. The server supports any number of source streams, it's enough to add additional entries to the `paths` section.
It's possible to save bandwidth by enabling the on-demand mode: the stream will be pulled only when at least a client is connected:
It's possible to save bandwidth by enabling the on-demand mode: the stream will be pulled only when at least a client is connected:
```yml
```yml
paths:
paths:
proxied:
proxied:
@ -112,6 +127,7 @@ paths:
### Serve a webcam
### Serve a webcam
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
```yml
paths:
paths:
cam:
cam:
@ -120,6 +136,7 @@ paths:
```
```
If the platform is Windows:
If the platform is Windows:
```yml
```yml
paths:
paths:
cam:
cam:
@ -137,7 +154,9 @@ After starting the server, the webcam can be reached on `rtsp://localhost:8554/c
2. gst-rpicamsrc, by following [instruction here](https://github.com/thaytan/gst-rpicamsrc)
2. gst-rpicamsrc, by following [instruction here](https://github.com/thaytan/gst-rpicamsrc)
Then edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
Then edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
```yml
paths:
paths:
cam:
cam:
@ -157,6 +177,7 @@ After starting the server, the webcam is available on `rtsp://localhost:8554/cam
### On-demand publishing
### On-demand publishing
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
```yml
paths:
paths:
ondemand:
ondemand:
@ -169,6 +190,7 @@ The command inserted into `runOnDemand` will start only when a client requests t
### Remuxing, re-encoding, compression
### Remuxing, re-encoding, compression
To change the format, codec or compression of a stream, use _FFmpeg_ or _Gstreamer_ together with _rtsp-simple-server_. For instance, to re-encode an existing stream, that is available in the `/original` path, and publish the resulting stream in the `/compressed` path, edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
To change the format, codec or compression of a stream, use _FFmpeg_ or _Gstreamer_ together with _rtsp-simple-server_. For instance, to re-encode an existing stream, that is available in the `/original` path, and publish the resulting stream in the `/compressed` path, edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
```yml
paths:
paths:
all:
all:
@ -180,6 +202,7 @@ paths:
### Redirect to another server
### Redirect to another server
To redirect to another server, use the `redirect` source:
To redirect to another server, use the `redirect` source:
```yml
```yml
paths:
paths:
redirected:
redirected:
@ -190,6 +213,7 @@ paths:
### Fallback stream
### Fallback stream
If no one is publishing to the server, readers can be redirected to a fallback URL that is serving a fallback stream:
If no one is publishing to the server, readers can be redirected to a fallback URL that is serving a fallback stream:
```yml
```yml
paths:
paths:
withfallback:
withfallback:
@ -199,6 +223,7 @@ paths:
### Authentication
### Authentication
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
```yml
paths:
paths:
all:
all:
@ -207,11 +232,13 @@ paths:
```
```
Only publishers that provide both username and password will be able to proceed:
Only publishers that provide both username and password will be able to proceed:
means that there are 2 clients, 1 publisher and 1 reader.
means that there are 2 clients, 1 publisher and 1 reader.
* A metrics exporter, compatible with Prometheus, can be enabled with the parameter `metrics: yes`; then the server can be queried for metrics with Prometheus or with a simple HTTP request:
* A metrics exporter, compatible with Prometheus, can be enabled with the parameter `metrics: yes`; then the server can be queried for metrics with Prometheus or with a simple HTTP request:
```
```
wget -qO- localhost:9998
wget -qO- localhost:9998
```
```
Obtaining:
Obtaining:
```
```
rtsp_clients{state="idle"} 2 1596122687740
rtsp_clients{state="idle"} 2 1596122687740
rtsp_clients{state="publishing"} 15 1596122687740
rtsp_clients{state="publishing"} 15 1596122687740
@ -273,6 +309,7 @@ There are multiple ways to monitor the server usage over time:
```
```
where:
where:
* `rtsp_clients{state="idle"}` is the count of clients that are neither publishing nor reading
* `rtsp_clients{state="idle"}` is the count of clients that are neither publishing nor reading
* `rtsp_clients{state="publishing"}` is the count of clients that are publishing
* `rtsp_clients{state="publishing"}` is the count of clients that are publishing
* `rtsp_clients{state="reading"}` is the count of clients that are reading
* `rtsp_clients{state="reading"}` is the count of clients that are reading
@ -282,10 +319,11 @@ There are multiple ways to monitor the server usage over time:
* `rtsp_sources{type="rtmp",state="running"}` is the count of rtmp sources that are running
* `rtsp_sources{type="rtmp",state="running"}` is the count of rtmp sources that are running
* A performance monitor, compatible with pprof, can be enabled with the parameter `pprof: yes`; then the server can be queried for metrics with pprof-compatible tools, like:
* A performance monitor, compatible with pprof, can be enabled with the parameter `pprof: yes`; then the server can be queried for metrics with pprof-compatible tools, like:
```
```
docker run --rm -it --network=host golang:1.15 go tool pprof -text http://localhost:9999/debug/pprof/goroutine
go tool pprof -text http://localhost:9999/debug/pprof/goroutine
docker run --rm -it --network=host golang:1.15 go tool pprof -text http://localhost:9999/debug/pprof/heap
go tool pprof -text http://localhost:9999/debug/pprof/heap
docker run --rm -it --network=host golang:1.15 go tool pprof -text http://localhost:9999/debug/pprof/profile?seconds=30
go tool pprof -text http://localhost:9999/debug/pprof/profile?seconds=30
```
```
### Full command-line usage
### Full command-line usage
@ -308,11 +346,13 @@ Args:
### Compile and run from source
### Compile and run from source
Install Go ≥ 1.15, download the repository, open a terminal in it and run:
Install Go ≥ 1.15, download the repository, open a terminal in it and run:
```
```
go run .
go run .
```
```
You can perform the entire operation inside Docker with:
You can perform the entire operation inside Docker with:
```
```
make run
make run
```
```
@ -320,6 +360,7 @@ make run
## Links
## Links
Related projects
Related projects
* https://github.com/aler9/gortsplib (RTSP library used internally)
* https://github.com/aler9/gortsplib (RTSP library used internally)
* https://github.com/pion/sdp (SDP library used internally)
* https://github.com/pion/sdp (SDP library used internally)
* https://github.com/pion/rtcp (RTCP library used internally)
* https://github.com/pion/rtcp (RTCP library used internally)