forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (53 loc) · 1.26 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
61
62
63
package main
import (
"log"
"github.com/Coimbra1984/gortsplib"
"github.com/Coimbra1984/gortsplib/pkg/base"
"github.com/pion/rtcp"
"github.com/pion/rtp"
)
// This example shows how to
// 1. connect to a RTSP server
// 2. get tracks published on a path
// 3. read only selected tracks
func main() {
c := gortsplib.Client{
// called when a RTP packet arrives
OnPacketRTP: func(trackID int, pkt *rtp.Packet) {
log.Printf("RTP packet from track %d, payload type %d\n", trackID, pkt.Header.PayloadType)
},
// called when a RTCP packet arrives
OnPacketRTCP: func(trackID int, pkt rtcp.Packet) {
log.Printf("RTCP packet from track %d, type %T\n", trackID, pkt)
},
}
u, err := base.ParseURL("rtsp://myserver/mypath")
if err != nil {
panic(err)
}
err = c.Start(u.Scheme, u.Host)
if err != nil {
panic(err)
}
defer c.Close()
tracks, baseURL, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// setup only H264 tracks, skipping audio or application tracks
for _, t := range tracks {
if _, ok := t.(*gortsplib.TrackH264); ok {
_, err := c.Setup(true, t, baseURL, 0, 0)
if err != nil {
panic(err)
}
}
}
// start reading tracks
_, err = c.Play(nil)
if err != nil {
panic(err)
}
// wait until a fatal error
panic(c.Wait())
}