diff --git a/transcoder/src/filestream.go b/transcoder/src/filestream.go index 0813d111..3386053f 100644 --- a/transcoder/src/filestream.go +++ b/transcoder/src/filestream.go @@ -179,7 +179,7 @@ func (fs *FileStream) getVideoStream(idx uint32, quality Quality) (*VideoStream, ret, _ := fs.transcoder.NewVideoStream(fs, idx, quality) return ret }) - stream.keyframes.info.ready.Wait() + stream.ready.Wait() return stream, nil } @@ -204,7 +204,7 @@ func (fs *FileStream) getAudioStream(audio uint32) (*AudioStream, error) { ret, _ := fs.transcoder.NewAudioStream(fs, audio) return ret }) - stream.keyframes.info.ready.Wait() + stream.ready.Wait() return stream, nil } diff --git a/transcoder/src/keyframes.go b/transcoder/src/keyframes.go index 18cb9e32..f8d74378 100644 --- a/transcoder/src/keyframes.go +++ b/transcoder/src/keyframes.go @@ -121,6 +121,7 @@ func (s *MetadataService) GetKeyframes(info *MediaInfo, isVideo bool, idx uint32 return } + kf.info.ready.Wait() tx, _ := s.database.Begin() tx.Exec( fmt.Sprintf(`update %s set keyframes = $3 where sha = $1 and idx = $2`, table), @@ -149,7 +150,7 @@ func getVideoKeyframes(path string, video_idx uint32, kf *Keyframe) error { cmd := exec.Command( "ffprobe", "-loglevel", "error", - "-select_streams", fmt.Sprint("V:%d", video_idx), + "-select_streams", fmt.Sprintf("V:%d", video_idx), "-show_entries", "packet=pts_time,flags", "-of", "csv=print_section=0", path, @@ -166,7 +167,7 @@ func getVideoKeyframes(path string, video_idx uint32, kf *Keyframe) error { scanner := bufio.NewScanner(stdout) ret := make([]float64, 0, 1000) - max := 100 + limit := 100 done := 0 // sometimes, videos can start at a timing greater than 0:00. We need to take that into account // and only list keyframes that come after the start of the video (without that, our segments count @@ -205,14 +206,14 @@ func getVideoKeyframes(path string, video_idx uint32, kf *Keyframe) error { ret = append(ret, fpts) - if len(ret) == max { + if len(ret) == limit { kf.add(ret) if done == 0 { kf.info.ready.Done() } else if done >= 500 { - max = 500 + limit = 500 } - done += max + done += limit // clear the array without reallocing it ret = ret[:0] } diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index c1de1a9e..3692e3ec 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -31,6 +31,7 @@ type StreamHandle interface { type Stream struct { handle StreamHandle + ready sync.WaitGroup file *FileStream keyframes *Keyframe segments []Segment @@ -69,6 +70,7 @@ func NewStream(file *FileStream, keyframes *Keyframe, handle StreamHandle, ret * ret.keyframes = keyframes ret.heads = make([]Head, 0) + ret.ready.Add(1) go func() { keyframes.info.ready.Wait() @@ -93,6 +95,7 @@ func NewStream(file *FileStream, keyframes *Keyframe, handle StreamHandle, ret * } }) } + ret.ready.Done() }() } diff --git a/transcoder/src/videostream.go b/transcoder/src/videostream.go index 85df7d38..95c69a56 100644 --- a/transcoder/src/videostream.go +++ b/transcoder/src/videostream.go @@ -60,7 +60,7 @@ func closestMultiple(n int32, x int32) int32 { func (vs *VideoStream) getTranscodeArgs(segments string) []string { args := []string{ - "-map", fmt.Sprint("0:V:%d", vs.video.Index), + "-map", fmt.Sprintf("0:V:%d", vs.video.Index), } if vs.quality == Original {