Browse Source

fix pkg.go.dev readme

pull/169/head
aler9 5 years ago
parent
commit
a3856222c7
  1. 49
      README.md

49
README.md

@ -8,6 +8,7 @@
_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_:
``` ```
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:8554/mystream ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:8554/mystream
``` ```
or _GStreamer_: or _GStreamer_:
``` ```
gst-launch-1.0 filesrc location=file.mp4 ! qtdemux ! rtspclientsink location=rtsp://localhost:8554/mystream gst-launch-1.0 filesrc location=file.mp4 ! qtdemux ! rtspclientsink location=rtsp://localhost:8554/mystream
``` ```
4. Open the stream. For instance, you can open the stream with _VLC_: 4. Open the stream. For instance, you can open the stream with _VLC_:
``` ```
vlc rtsp://localhost:8554/mystream vlc rtsp://localhost:8554/mystream
``` ```
or _GStreamer_: or _GStreamer_:
``` ```
gst-launch-1.0 rtspsrc location=rtsp://localhost:8554/mystream ! rtph264depay ! decodebin ! autovideosink gst-launch-1.0 rtspsrc location=rtsp://localhost:8554/mystream ! rtph264depay ! decodebin ! autovideosink
``` ```
or _FFmpeg_: or _FFmpeg_:
``` ```
ffmpeg -i rtsp://localhost:8554/mystream -c copy output.mp4 ffmpeg -i rtsp://localhost:8554/mystream -c copy output.mp4
``` ```
@ -57,11 +64,13 @@ Features:
### Usage with Docker ### Usage with Docker
Download and launch the image: Download and launch the image:
``` ```
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
``` ```
@ -69,16 +78,19 @@ docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server
### Configuration ### Configuration
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:
``` ```
RTSP_PATHS_TEST_SOURCE=rtsp://myurl ./rtsp-simple-server RTSP_PATHS_TEST_SOURCE=rtsp://myurl ./rtsp-simple-server
``` ```
@ -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
### Serve a Raspberry Pi Camera ### Serve a Raspberry Pi Camera
Install dependencies: Install dependencies:
1. Gstreamer 1. Gstreamer
``` ```
sudo apt install -y gstreamer1.0-tools gstreamer1.0-rtsp sudo apt install -y gstreamer1.0-tools gstreamer1.0-rtsp
``` ```
@ -145,6 +164,7 @@ Install dependencies:
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:
``` ```
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://admin:mypassword@localhost:8554/mystream ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://admin:mypassword@localhost:8554/mystream
``` ```
It's possible to setup authentication for readers too: It's possible to setup authentication for readers too:
```yml ```yml
paths: paths:
all: all:
@ -229,10 +256,12 @@ WARNING: RTSP is a plain protocol, and the credentials can be intercepted and re
Systemd is the service manager used by Ubuntu, Debian and many other Linux distributions, and allows to launch rtsp-simple-server on boot. Systemd is the service manager used by Ubuntu, Debian and many other Linux distributions, and allows to launch rtsp-simple-server on boot.
Download a release bundle from the [release page](https://github.com/aler9/rtsp-simple-server/releases), and put: Download a release bundle from the [release page](https://github.com/aler9/rtsp-simple-server/releases), and put:
* `rtsp-simple-server` in `/usr/local/bin` * `rtsp-simple-server` in `/usr/local/bin`
* `rtsp-simple-server.yml` in `/usr/local/etc` * `rtsp-simple-server.yml` in `/usr/local/etc`
Create a file `/etc/systemd/system/rtsp-simple-server.service` with the following content: Create a file `/etc/systemd/system/rtsp-simple-server.service` with the following content:
``` ```
[Unit] [Unit]
After=network.target After=network.target
@ -243,6 +272,7 @@ WantedBy=multi-user.target
``` ```
Enable and start the service with: Enable and start the service with:
``` ```
systemctl enable rtsp-simple-server systemctl enable rtsp-simple-server
systemctl start rtsp-simple-server systemctl start rtsp-simple-server
@ -251,17 +281,23 @@ systemctl start rtsp-simple-server
### Monitoring ### Monitoring
There are multiple ways to monitor the server usage over time: There are multiple ways to monitor the server usage over time:
* The current number of clients, publishers and readers is printed in each log line; for instance, the line: * The current number of clients, publishers and readers is printed in each log line; for instance, the line:
``` ```
2020/01/01 00:00:00 [2/1/1] [client 127.0.0.1:44428] OPTION 2020/01/01 00:00:00 [2/1/1] [client 127.0.0.1:44428] OPTION
``` ```
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)
@ -328,9 +369,11 @@ Related projects
* https://github.com/flaviostutz/rtsp-relay * https://github.com/flaviostutz/rtsp-relay
IETF Standards IETF Standards
* RTSP 1.0 https://tools.ietf.org/html/rfc2326 * RTSP 1.0 https://tools.ietf.org/html/rfc2326
* RTSP 2.0 https://tools.ietf.org/html/rfc7826 * RTSP 2.0 https://tools.ietf.org/html/rfc7826
* HTTP 1.1 https://tools.ietf.org/html/rfc2616 * HTTP 1.1 https://tools.ietf.org/html/rfc2616
Conventions Conventions
* https://github.com/golang-standards/project-layout * https://github.com/golang-standards/project-layout

Loading…
Cancel
Save