mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-09-28 04:22:07 +08:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7e61ba71f7 | ||
![]() |
d6384dcbd5 | ||
![]() |
2159a6fd9b |
@@ -13,12 +13,15 @@ ListenAddr = ":554"
|
|||||||
BufferLength = 2048
|
BufferLength = 2048
|
||||||
AutoPull = false
|
AutoPull = false
|
||||||
RemoteAddr = "rtsp://localhost/${streamPath}"
|
RemoteAddr = "rtsp://localhost/${streamPath}"
|
||||||
|
[[RTSP.AutoPullList]]
|
||||||
|
URL = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=1&subtype=1"
|
||||||
|
StreamPath = "live/rtsp"
|
||||||
```
|
```
|
||||||
- ListenAddr 是监听端口,可以将rtsp流推到Monibuca中
|
- ListenAddr 是监听端口,可以将rtsp流推到Monibuca中
|
||||||
- BufferLength是指解析拉取的rtp包的缓冲大小
|
- BufferLength是指解析拉取的rtp包的缓冲大小
|
||||||
- AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发
|
- AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发
|
||||||
- RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。
|
- RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。
|
||||||
|
- AutoPullList 是一个数组,如果配置了该数组,则会在程序启动时自动启动拉流,StreamPath一定要是唯一的,不能重复
|
||||||
|
|
||||||
## 使用方法(拉流转发)
|
## 使用方法(拉流转发)
|
||||||
```go
|
```go
|
||||||
|
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/Monibuca/plugin-rtsp
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Monibuca/engine/v2 v2.2.0
|
github.com/Monibuca/engine/v2 v2.2.2
|
||||||
github.com/Monibuca/plugin-rtp v1.0.0
|
github.com/Monibuca/plugin-rtp v1.0.0
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||||
github.com/mattn/go-colorable v0.1.7 // indirect
|
github.com/mattn/go-colorable v0.1.7 // indirect
|
||||||
|
6
go.sum
6
go.sum
@@ -8,8 +8,13 @@ github.com/Monibuca/engine/v2 v2.1.9 h1:IulMIeP24qv8xWaI+tcg233Y7w3mCaLXxt4iQaVp
|
|||||||
github.com/Monibuca/engine/v2 v2.1.9/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
github.com/Monibuca/engine/v2 v2.1.9/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||||
github.com/Monibuca/engine/v2 v2.2.0 h1:A4SyWwzVLegd8Oa6LfSW3LpNfBmWq+MHJJLO55gvaYI=
|
github.com/Monibuca/engine/v2 v2.2.0 h1:A4SyWwzVLegd8Oa6LfSW3LpNfBmWq+MHJJLO55gvaYI=
|
||||||
github.com/Monibuca/engine/v2 v2.2.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
github.com/Monibuca/engine/v2 v2.2.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||||
|
github.com/Monibuca/engine/v2 v2.2.1 h1:I9mcnj9ZABl974n+HKGWe4pFcn9z8kETLVpD1fx2zEI=
|
||||||
|
github.com/Monibuca/engine/v2 v2.2.1/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||||
|
github.com/Monibuca/engine/v2 v2.2.2 h1:ho5M3aFW9Mlj9Lb56Qvk0m+9L8yWc7RhwPh8dRWAeBk=
|
||||||
|
github.com/Monibuca/engine/v2 v2.2.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||||
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb h1:CnmoQ8XsWxs/6mulbQfTGUa8cPr6c/3bkkTsNozRBwE=
|
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb h1:CnmoQ8XsWxs/6mulbQfTGUa8cPr6c/3bkkTsNozRBwE=
|
||||||
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb/go.mod h1:8HxBilkF835Lepe/DLUCjaw1mRiu3MxTDsG7g9UcfZA=
|
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb/go.mod h1:8HxBilkF835Lepe/DLUCjaw1mRiu3MxTDsG7g9UcfZA=
|
||||||
|
github.com/Monibuca/plugin-rtp v1.0.0 h1:yksNsIIGxoKX8UZirkAUK+mGZ/XoEeS2vqbIqtqXyCg=
|
||||||
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc=
|
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc=
|
||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||||
@@ -25,6 +30,7 @@ github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRn
|
|||||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||||
|
github.com/mask-pp/rtp-ps v1.0.0 h1:JFxuJL9N+gD1ldgJlAy3b7rYfY8wAVHi9ODNmdP4+EE=
|
||||||
github.com/mask-pp/rtp-ps v1.0.0/go.mod h1:jCxsZ2G7z/jX+aqFypEWMePnhNrfnUiXUEKm6Xp0vgU=
|
github.com/mask-pp/rtp-ps v1.0.0/go.mod h1:jCxsZ2G7z/jX+aqFypEWMePnhNrfnUiXUEKm6Xp0vgU=
|
||||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
|
27
main.go
27
main.go
@@ -18,12 +18,16 @@ import (
|
|||||||
|
|
||||||
var collection sync.Map
|
var collection sync.Map
|
||||||
var config = struct {
|
var config = struct {
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
AutoPull bool
|
AutoPull bool
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
Timeout int
|
Timeout int
|
||||||
Reconnect bool
|
Reconnect bool
|
||||||
}{":554", false, "rtsp://localhost/${streamPath}", 0, false}
|
AutoPullList []*struct {
|
||||||
|
URL string
|
||||||
|
StreamPath string
|
||||||
|
}
|
||||||
|
}{":554", false, "rtsp://localhost/${streamPath}", 0, false, nil}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
InstallPlugin(&PluginConfig{
|
InstallPlugin(&PluginConfig{
|
||||||
@@ -67,6 +71,13 @@ func runPlugin() {
|
|||||||
w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error())))
|
w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error())))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if len(config.AutoPullList) > 0 {
|
||||||
|
for _, info := range config.AutoPullList {
|
||||||
|
if err := new(RTSP).PullStream(info.StreamPath, info.URL); err != nil {
|
||||||
|
Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if config.ListenAddr != "" {
|
if config.ListenAddr != "" {
|
||||||
log.Fatal(ListenRtsp(config.ListenAddr))
|
log.Fatal(ListenRtsp(config.ListenAddr))
|
||||||
}
|
}
|
||||||
@@ -144,7 +155,8 @@ type RTSP struct {
|
|||||||
UDPClient *UDPClient
|
UDPClient *UDPClient
|
||||||
Auth func(string) string
|
Auth func(string) string
|
||||||
}
|
}
|
||||||
func (rtsp *RTSP) setAudioFormat(){
|
|
||||||
|
func (rtsp *RTSP) setAudioFormat() {
|
||||||
switch rtsp.ASdp.Codec {
|
switch rtsp.ASdp.Codec {
|
||||||
case "aac":
|
case "aac":
|
||||||
rtsp.AudioInfo.SoundFormat = 10
|
rtsp.AudioInfo.SoundFormat = 10
|
||||||
@@ -158,6 +170,7 @@ func (rtsp *RTSP) setAudioFormat(){
|
|||||||
rtsp.AudioInfo.SoundSize = 16
|
rtsp.AudioInfo.SoundSize = 16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RTSPClientInfo struct {
|
type RTSPClientInfo struct {
|
||||||
Agent string
|
Agent string
|
||||||
Session string
|
Session string
|
||||||
|
60
session.go
60
session.go
@@ -319,9 +319,9 @@ func (session *RTSP) handleRequest(req *Request) {
|
|||||||
session.SDPMap = ParseSDP(req.Body)
|
session.SDPMap = ParseSDP(req.Body)
|
||||||
if session.Publish(streamPath) {
|
if session.Publish(streamPath) {
|
||||||
if session.ASdp, session.HasAudio = session.SDPMap["audio"]; session.HasAudio {
|
if session.ASdp, session.HasAudio = session.SDPMap["audio"]; session.HasAudio {
|
||||||
if len(session.ASdp.Control) >0 {
|
if len(session.ASdp.Control) > 0 {
|
||||||
session.WriteASC(session.ASdp.Config)
|
session.WriteASC(session.ASdp.Config)
|
||||||
}else{
|
} else {
|
||||||
session.setAudioFormat()
|
session.setAudioFormat()
|
||||||
}
|
}
|
||||||
Printf("audio codec[%s]\n", session.ASdp.Codec)
|
Printf("audio codec[%s]\n", session.ASdp.Codec)
|
||||||
@@ -379,36 +379,38 @@ func (session *RTSP) handleRequest(req *Request) {
|
|||||||
// res.Status = "Error Status"
|
// res.Status = "Error Status"
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
vPath := ""
|
var vPath, aPath string
|
||||||
if strings.Index(strings.ToLower(session.VSdp.Control), "rtsp://") == 0 {
|
if session.HasVideo {
|
||||||
vControlUrl, err := url.Parse(session.VSdp.Control)
|
if strings.Index(strings.ToLower(session.VSdp.Control), "rtsp://") == 0 {
|
||||||
if err != nil {
|
vControlUrl, err := url.Parse(session.VSdp.Control)
|
||||||
res.StatusCode = 500
|
if err != nil {
|
||||||
res.Status = "Invalid VControl"
|
res.StatusCode = 500
|
||||||
return
|
res.Status = "Invalid VControl"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if vControlUrl.Port() == "" {
|
||||||
|
vControlUrl.Host = fmt.Sprintf("%s:554", vControlUrl.Host)
|
||||||
|
}
|
||||||
|
vPath = vControlUrl.String()
|
||||||
|
} else {
|
||||||
|
vPath = session.VSdp.Control
|
||||||
}
|
}
|
||||||
if vControlUrl.Port() == "" {
|
|
||||||
vControlUrl.Host = fmt.Sprintf("%s:554", vControlUrl.Host)
|
|
||||||
}
|
|
||||||
vPath = vControlUrl.String()
|
|
||||||
} else {
|
|
||||||
vPath = session.VSdp.Control
|
|
||||||
}
|
}
|
||||||
|
if session.HasAudio {
|
||||||
aPath := ""
|
if strings.Index(strings.ToLower(session.ASdp.Control), "rtsp://") == 0 {
|
||||||
if strings.Index(strings.ToLower(session.ASdp.Control), "rtsp://") == 0 {
|
aControlUrl, err := url.Parse(session.ASdp.Control)
|
||||||
aControlUrl, err := url.Parse(session.ASdp.Control)
|
if err != nil {
|
||||||
if err != nil {
|
res.StatusCode = 500
|
||||||
res.StatusCode = 500
|
res.Status = "Invalid AControl"
|
||||||
res.Status = "Invalid AControl"
|
return
|
||||||
return
|
}
|
||||||
|
if aControlUrl.Port() == "" {
|
||||||
|
aControlUrl.Host = fmt.Sprintf("%s:554", aControlUrl.Host)
|
||||||
|
}
|
||||||
|
aPath = aControlUrl.String()
|
||||||
|
} else {
|
||||||
|
aPath = session.ASdp.Control
|
||||||
}
|
}
|
||||||
if aControlUrl.Port() == "" {
|
|
||||||
aControlUrl.Host = fmt.Sprintf("%s:554", aControlUrl.Host)
|
|
||||||
}
|
|
||||||
aPath = aControlUrl.String()
|
|
||||||
} else {
|
|
||||||
aPath = session.ASdp.Control
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?")
|
mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?")
|
||||||
|
Reference in New Issue
Block a user