mediamtx/README.md

601 lines
20 KiB
Markdown
Raw Normal View History

2019-12-28 21:07:03 +00:00
2021-02-14 21:50:04 +00:00
<h1 align="center">
<img src="logo.png" alt="rtsp-simple-server">
</h1>
2019-12-28 21:07:03 +00:00
[![Test](https://github.com/aler9/rtsp-simple-server/workflows/test/badge.svg)](https://github.com/aler9/rtsp-simple-server/actions?query=workflow:test)
[![Lint](https://github.com/aler9/rtsp-simple-server/workflows/lint/badge.svg)](https://github.com/aler9/rtsp-simple-server/actions?query=workflow:lint)
2021-02-13 19:13:23 +00:00
[![CodeCov](https://codecov.io/gh/aler9/rtsp-simple-server/branch/main/graph/badge.svg)](https://codecov.io/gh/aler9/rtsp-simple-server/branch/main)
2021-02-14 21:50:04 +00:00
[![Release](https://img.shields.io/github/v/release/aler9/rtsp-simple-server)](https://github.com/aler9/rtsp-simple-server/releases)
[![Docker Hub](https://img.shields.io/badge/docker-aler9/rtsp--simple--server-blue)](https://hub.docker.com/r/aler9/rtsp-simple-server)
2019-12-28 21:12:11 +00:00
2021-05-09 16:13:10 +00:00
_rtsp-simple-server_ is a simple, ready-to-use and zero-dependency RTSP / RTMP / HLS server and proxy, a software that allows users to publish, read and proxy live video and audio streams. RTSP, RTMP and HLS are independent protocols that allows 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; in particular:
* RTSP is the fastest way to publish and receive streams
2021-05-17 09:19:26 +00:00
* RTMP allows to interact with legacy servers or software (like OBS Studio)
2021-05-09 16:13:10 +00:00
* HLS allows to embed streams into a web page
2019-12-28 21:07:03 +00:00
2019-12-28 22:46:32 +00:00
Features:
2020-11-15 09:29:04 +00:00
2021-05-09 16:13:10 +00:00
* Publish live streams with RTSP (UDP, TCP or TLS mode) or RTMP
* Read live streams with RTSP (UDP, UDP-multicast, TCP or TLS mode), RTMP or HLS
2021-05-09 16:13:10 +00:00
* Pull and serve streams from other RTSP or RTMP servers or cameras, always or on-demand (RTSP proxy)
* Each stream can have multiple video and audio tracks, encoded with any codec, including H264, H265, VP8, VP9, MPEG2, MP3, AAC, Opus, PCM, JPEG
* Streams are automatically converted from a protocol to another. For instance, it's possible to publish with RTSP and read with HLS
Plus:
2020-10-28 21:58:04 +00:00
* Serve multiple streams at once in separate paths
2021-02-03 20:38:27 +00:00
* Authenticate readers and publishers
2021-02-13 19:13:23 +00:00
* Redirect readers to other RTSP servers (load balancing)
* Query and control the server through an HTTP API
2020-09-07 06:32:38 +00:00
* Run custom commands when clients connect, disconnect, read or publish streams
2020-10-28 21:58:04 +00:00
* Reload the configuration without disconnecting existing clients (hot reloading)
* Compatible with Linux, Windows and macOS, does not require any dependency or interpreter, it's a single executable
2019-12-28 21:07:03 +00:00
2020-12-12 22:48:06 +00:00
## Table of contents
* [Installation](#installation)
* [Standard](#standard)
* [Docker](#docker)
* [Basic usage](#basic-usage)
* [Advanced usage and FAQs](#advanced-usage-and-faqs)
* [Configuration](#configuration)
2020-12-13 22:43:31 +00:00
* [Encryption](#encryption)
2020-12-31 18:47:25 +00:00
* [Authentication](#authentication)
* [Encrypt the configuration](#encrypt-the-configuration)
2021-03-19 22:08:47 +00:00
* [Proxy mode](#proxy-mode)
2021-03-10 14:06:45 +00:00
* [RTMP protocol](#rtmp-protocol)
2021-05-09 16:13:10 +00:00
* [HLS protocol](#hls-protocol)
2021-03-19 22:08:47 +00:00
* [Publish from OBS Studio](#publish-from-obs-studio)
2020-12-12 22:48:06 +00:00
* [Publish a webcam](#publish-a-webcam)
* [Publish a Raspberry Pi Camera](#publish-a-raspberry-pi-camera)
* [Remuxing, re-encoding, compression](#remuxing-re-encoding-compression)
* [On-demand publishing](#on-demand-publishing)
* [Redirect to another server](#redirect-to-another-server)
* [Fallback stream](#fallback-stream)
* [Start on boot with systemd](#start-on-boot-with-systemd)
* [Monitoring](#monitoring)
2021-06-19 10:33:06 +00:00
* [Corrupted frames](#corrupted-frames)
* [HTTP API](#http-api)
2020-12-12 22:48:06 +00:00
* [Command-line usage](#command-line-usage)
* [Compile and run from source](#compile-and-run-from-source)
* [Links](#links)
## Installation
### Standard
2019-12-28 21:07:03 +00:00
1. Download and extract a precompiled binary from the [release page](https://github.com/aler9/rtsp-simple-server/releases).
2019-12-28 21:07:03 +00:00
2020-06-14 15:54:52 +00:00
2. Start the server:
2020-11-15 09:29:04 +00:00
2019-12-28 21:07:03 +00:00
```
./rtsp-simple-server
```
2020-12-12 22:48:06 +00:00
### Docker
Download and launch the image:
```
docker run --rm -it --network=host aler9/rtsp-simple-server
```
The `--network=host` flag is mandatory since Docker can change the source port of UDP packets for routing reasons, and this doesn't allow to find out the publisher of the packets. This issue can be avoided by disabling UDP and exposing the RTSP port:
2020-12-12 22:48:06 +00:00
```
2021-03-10 19:53:50 +00:00
docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 -p 1935:1935 aler9/rtsp-simple-server
2020-12-12 22:48:06 +00:00
```
## Basic usage
1. Publish a stream. For instance, you can publish a video/audio file with _FFmpeg_:
2020-11-15 09:29:04 +00:00
2019-12-28 21:07:03 +00:00
```
2019-12-31 13:55:46 +00:00
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:8554/mystream
2019-12-28 21:07:03 +00:00
```
or _GStreamer_:
2020-11-15 09:29:04 +00:00
```
gst-launch-1.0 rtspclientsink name=s location=rtsp://localhost:8554/mystream filesrc location=file.mp4 ! qtdemux name=d d.video_0 ! queue ! s.sink_0 d.audio_0 ! queue ! s.sink_1
```
2020-12-12 22:48:06 +00:00
2. Open the stream. For instance, you can open the stream with _VLC_:
2020-11-15 09:29:04 +00:00
2019-12-28 21:07:03 +00:00
```
2019-12-31 13:55:46 +00:00
vlc rtsp://localhost:8554/mystream
2019-12-28 21:07:03 +00:00
```
2020-06-08 12:19:49 +00:00
or _GStreamer_:
2020-11-15 09:29:04 +00:00
2019-12-28 21:07:03 +00:00
```
gst-launch-1.0 rtspsrc location=rtsp://localhost:8554/mystream name=s s. ! application/x-rtp,media=video ! decodebin ! autovideosink s. ! application/x-rtp,media=audio ! decodebin ! audioconvert ! audioresample ! autoaudiosink
2019-12-28 21:07:03 +00:00
```
2020-06-08 12:19:49 +00:00
or _FFmpeg_:
2020-11-15 09:29:04 +00:00
2020-06-08 12:19:49 +00:00
```
ffmpeg -i rtsp://localhost:8554/mystream -c copy output.mp4
```
2020-06-14 15:54:52 +00:00
## Advanced usage and FAQs
2020-10-07 19:06:27 +00:00
### Configuration
2020-12-13 22:43:31 +00:00
All the configuration parameters are listed and commented in the [configuration file](rtsp-simple-server.yml).
2020-11-15 09:29:04 +00:00
2020-12-13 22:43:31 +00:00
There are two ways to change the configuration:
2020-12-13 22:43:31 +00:00
* By editing the `rtsp-simple-server.yml` file, that is
2020-11-15 09:29:04 +00:00
2020-12-13 22:43:31 +00:00
* included into the release bundle
* available in the root folder of the Docker image (`/rtsp-simple-server.yml`); it can be overridden in this way:
```
docker run --rm -it --network=host -v $PWD/rtsp-simple-server.yml:/rtsp-simple-server.yml aler9/rtsp-simple-server
```
2020-12-13 22:43:31 +00:00
* By overriding configuration parameters with environment variables, in the format `RTSP_PARAMNAME`, where `PARAMNAME` is the uppercase name of a parameter. For instance, the `rtspAddress` parameter can be overridden in the following way:
2020-12-13 22:43:31 +00:00
```
RTSP_RTSPADDRESS="127.0.0.1:8554" ./rtsp-simple-server
2020-12-13 22:43:31 +00:00
```
Parameters in maps can be overridden by using underscores, in the following way:
```
RTSP_PATHS_TEST_SOURCE=rtsp://myurl ./rtsp-simple-server
```
This method is particularly useful when using Docker; any configuration parameter can be changed by passing environment variables with the `-e` flag:
2020-12-13 22:43:31 +00:00
```
docker run --rm -it --network=host -e RTSP_PATHS_TEST_SOURCE=rtsp://myurl aler9/rtsp-simple-server
```
The configuration can be changed dinamically when the server is running (hot reloading) by writing to the configuration file. Changes are detected and applied without disconnecting existing clients, whenever it's possible.
### Encryption
Incoming and outgoing streams can be encrypted with TLS (obtaining the RTSPS protocol). A self-signed TLS certificate is needed and can be generated with openSSL:
2020-12-13 22:43:31 +00:00
```
openssl genrsa -out server.key 2048
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
```
2020-12-13 22:43:31 +00:00
Edit `rtsp-simple-server.yml`, and set the `protocols`, `encrypt`, `serverKey` and `serverCert` parameters:
```yml
protocols: [tcp]
encryption: optional
serverKey: server.key
serverCert: server.crt
```
2020-12-17 13:36:38 +00:00
Streams can then be published and read with the `rtsps` scheme and the `8555` port:
2020-11-15 09:29:04 +00:00
2020-10-13 22:05:10 +00:00
```
2020-12-14 22:32:24 +00:00
ffmpeg -i rtsps://ip:8555/...
2020-10-13 22:05:10 +00:00
```
If the client is _GStreamer_, disable the certificate validation:
2020-12-13 22:43:31 +00:00
```
2020-12-14 22:32:24 +00:00
gst-launch-1.0 rtspsrc location=rtsps://ip:8555/... tls-validation-flags=0
2020-12-13 22:43:31 +00:00
```
If the client is _VLC_, encryption can't be deployed, since _VLC_ doesn't support it.
2020-12-31 18:47:25 +00:00
### Authentication
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
paths:
all:
2021-01-31 20:58:59 +00:00
publishUser: myuser
publishPass: mypass
2020-12-31 18:47:25 +00:00
```
Only publishers that provide both username and password will be able to proceed:
```
2021-01-31 20:58:59 +00:00
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://myuser:mypass@localhost:8554/mystream
2020-12-31 18:47:25 +00:00
```
It's possible to setup authentication for readers too:
```yml
paths:
all:
2021-01-31 20:58:59 +00:00
publishUser: myuser
2020-12-31 18:47:25 +00:00
publishPass: mypass
readUser: user
readPass: userpass
```
If storing plain credentials in the configuration file is a security problem, username and passwords can be stored as sha256-hashed strings; a string must be hashed with sha256 and encoded with base64:
2020-12-31 18:47:25 +00:00
```
echo -n "userpass" | openssl dgst -binary -sha256 | openssl base64
```
Then stored with the `sha256:` prefix:
```yml
paths:
all:
readUser: sha256:j1tsRqDEw9xvq/D7/9tMx6Jh/jMhk3UfjwIB2f1zgMo=
readPass: sha256:BdSWkrdV+ZxFBLUQQY7+7uv9RmiSVA8nrPmjGjJtZQQ=
```
**WARNING**: enable encryption or use a VPN to ensure that no one is intercepting the credentials.
2020-12-31 18:47:25 +00:00
### Encrypt the configuration
The configuration file can be entirely encrypted for security purposes.
An online encryption tool is [available here](https://play.golang.org/p/rX29jwObNe4).
The encryption procedure is the following:
1. NaCL's `crypto_secretbox` function is applied to the content of the configuration. NaCL is a cryptographic library available for [C/C++](https://nacl.cr.yp.to/secretbox.html), [Go](https://pkg.go.dev/golang.org/x/crypto/nacl/secretbox), [C#](https://github.com/somdoron/NaCl.net) and many other languages;
2. The string is prefixed with the nonce;
3. The string is encoded with base64.
After performing the encryption, it's enough to put the base64-encoded result into the configuration file, and launch the server with the `RTSP_CONFKEY` variable:
```
RTSP_CONFKEY=mykey ./rtsp-simple-server
```
2021-03-19 22:08:47 +00:00
### Proxy mode
2021-02-03 20:38:27 +00:00
_rtsp-simple-server_ is also a RTSP and RTMP proxy, that is usually deployed in one of these scenarios:
2020-11-15 09:29:04 +00:00
2020-09-28 12:14:11 +00:00
* 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.
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
2020-06-27 19:22:50 +00:00
paths:
proxied:
# url of the source stream, in the format rtsp://user:pass@host:port/path
source: rtsp://original-url
```
2020-06-27 19:22:50 +00:00
2020-12-06 18:45:16 +00:00
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:
```yml
paths:
proxied1:
source: rtsp://url1
proxied2:
source: rtsp://url1
```
2020-11-01 22:19:58 +00:00
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:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
paths:
proxied:
source: rtsp://original-url
sourceOnDemand: yes
```
2021-03-10 14:06:45 +00:00
### RTMP protocol
RTMP is a protocol that is used to read and publish streams, but is less versatile and less efficient than RTSP (doesn't support UDP, encryption, doesn't support most RTSP codecs, doesn't support feedback mechanism). It is used when there's need of publishing or reading streams from a software that supports only RTMP (for instance, OBS Studio and DJI drones).
2021-01-31 20:58:59 +00:00
2021-03-10 22:13:53 +00:00
At the moment, only the H264 and AAC codecs can be used with the RTMP protocol.
2021-01-31 20:58:59 +00:00
Streams can be published or read with the RTMP protocol, for instance with _FFmpeg_:
2021-01-31 20:58:59 +00:00
```
2021-01-31 22:51:19 +00:00
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f flv rtmp://localhost/mystream
2021-01-31 20:58:59 +00:00
```
or _GStreamer_:
```
gst-launch-1.0 -v flvmux name=s ! rtmpsink location=rtmp://localhost/mystream filesrc location=file.mp4 ! qtdemux name=d d.video_0 ! queue ! s.video d.audio_0 ! queue ! s.audio
```
Credentials can be provided by appending to the URL the `user` and `pass` parameters:
```
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f flv rtmp://localhost:8554/mystream?user=myuser&pass=mypass
```
2021-05-09 16:13:10 +00:00
### HLS protocol
HLS is a media format that allows to embed live streams into web pages, inside standard `<video>` HTML tags. Every stream published to the server can be accessed with a web browser by visiting
```
http://localhost:8888/mystream
```
where `mystream` is the name of a stream that is being published.
2021-03-19 22:08:47 +00:00
### Publish from OBS Studio
2021-03-26 18:04:41 +00:00
In `Settings -> Stream` (or in the Auto-configuration Wizard), use the following parameters:
2021-03-19 22:08:47 +00:00
2021-03-26 18:04:41 +00:00
* Service: `Custom...`
* Server: `rtmp://localhost`
* Stream key: `mystream`
2021-03-19 22:08:47 +00:00
If credentials are in use, use the following parameters:
2021-03-26 18:04:41 +00:00
* Service: `Custom...`
* Server: `rtmp://localhost`
* Stream key: `mystream?user=myuser&pass=mypass`
2021-03-19 22:08:47 +00:00
2020-11-25 09:04:32 +00:00
### Publish a webcam
2020-07-19 13:41:24 +00:00
2020-07-31 16:12:42 +00:00
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
2020-07-31 16:12:42 +00:00
paths:
2020-09-05 08:02:48 +00:00
cam:
2021-03-19 22:08:47 +00:00
runOnInit: ffmpeg -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH
runOnInitRestart: yes
2020-07-19 13:41:24 +00:00
```
If the platform is Windows:
2020-11-15 09:29:04 +00:00
```yml
paths:
cam:
runOnInit: ffmpeg -f dshow -i video="USB2.0 HD UVC WebCam" -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH
runOnInitRestart: yes
```
Where `USB2.0 HD UVC WebCam` is the name of your webcam, that can be obtained with:
```
ffmpeg -list_devices true -f dshow -i dummy
```
After starting the server, the webcam can be reached on `rtsp://localhost:8554/cam`.
2020-09-05 08:02:48 +00:00
2020-11-25 09:04:32 +00:00
### Publish a Raspberry Pi Camera
2020-09-05 08:02:48 +00:00
Install dependencies:
2020-11-15 09:29:04 +00:00
2020-09-05 08:02:48 +00:00
1. Gstreamer
2020-11-15 09:29:04 +00:00
2020-09-05 08:02:48 +00:00
```
sudo apt install -y gstreamer1.0-tools gstreamer1.0-rtsp
```
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:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
2020-09-05 08:02:48 +00:00
paths:
cam:
2021-04-03 20:12:18 +00:00
runOnInit: gst-launch-1.0 rpicamsrc preview=false bitrate=2000000 keyframe-interval=50 ! video/x-h264,width=1920,height=1080,framerate=25/1 ! h264parse ! rtspclientsink location=rtsp://localhost:$RTSP_PORT/$RTSP_PATH
runOnInitRestart: yes
2020-09-05 08:02:48 +00:00
```
2021-04-03 20:12:18 +00:00
After starting the server, the camera is available on `rtsp://localhost:8554/cam`.
2020-07-19 13:41:24 +00:00
2020-08-17 17:12:07 +00:00
### Remuxing, re-encoding, compression
2020-07-19 13:41:24 +00:00
2020-11-01 22:19:58 +00:00
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:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
2020-07-19 13:41:24 +00:00
paths:
all:
original:
2020-11-19 20:57:15 +00:00
runOnPublish: ffmpeg -i rtsp://localhost:$RTSP_PORT/$RTSP_PATH -c:v libx264 -preset ultrafast -b:v 500k -max_muxing_queue_size 1024 -f rtsp rtsp://localhost:$RTSP_PORT/compressed
runOnPublishRestart: yes
2020-07-19 13:41:24 +00:00
```
2020-11-19 20:57:15 +00:00
### On-demand publishing
Edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
```yml
paths:
ondemand:
runOnDemand: ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH
runOnDemandRestart: yes
```
The command inserted into `runOnDemand` will start only when a client requests the path `ondemand`, therefore the file will start streaming only when requested.
2020-11-03 11:19:10 +00:00
### Redirect to another server
2020-11-01 22:19:58 +00:00
2020-11-03 11:19:10 +00:00
To redirect to another server, use the `redirect` source:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
paths:
redirected:
source: redirect
sourceRedirect: rtsp://otherurl/otherpath
```
### Fallback stream
2021-02-09 21:33:50 +00:00
If no one is publishing to the server, readers can be redirected to a fallback path or URL that is serving a fallback stream:
2020-11-15 09:29:04 +00:00
2020-11-01 22:19:58 +00:00
```yml
paths:
withfallback:
2021-02-09 21:33:50 +00:00
fallback: /otherpath
2020-11-01 22:19:58 +00:00
```
2020-08-17 17:12:07 +00:00
### Start on boot with systemd
Systemd is the service manager used by Ubuntu, Debian and many other Linux distributions, and allows to launch rtsp-simple-server on boot.
2020-12-03 15:17:18 +00:00
Download a release bundle from the [release page](https://github.com/aler9/rtsp-simple-server/releases), unzip it, and move the executable and configuration in the system:
2020-11-15 09:29:04 +00:00
2020-12-03 15:17:18 +00:00
```
sudo mv rtsp-simple-server /usr/local/bin/
sudo mv rtsp-simple-server.yml /usr/local/etc/
```
2020-12-03 15:17:18 +00:00
Create the service:
2020-11-15 09:29:04 +00:00
```
2020-12-03 15:17:18 +00:00
sudo tee /etc/systemd/system/rtsp-simple-server.service >/dev/null << EOF
[Unit]
After=network.target
[Service]
ExecStart=/usr/local/bin/rtsp-simple-server /usr/local/etc/rtsp-simple-server.yml
[Install]
WantedBy=multi-user.target
2020-12-03 15:17:18 +00:00
EOF
```
2020-12-03 15:17:18 +00:00
Enable and start the service:
2020-11-15 09:29:04 +00:00
```
2020-12-03 15:17:18 +00:00
sudo systemctl enable rtsp-simple-server
sudo systemctl start rtsp-simple-server
```
2020-08-17 17:12:07 +00:00
### Monitoring
2020-07-30 15:30:50 +00:00
There are multiple ways to monitor the server usage over time:
2020-11-15 09:29:04 +00:00
2020-07-30 15:30:50 +00:00
* The current number of clients, publishers and readers is printed in each log line; for instance, the line:
2020-11-15 09:29:04 +00:00
2020-07-30 15:30:50 +00:00
```
2021-05-09 15:22:24 +00:00
2020/01/01 00:00:00 [3/2] [conn 127.0.0.1:44428] OPTION
2020-07-30 15:30:50 +00:00
```
2020-11-15 09:29:04 +00:00
2021-05-08 20:52:10 +00:00
means that there are 3 publishers and 2 readers.
2020-07-30 15:30:50 +00:00
2020-10-28 22:03:44 +00:00
* 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:
2020-11-15 09:29:04 +00:00
2020-07-30 15:30:50 +00:00
```
wget -qO- localhost:9998/metrics
2020-07-30 15:30:50 +00:00
```
2020-11-15 09:29:04 +00:00
2020-07-30 15:30:50 +00:00
Obtaining:
2020-11-15 09:29:04 +00:00
2020-07-30 15:30:50 +00:00
```
2020-09-19 21:37:54 +00:00
rtsp_clients{state="publishing"} 15 1596122687740
rtsp_clients{state="reading"} 8 1596122687740
2020-10-05 20:06:32 +00:00
rtsp_sources{type="rtsp",state="idle"} 3 1596122687740
rtsp_sources{type="rtsp",state="running"} 2 1596122687740
rtsp_sources{type="rtmp",state="idle"} 1 1596122687740
rtsp_sources{type="rtmp",state="running"} 0 1596122687740
2020-07-30 15:30:50 +00:00
```
2020-09-19 21:39:41 +00:00
where:
2020-11-15 09:29:04 +00:00
2020-09-19 21:39:41 +00:00
* `rtsp_clients{state="publishing"}` is the count of clients that are publishing
* `rtsp_clients{state="reading"}` is the count of clients that are reading
2020-10-03 19:10:41 +00:00
* `rtsp_sources{type="rtsp",state="idle"}` is the count of rtsp sources that are not running
* `rtsp_sources{type="rtsp",state="running"}` is the count of rtsp sources that are running
* `rtsp_sources{type="rtmp",state="idle"}` is the count of rtmp sources that are not running
* `rtsp_sources{type="rtmp",state="running"}` is the count of rtmp sources that are running
2020-09-19 21:39:41 +00:00
2020-10-28 22:03:44 +00:00
* 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:
2020-11-15 09:29:04 +00:00
2020-07-30 15:30:50 +00:00
```
2020-11-15 09:29:04 +00:00
go tool pprof -text http://localhost:9999/debug/pprof/goroutine
go tool pprof -text http://localhost:9999/debug/pprof/heap
go tool pprof -text http://localhost:9999/debug/pprof/profile?seconds=30
2020-07-30 15:30:50 +00:00
```
2020-06-27 20:16:43 +00:00
2021-06-19 10:33:06 +00:00
### Corrupted frames
In some scenarios, the server can send incomplete or corrupted frames. This can be caused by multiple reasons:
* the packet buffer of the server is too small and can't handle the stream throughput. A solution consists in increasing its size:
```yml
readBufferCount: 1024
```
* The stream throughput is too big and the stream can't be sent correctly with the UDP stream protocol. UDP is more performant, faster and more efficient than TCP, but doesn't have a retransmission mechanism, that is needed in case of streams that need a large bandwidth. A solution consists in switching to TCP:
```yml
protocols: [tcp]
```
In case the source is a camera:
```yml
paths:
test:
source: rtsp://..
sourceProtocol: tcp
```
* the software that is generating the stream (a camera or FFmpeg) is generating non-conformant RTP packets, with a payload bigger than the maximum allowed (that is 1460 due to the UDP MTU). A solution consists in increasing the buffer size:
```yml
readBufferSize: 8192
```
### HTTP API
TODO
2020-12-12 22:48:06 +00:00
### Command-line usage
2019-12-28 21:07:03 +00:00
```
usage: rtsp-simple-server [<flags>]
2020-01-03 21:39:55 +00:00
rtsp-simple-server v0.0.0
2019-12-28 21:07:03 +00:00
RTSP server.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--version print version
Args:
2020-10-13 23:19:14 +00:00
[<confpath>] path to a config file. The default is rtsp-simple-server.yml.
2019-12-28 21:07:03 +00:00
```
2020-08-17 17:12:07 +00:00
### Compile and run from source
2020-06-14 15:54:52 +00:00
2021-06-19 16:59:33 +00:00
Install Go 1.16, download the repository, open a terminal in it and run:
2020-11-15 09:29:04 +00:00
2020-06-14 15:54:52 +00:00
```
2020-06-14 20:07:03 +00:00
go run .
2020-06-14 15:54:52 +00:00
```
2020-12-03 15:17:18 +00:00
You can perform the entire operation inside Docker:
2020-11-15 09:29:04 +00:00
2020-06-14 15:54:52 +00:00
```
make run
```
2019-12-28 21:07:03 +00:00
## Links
2020-01-20 22:04:12 +00:00
Related projects
2020-11-15 09:29:04 +00:00
2020-07-30 12:07:20 +00:00
* https://github.com/aler9/gortsplib (RTSP library used internally)
* https://github.com/pion/sdp (SDP library used internally)
* https://github.com/pion/rtcp (RTCP library used internally)
2020-10-06 16:55:58 +00:00
* https://github.com/pion/rtp (RTP library used internally)
* https://github.com/notedit/rtmp (RTMP library used internally)
* https://github.com/flaviostutz/rtsp-relay
2020-01-20 22:04:12 +00:00
IETF Standards
2020-11-15 09:29:04 +00:00
* RTSP 1.0 https://tools.ietf.org/html/rfc2326
* RTSP 2.0 https://tools.ietf.org/html/rfc7826
* HTTP 1.1 https://tools.ietf.org/html/rfc2616
2020-11-05 10:39:35 +00:00
Conventions
2020-11-15 09:29:04 +00:00
2020-11-05 10:39:35 +00:00
* https://github.com/golang-standards/project-layout