-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (61 loc) · 1.27 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
package main
import (
"flag"
"log"
"os"
"path/filepath"
)
var (
inputFile = flag.String("in", "", "input file (required)")
outputFile = flag.String("out", "", "output file")
)
func main() {
flag.Parse()
// take input video file (as param to ffmpeg or ffprobe) and generate a video file
if inputFile == nil || *inputFile == "" {
log.Printf("Syntax: %s -in filename [-key key]", os.Args[0])
flag.PrintDefaults()
os.Exit(1)
return
}
inFile, err := filepath.Abs(*inputFile)
if err != nil {
log.Printf("Invalid input path: %s", err)
os.Exit(1)
return
}
if _, err = os.Stat(inFile); err != nil {
log.Printf("Input file could not be located: %s", err)
os.Exit(1)
return
}
out := *outputFile
if out == "" {
out = inFile + ".hls"
}
hlsb, err := newHlsBuilder(out)
if err != nil {
log.Printf("failed to create output file: %s", err)
os.Exit(1)
return
}
defer hlsb.Close()
err = hlsb.prepareVideo(inFile)
if err != nil {
log.Printf("preparing failed: %s", err)
os.Exit(1)
return
}
err = hlsb.encodeVideo() // will generate {hls.dir}/master.m3u8
if err != nil {
log.Printf("encoding failed: %s", err)
os.Exit(1)
return
}
err = hlsb.build()
if err != nil {
log.Printf("failed to build hls: %s", err)
os.Exit(1)
return
}
}