-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
81 lines (66 loc) · 1.5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"net/url"
"os"
"time"
)
func main() {
var (
network = flag.String("network", "udp4", "network")
addr = flag.String("addr", "", "example: 1.2.3.4:80")
sni = flag.String("sni", "", "domain,empty is skip")
quicVersion = flag.String("quic-version", "43", "support 39,43,44")
local = flag.String("bind", "", "bind local ip")
name = flag.String("file", "d.flv", "specify i/o flv file")
buffer = flag.Int("buffer", 102400, "buffer size in byte")
rtmpType = flag.Bool("type", true, "whether to pull or publish,true is pull")
skip = flag.Bool("skip", true, "whether a client verifies the server's certificate chain and host name")
)
flag.Parse()
rawurl := os.Args[len(os.Args)-1]
filename := *name
if *name == "d.flv" {
filename = time.Now().Format("2006-01-02-15-04-05-999-") + *name
}
file, err := os.OpenFile(filename,
os.O_WRONLY|os.O_TRUNC|os.O_CREATE,
0666)
if err != nil {
fmt.Println(err)
return
}
defer func() {
file.Sync()
stat, _ := file.Stat()
if stat.Size() == 0 {
os.Remove(file.Name())
}
file.Close()
}()
u, err := url.Parse(rawurl)
if err != nil {
fmt.Println(rawurl, err)
return
}
if *sni == "" {
*sni = u.Host
}
tlsCfg, cfg := parseCfg(*quicVersion, *sni, *skip)
appBuffer := make([]byte, *buffer)
quit := make(chan os.Signal, 1)
go run(*network,
*local,
*addr,
rawurl,
filename,
tlsCfg,
cfg,
appBuffer,
file,
u,
*rtmpType,
quit)
<-quit
}