-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (52 loc) · 1.43 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
package main
import (
"flag"
"fmt"
"os"
"path"
)
var Args struct {
Output string
ForceTranscode bool
JSONSideCar bool
}
func init() {
flag.BoolVar(&Args.ForceTranscode, "force-transcode", false, "Should the input file be transmuxed regardless of if it has to")
flag.BoolVar(&Args.JSONSideCar, "json", false, "Output JSON formatted manifest")
flag.StringVar(&Args.Output, "output", "./", "Output directory for torrent and video files")
}
func main() {
flag.Parse()
if len(os.Args) < 2 {
fmt.Printf("No input specified\n")
os.Exit(1)
}
input := os.Args[1]
if input == "" {
fmt.Printf("No input specified\n")
os.Exit(1)
}
ffmpegCmd, err := FFmpegCmd(input, Args.ForceTranscode, Args.Output)
if err != nil {
fmt.Printf("FFmpeg command error: %s\n", err)
os.Exit(1)
}
if ffmpegCmd != nil {
ffmpegCmd.Run()
}
outputVideoFile := path.Join(Args.Output, "out.mp4")
outputTorrentFile := path.Join(Args.Output, "out.torrent")
// segments := GetSegments(outputVideoFile)
// CreateTorrentFile(outputVideoFile, segments, outputTorrentFile)
manifest, err := GetManifest(outputVideoFile)
if err != nil {
fmt.Printf("Get manifest error: %s\n", err)
os.Exit(1)
}
CreateTorrentFile(outputVideoFile, manifest, outputTorrentFile)
if Args.JSONSideCar {
outputJsonFile := path.Join(Args.Output, "out.json")
// WriteSegmentsToFile(manifest, outputJsonFile)
WriteManifestToFile(manifest, outputJsonFile)
}
}