forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 878 Bytes
/
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
package main
import (
"fmt"
"time"
"github.com/aler9/gortsplib"
)
// This example shows how to
// 1. connect to a RTSP server and read all tracks on a path
// 2. wait for 5 seconds
// 3. pause for 5 seconds
// 4. repeat
func main() {
// connect to the server and start reading all tracks
conn, err := gortsplib.DialRead("rtsp://localhost:8554/mystream")
if err != nil {
panic(err)
}
defer conn.Close()
for {
// read RTP frames
done := conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
})
// wait
time.Sleep(5 * time.Second)
// pause
_, err := conn.Pause()
if err != nil {
panic(err)
}
// join reader
<-done
// wait
time.Sleep(5 * time.Second)
// play again
_, err = conn.Play()
if err != nil {
panic(err)
}
}
}