forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (47 loc) · 1.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"log"
"github.com/cobalt-robotics/gortsplib"
"github.com/cobalt-robotics/gortsplib/pkg/url"
)
// This example shows how to
// 1. connect to a RTSP server and read all tracks on a path
// 2. re-publish all tracks on another path.
func main() {
reader := gortsplib.Client{}
// parse source URL
sourceURL, err := url.Parse("rtsp://localhost:8554/mystream")
if err != nil {
panic(err)
}
// connect to the server
err = reader.Start(sourceURL.Scheme, sourceURL.Host)
if err != nil {
panic(err)
}
defer reader.Close()
// find published tracks
tracks, baseURL, _, err := reader.Describe(sourceURL)
if err != nil {
panic(err)
}
log.Printf("republishing %d tracks", len(tracks))
publisher := gortsplib.Client{}
// connect to the server and start publishing
err = publisher.StartPublishing("rtsp://localhost:8554/mystream2", tracks)
if err != nil {
panic(err)
}
defer publisher.Close()
// called when a RTP packet arrives
reader.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
publisher.WritePacketRTP(ctx.TrackID, ctx.Packet, ctx.PTSEqualsDTS)
}
// setup and read all tracks
err = reader.SetupAndPlay(tracks, baseURL)
if err != nil {
panic(err)
}
// wait until a fatal error
panic(reader.Wait())
}