add speed and fps to ws response

This commit is contained in:
Alf
2021-02-27 22:24:32 -08:00
parent 080822a1b2
commit 0a76957b77

16
main.go
View File

@@ -36,6 +36,8 @@ type Message struct {
// Status response to client.
type Status struct {
Percent float64 `json:"percent"`
Speed string `json:"speed"`
FPS float64 `json:"fps"`
}
var progressCh chan struct{}
@@ -107,6 +109,18 @@ func runEncode(input, output, payload string) {
}
close(progressCh)
fmt.Println(ffmpeg)
for client := range clients {
p := &Status{
Percent: 100,
}
err := client.WriteJSON(p)
if err != nil {
log.Printf("error: %w", err)
client.Close()
delete(clients, client)
}
}
}
func trackEncodeProgress(p *FFProbeResponse, f *FFmpeg) {
@@ -135,6 +149,8 @@ func trackEncodeProgress(p *FFProbeResponse, f *FFmpeg) {
for client := range clients {
p := &Status{
Percent: pct,
Speed: speed,
FPS: fps,
}
fmt.Println(p)
err := client.WriteJSON(p)