Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reading with WebRTC #1242

Merged
merged 13 commits into from
Dec 15, 2022
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
<img src="logo.png" alt="rtsp-simple-server">
</p>

_rtsp-simple-server_ is a ready-to-use and zero-dependency server and proxy that allows users to publish, read and proxy live video and audio streams through various protocols:
_rtsp-simple-server_ is a ready-to-use and zero-dependency server and proxy that allows users to publish, read and proxy live video and audio streams.

|protocol|description|variants|publish|read|proxy|
|--------|-----------|--------|-------|----|-----|
|RTSP|fastest way to publish and read streams|RTSP, RTSPS|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|RTMP|allows to interact with legacy software|RTMP, RTMPS|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|HLS|allows to embed streams into a web page|Low-Latency HLS, standard HLS|:x:|:heavy_check_mark:|:heavy_check_mark:|
Live streams can be published to the server with:

|protocol|variants|codecs|
|--------|--------|------|
|RTSP clients (FFmpeg, GStreamer, etc)|UDP, TCP, RTSPS|H264, H265, VP8, VP9, AV1, MPEG2, JPEG, MP3, MPEG4 Audio (AAC), Opus, G711, G722, LPCM and any RTP-compatible codec|
|RTSP servers and cameras|UDP, UDP-Multicast, TCP, RTSPS|H264, H265, VP8, VP9, AV1, MPEG2, JPEG, MP3, MPEG4 Audio (AAC), Opus, G711, G722, LPCM and any RTP-compatible codec|
|RTMP clients (OBS Studio)|RTMP, RTMPS|H264, MPEG4 Audio (AAC)|
|RTMP servers and cameras|RTMP, RTMPS|H264, MPEG4 Audio (AAC)|
|HLS servers and cameras|Low-Latency HLS, MP4-based HLS, legacy HLS|H264, MPEG4 Audio (AAC)|
|Raspberry Pi Cameras||H264|

And can be read from the server with:

|protocol|variants|codecs|
|--------|--------|------|
|RTSP|UDP, UDP-Multicast, TCP, RTSPS|H264, H265, VP8, VP9, AV1, MPEG2, JPEG, MP3, MPEG4 Audio (AAC), Opus, G711, G722, LPCM and any RTP-compatible codec|
|RTMP|RTMP, RTMPS|H264, MPEG4 Audio (AAC)|
|HLS|Low-Latency HLS, MP4-based HLS, legacy HLS|H264, MPEG4 Audio (AAC)|
|WebRTC||H264, VP8, VP9, Opus, G711, G722|

Features:

* Publish live streams to the server
* Read live streams from the server
* Proxy streams from other servers or cameras, always or on-demand
* Each stream can have multiple video and audio tracks, encoded with any RTP-compatible 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 a stream with RTSP and read it with HLS
* Serve multiple streams at once in separate paths
* Authenticate users; use internal or external authentication
Expand Down Expand Up @@ -446,6 +459,10 @@ Obtaining:
paths{name="[path_name]",state="[state]"} 1
paths_bytes_received{name="[path_name]",state="[state]"} 1234

# metrics of every HLS muxer
hls_muxers{name="[name]"} 1
hls_muxers_bytes_sent{name="[name]"} 187

# metrics of every RTSP connection
rtsp_conns{id="[id]"} 1
rtsp_conns_bytes_received{id="[id]"} 1234
Expand All @@ -471,9 +488,10 @@ rtmp_conns{id="[id]",state="[state]"} 1
rtmp_conns_bytes_received{id="[id]",state="[state]"} 1234
rtmp_conns_bytes_sent{id="[id]",state="[state]"} 187

# metrics of every HLS muxer
hls_muxers{name="[name]"} 1
hls_muxers_bytes_sent{name="[name]"} 187
# metrics of every WebRTC connection
webrtc_conns{id="[id]"} 1
webrtc_conns_bytes_received{id="[id]",state="[state]"} 1234
webrtc_conns_bytes_sent{id="[id]",state="[state]"} 187
```

### pprof
Expand Down
111 changes: 84 additions & 27 deletions apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ components:
bytesSent:
type: number

HLSMuxersList:
type: object
properties:
items:
type: object
additionalProperties:
$ref: '#/components/schemas/HLSMuxer'

PathsList:
type: object
properties:
Expand All @@ -437,6 +445,14 @@ components:
additionalProperties:
$ref: '#/components/schemas/Path'

RTMPConnsList:
type: object
properties:
items:
type: object
additionalProperties:
$ref: '#/components/schemas/RTMPConn'

RTSPConnsList:
type: object
properties:
Expand All @@ -461,21 +477,25 @@ components:
additionalProperties:
$ref: '#/components/schemas/RTSPSession'

RTMPConnsList:
WebRTCConn:
type: object
properties:
items:
type: object
additionalProperties:
$ref: '#/components/schemas/RTMPConn'
created:
type: string
remoteAddr:
type: string
bytesReceived:
type: number
bytesSent:
type: number

HLSMuxersList:
WebRTCConnsList:
type: object
properties:
items:
type: object
additionalProperties:
$ref: '#/components/schemas/HLSMuxer'
$ref: '#/components/schemas/WebRTCConn'

paths:
/v1/config/get:
Expand Down Expand Up @@ -586,69 +606,69 @@ paths:
'500':
description: internal server error.

/v1/paths/list:
/v1/hlsmuxers/list:
get:
operationId: pathsList
summary: returns all paths.
operationId: hlsMuxersList
summary: returns all HLS muxers.
description: ''
responses:
'200':
description: the request was successful.
content:
application/json:
schema:
$ref: '#/components/schemas/PathsList'
$ref: '#/components/schemas/HLSMuxersList'
'400':
description: invalid request.
'500':
description: internal server error.

/v1/rtspconns/list:
/v1/paths/list:
get:
operationId: rtspConnsList
summary: returns all RTSP connections.
operationId: pathsList
summary: returns all paths.
description: ''
responses:
'200':
description: the request was successful.
content:
application/json:
schema:
$ref: '#/components/schemas/RTSPConnsList'
$ref: '#/components/schemas/PathsList'
'400':
description: invalid request.
'500':
description: internal server error.

/v1/rtspsessions/list:
/v1/rtspconns/list:
get:
operationId: rtspSessionsList
summary: returns all RTSP sessions.
operationId: rtspConnsList
summary: returns all RTSP connections.
description: ''
responses:
'200':
description: the request was successful.
content:
application/json:
schema:
$ref: '#/components/schemas/RTSPSessionsList'
$ref: '#/components/schemas/RTSPConnsList'
'400':
description: invalid request.
'500':
description: internal server error.

/v1/rtspsconns/list:
/v1/rtspsessions/list:
get:
operationId: rtspsConnsList
summary: returns all RTSPS connections.
operationId: rtspSessionsList
summary: returns all RTSP sessions.
description: ''
responses:
'200':
description: the request was successful.
content:
application/json:
schema:
$ref: '#/components/schemas/RTSPConnsList'
$ref: '#/components/schemas/RTSPSessionsList'
'400':
description: invalid request.
'500':
Expand All @@ -674,6 +694,23 @@ paths:
'500':
description: internal server error.

/v1/rtspsconns/list:
get:
operationId: rtspsConnsList
summary: returns all RTSPS connections.
description: ''
responses:
'200':
description: the request was successful.
content:
application/json:
schema:
$ref: '#/components/schemas/RTSPConnsList'
'400':
description: invalid request.
'500':
description: internal server error.

/v1/rtspssessions/list:
get:
operationId: rtspsSessionsList
Expand Down Expand Up @@ -785,18 +822,38 @@ paths:
'500':
description: internal server error.

/v1/hlsmuxers/list:
/v1/webrtcconns/list:
get:
operationId: hlsMuxersList
summary: returns all HLS muxers.
operationId: webrtcConnsList
summary: returns all WebRTC connections.
description: ''
responses:
'200':
description: the request was successful.
content:
application/json:
schema:
$ref: '#/components/schemas/HLSMuxersList'
$ref: '#/components/schemas/WebRTCConnsList'
'400':
description: invalid request.
'500':
description: internal server error.

/v1/webrtcconns/kick/{id}:
post:
operationId: webrtcConnsKick
summary: kicks out a WebRTC connection from the server.
description: ''
parameters:
- name: id
in: path
required: true
description: the ID of the session.
schema:
type: string
responses:
'200':
description: the request was successful.
'400':
description: invalid request.
'500':
Expand Down
28 changes: 21 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ go 1.18
require (
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
github.com/abema/go-mp4 v0.8.0
github.com/aler9/gortsplib/v2 v2.0.0-20221214165733-d43cb0455e33
github.com/aler9/gortsplib/v2 v2.0.0-20221214210611-e1c07a1c8d71
github.com/asticode/go-astits v1.10.1-0.20220319093903-4abe66a9b757
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.8.1
github.com/google/uuid v1.1.2
github.com/google/uuid v1.3.0
github.com/gookit/color v1.4.2
github.com/gorilla/websocket v1.5.0
github.com/grafov/m3u8 v0.11.1
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/notedit/rtmp v0.0.2
github.com/orcaman/writerseeker v0.0.0
github.com/pion/rtp v1.7.13
github.com/pion/webrtc/v3 v3.1.47
github.com/stretchr/testify v1.7.1
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -38,14 +40,26 @@ require (
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pion/datachannel v1.5.2 // indirect
github.com/pion/dtls/v2 v2.1.5 // indirect
github.com/pion/ice/v2 v2.2.11 // indirect
github.com/pion/interceptor v0.1.11 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.5 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.9 // indirect
github.com/pion/sdp/v3 v3.0.5 // indirect
github.com/pion/rtcp v1.2.10 // indirect
github.com/pion/sctp v1.8.2 // indirect
github.com/pion/sdp/v3 v3.0.6 // indirect
github.com/pion/srtp/v2 v2.0.10 // indirect
github.com/pion/stun v0.3.5 // indirect
github.com/pion/transport v0.13.1 // indirect
github.com/pion/turn/v2 v2.0.8 // indirect
github.com/pion/udp v0.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
Loading