9
9
"strings"
10
10
11
11
g "github.com/AllenDang/giu"
12
- "github.com/jaypipes/ghw"
13
12
)
14
13
15
14
func handleUpscalingLogs (stderr io.ReadCloser , anime Anime ) string {
@@ -28,58 +27,56 @@ func handleUpscalingLogs(stderr io.ReadCloser, anime Anime) string {
28
27
}
29
28
30
29
if ! strings .HasPrefix (line , "frame=" ) {
31
- trim := strings .Replace (line , "\r " , "" , - 1 )
32
- trim = strings .Replace (trim , "\n " , "" , - 1 )
30
+ trim := strings .ReplaceAll (line , "\r " , "" )
31
+ trim = strings .ReplaceAll (trim , "\n " , "" )
33
32
logDebug (trim , false )
34
33
ffmpegLogs += line
35
34
line = ""
36
35
continue
37
36
}
38
37
39
38
// It's line with speed and time
40
- speedRaw := strings .Split (strings .Split (line , "speed=" )[1 ], " " )[0 ]
41
- time := strings .Split (strings .Split (strings .Split (line , "time=" )[1 ], " " )[0 ], "." )[0 ]
39
+ time := strings .Split (readOutputParameter (line , "time" , "bitrate" ), "." )[0 ]
42
40
millis := durationToMillis (time )
43
- progress = float32 (millis ) / float32 (anime .Length )
41
+ gui . Progress = float32 (millis ) / float32 (anime .Length )
44
42
45
- if time == "N/A" { // FFMPEG does not report time, we must estimate it manually
46
- split := strings .Split (line , "frame=" )
47
- if len (split ) > 1 { // Just for safety
48
- frame , _ := strconv .ParseFloat (strings .ReplaceAll (strings .Split (split [1 ], "f" )[0 ], " " , "" ), 32 )
49
- progress = float32 (frame ) / float32 (anime .TotalFrames )
43
+ // FFMPEG may not report time, we must calculate it manually
44
+ if time == "N/A" && len (strings .Split (line , "frame=" )) > 1 {
45
+ frame , _ := strconv .ParseFloat (readOutputParameter (line , "frame" , "fps" ), 32 )
46
+ gui .Progress = float32 (frame ) / float32 (anime .TotalFrames )
50
47
51
- fps , _ := strconv .ParseFloat (strings . ReplaceAll ( strings . Split ( strings . Split ( line , "fps=" )[ 1 ] , "q" )[ 0 ], " " , " " ), 32 )
52
- currentSpeed = fmt .Sprintf ("Speed: %.2fx" , fps / anime .FrameRate )
48
+ fps , _ := strconv .ParseFloat (readOutputParameter ( line , "fps" , "q" ), 32 )
49
+ gui . CurrentSpeed = fmt .Sprintf ("Speed: %.2fx" , fps / anime .FrameRate )
53
50
54
- leftFrames := anime .TotalFrames - int (frame )
55
- leftMillis := int64 ((float32 (leftFrames ) / float32 (fps )) * 1000 )
56
- eta = fmt .Sprintf ("ETA: %s" , formatMillis (leftMillis ))
57
- }
58
- }
59
-
60
- rounded := int (progress * 100 )
61
- if rounded == 99 {
62
- progress = 1
63
- progressLabel = "100%"
64
- } else {
65
- progressLabel = fmt .Sprintf ("%d%%" , rounded )
51
+ leftFrames := anime .TotalFrames - int (frame )
52
+ leftMillis := int64 ((float32 (leftFrames ) / float32 (fps )) * 1000 )
53
+ gui .Eta = fmt .Sprintf ("ETA: %s" , formatMillis (leftMillis ))
66
54
}
67
55
68
- // Workaround for disappearing speed
56
+ // Speed
57
+ speedRaw := strings .ReplaceAll (readOutputParameter (line , "speed" , "" ), "x" , "" )
69
58
if strings .Contains (speedRaw , "." ) {
70
- speedValue , _ := strconv .ParseFloat (strings .Replace (speedRaw , "x" , "" , - 1 ), 32 )
71
-
72
- currentSpeed = fmt .Sprintf ("Speed: %s" , speedRaw )
59
+ gui .CurrentSpeed = fmt .Sprintf ("Speed: %s" , speedRaw )
60
+ speedValue , _ := strconv .ParseFloat (speedRaw , 32 )
73
61
74
62
// Just for safety
75
63
if speedValue != 0 {
76
64
etaMillis := float64 (anime .Length - millis ) / speedValue
77
- eta = fmt .Sprintf ("ETA: %s" , formatMillis (int64 (etaMillis )))
65
+ gui . Eta = fmt .Sprintf ("ETA: %s" , formatMillis (int64 (etaMillis )))
78
66
}
79
67
}
80
68
81
- ffmpegLogs = strings .Replace (ffmpegLogs , progressLine , line , - 1 )
82
- logs = strings .Replace (logs , progressLine , line , - 1 )
69
+ // Progress bar
70
+ rounded := int (gui .Progress * 100 )
71
+ if rounded == 99 {
72
+ gui .Progress = 1
73
+ gui .ProgressLabel = "100%"
74
+ } else {
75
+ gui .ProgressLabel = fmt .Sprintf ("%d%%" , rounded )
76
+ }
77
+
78
+ ffmpegLogs = strings .ReplaceAll (ffmpegLogs , progressLine , line )
79
+ gui .Logs = strings .ReplaceAll (gui .Logs , progressLine , line )
83
80
progressLine = line
84
81
85
82
line = ""
@@ -136,71 +133,10 @@ func buildUpscalingParams(anime Anime, resolution Resolution, shader Shader, out
136
133
return params
137
134
}
138
135
139
- func searchHardwareAcceleration () {
140
- nvidia := false
141
- amd := false
142
- intel := false
143
-
144
- gpus , err := ghw .GPU ()
145
- if err != nil {
146
- handleSoftError ("Getting GPU info error" , err .Error ())
147
- return
148
- }
149
-
150
- logMessage (fmt .Sprintf ("Detected GPUs (%d): " , len (gpus .GraphicsCards )), false )
151
-
152
- for index , gpu := range gpus .GraphicsCards {
153
- vendor := strings .ToLower (gpu .DeviceInfo .Vendor .Name )
154
-
155
- logDebug (fmt .Sprintf ("GPU ID: %d, Vendor: %s" , index , vendor ), false )
156
-
157
- if strings .Contains (vendor , "nvidia" ) {
158
- nvidia = true
159
- } else if strings .Contains (vendor , "amd" ) || strings .Contains (vendor , "advanced micro devices" ) {
160
- amd = true
161
- } else if strings .Contains (vendor , "intel" ) {
162
- intel = true
163
- }
164
-
165
- logMessage (fmt .Sprintf (" %d. %s" , index + 1 , gpu .DeviceInfo .Product .Name ), false )
166
- }
167
-
168
- if (nvidia && intel ) || (amd && intel ) {
169
- intel = false
170
- logDebug ("Ignoring Intel iGPU, detected NVIDIA/AMD dGPU)" , false )
171
- }
172
-
173
- if nvidia && amd { // AMD is iGPU
174
- amd = false
175
- logDebug ("Ignoring AMD iGPU, detected NVIDIA dGPU" , false )
136
+ func readOutputParameter (line string , parameter string , nextParameter string ) string {
137
+ if nextParameter == "" {
138
+ return strings .ReplaceAll (strings .Split (line , parameter + "=" )[1 ], " " , "" )
176
139
}
177
140
178
- if nvidia {
179
- hwaccelParams = append (hwaccelParams , "-hwaccel_device" , "cuda" , "-hwaccel_output_format" , "cuda" )
180
- addEncoders ("nvidia" )
181
-
182
- logMessage ("Available GPU acceleration: CUDA + NVENC" , false )
183
- } else if amd {
184
- hwaccelParams = append (hwaccelParams , "-hwaccel_device" , "opencl" )
185
- addEncoders ("advanced micro devices" )
186
-
187
- logMessage ("Available GPU acceleration: AMF" , false )
188
- } else if intel {
189
- settings .CompatibilityMode = true
190
- addEncoders ("cpu" )
191
-
192
- logMessage ("Intel GPUs are not supported - application may not work correctly" , false )
193
- } else {
194
- settings .CompatibilityMode = true
195
- addEncoders ("cpu" )
196
-
197
- logMessage ("There's no available GPU acceleration, application may not work correctly! Please verify your GPU drivers or report bug on GitHub" , false )
198
- }
199
-
200
- for index , encoder := range availableEncoders {
201
- if encoder .Vendor != "cpu" {
202
- settings .Encoder = int32 (index )
203
- break
204
- }
205
- }
141
+ return strings .ReplaceAll (strings .Split (strings .Split (line , parameter + "=" )[1 ], nextParameter )[0 ], " " , "" )
206
142
}
0 commit comments