Silent timeline removed when hitting export
This commit is contained in:
@@ -14,6 +14,13 @@ import (
|
||||
type exportRequest struct {
|
||||
Filename string `json:"filename"`
|
||||
Segments []transcode.Segment `json:"segments"`
|
||||
Duration float64 `json:"duration"`
|
||||
}
|
||||
|
||||
type updateTimeLine struct {
|
||||
Type string `json:"type"`
|
||||
Segments []transcode.Segment `json:"segments"`
|
||||
Duration float64 `json:"duration"`
|
||||
}
|
||||
|
||||
func ExportHandler(st *store.Store, hub *ws.Hub) http.HandlerFunc {
|
||||
@@ -28,6 +35,7 @@ func ExportHandler(st *store.Store, hub *ws.Hub) http.HandlerFunc {
|
||||
http.Error(w, "bad JSON: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Segments) == 0 {
|
||||
http.Error(w, "no segments", http.StatusBadRequest)
|
||||
return
|
||||
@@ -50,15 +58,30 @@ func ExportHandler(st *store.Store, hub *ws.Hub) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
msg, _ := json.Marshal(map[string]string{
|
||||
doneMsg, _ := json.Marshal(map[string]string{
|
||||
"type": "done",
|
||||
"message": outputKey,
|
||||
})
|
||||
hub.Broadcast(msg)
|
||||
hub.Broadcast(doneMsg)
|
||||
|
||||
// Build normalized segments for the exported video: timestamps start at 0
|
||||
// with no gaps, so the timeline reflects the exported file's layout.
|
||||
var normalized []transcode.Segment
|
||||
cursor := 0.0
|
||||
for _, seg := range req.Segments {
|
||||
dur := seg.End - seg.Start
|
||||
normalized = append(normalized, transcode.Segment{Start: cursor, End: cursor + dur})
|
||||
cursor += dur
|
||||
}
|
||||
timelineMsg, _ := json.Marshal(updateTimeLine{
|
||||
Type: "timeline",
|
||||
Segments: normalized,
|
||||
Duration: cursor,
|
||||
})
|
||||
hub.Broadcast(timelineMsg)
|
||||
}()
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
|
||||
log.Println("Export handler works")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user