-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
superview-gui.go
162 lines (135 loc) · 3.86 KB
/
superview-gui.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"fmt"
"log"
"strconv"
"strings"
"superview/common"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/storage"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
)
func main() {
var video *common.VideoSpecs
var ffmpeg map[string]string
var encoder *widget.Select
app := app.New()
app.Settings().SetTheme(theme.LightTheme())
window := app.NewWindow("Superview")
title := widget.NewLabel("Superview - dynamic video stretching")
title.Alignment = fyne.TextAlignCenter
title.TextStyle = fyne.TextStyle{Bold: true}
info := widget.NewMultiLineEntry()
info.SetReadOnly(true)
//info.Disable()
info.SetPlaceHolder("Info box...")
squeeze := widget.NewCheck("Squeeze video", nil)
bitrate := widget.NewEntry()
bitrate.SetPlaceHolder("Set output bitrate in bytes/second if you want to change")
start := widget.NewButton("Encode the video...", func() {
dialog.ShowFileSave(func(file fyne.URIWriteCloser, err error) {
if err == nil && file == nil {
log.Println("File saving cancelled")
return
}
if err != nil {
dialog.ShowError(err, window)
return
}
uri := strings.ReplaceAll(file.URI().String(), "file://", "")
err = file.Close()
if err != nil {
fyne.LogError("Failed to close stream", err)
}
prog := dialog.NewProgress("Re-encoding", "Please wait...", window)
prog.Show()
go func() {
err := common.GeneratePGM(video, squeeze.Checked)
if err != nil {
prog.Hide()
dialog.ShowError(err, window)
return
}
br, err := strconv.Atoi(bitrate.Text)
if err != nil {
br = video.Streams[0].BitrateInt
}
enc := video.Streams[0].Codec
if encoder.Selected != "Use same video codec as input file" {
enc = strings.Split(encoder.Selected, " ")[0]
}
err = common.EncodeVideo(video, common.FindEncoder(enc, ffmpeg, video), br, uri, func(v float64) { prog.SetValue(v / 100) })
if err != nil {
dialog.ShowError(err, window)
return
}
err = common.CleanUp()
if err != nil {
dialog.ShowError(err, window)
return
}
prog.Hide()
dialog.ShowInformation("Encode done", "Encode finished, your output file can be found here:\n"+uri, window)
}()
}, window)
})
start.Disable()
open := widget.NewButton("Open input video...", func() {
fd := dialog.NewFileOpen(func(file fyne.URIReadCloser, err error) {
if err == nil && file == nil {
log.Println("File opening cancelled")
return
}
if err != nil {
dialog.ShowError(err, window)
return
}
uri := strings.ReplaceAll(file.URI().String(), "file://", "")
err = file.Close()
if err != nil {
fyne.LogError("Failed to close stream", err)
}
video, err = common.CheckVideo(uri)
if err != nil {
dialog.ShowError(err, window)
return
}
info.SetText(fmt.Sprintf("%sFile opened: %s\nInfo: %vx%v px, %s @ %v Mb/s, %.1f secs", info.Text, video.File, video.Streams[0].Width, video.Streams[0].Height, video.Streams[0].Codec, video.Streams[0].BitrateInt/1024/1024, video.Streams[0].DurationFloat))
start.Enable()
}, window)
fd.SetFilter(storage.NewExtensionFileFilter([]string{".mp4", ".avi", ".MP4", ".AVI"}))
fd.Show()
})
ffmpeg, err := common.CheckFfmpeg()
if err != nil {
dialog.ShowError(err, window)
open.Disable()
}
info.SetText(common.GetHeader(ffmpeg))
encoderOptions := []string{"Use same video codec as input file"}
for _, enc := range strings.Split(ffmpeg["encoders"], ",") {
encoderOptions = append(encoderOptions, enc+" encoder")
}
encoder = widget.NewSelect(encoderOptions, func(s string) {
})
encoder.SetSelected(encoderOptions[0])
window.SetContent(widget.NewVBox(
title,
info,
layout.NewSpacer(),
open,
squeeze,
encoder,
bitrate,
start,
widget.NewButton("Quit", func() {
app.Quit()
}),
))
window.Resize(fyne.NewSize(640, 330))
window.ShowAndRun()
}