Add video index generation

This commit is contained in:
Zoe Roux 2024-01-14 02:10:57 +01:00
parent 80d1b1af0f
commit 88406c6ee5
2 changed files with 34 additions and 6 deletions

View File

@ -172,3 +172,20 @@ func (fs *FileStream) GetMaster() string {
}
return master
}
func (fs *FileStream) GetIndex(quality Quality, client string) (string, error) {
index := `#EXTM3U
#EXT-X-VERSION:3
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
`
for segment := 1; segment < len(fs.Keyframes); segment++ {
index += fmt.Sprintf("#EXTINF:%.6f\n", fs.Keyframes[segment]-fs.Keyframes[segment-1])
index += fmt.Sprintf("segment-%d.ts\n", segment)
}
index += `#EXT-X-ENDLIST`
return index, nil
}

View File

@ -21,7 +21,7 @@ func NewTranscoder() *Transcoder {
}
}
func (t *Transcoder) GetMaster(path string, client string) (string, error) {
func (t *Transcoder) getFileStream(path string) (*FileStream, error) {
t.mutex.RLock()
stream, ok := t.streams[path]
channel, preparing := t.preparing[path]
@ -30,7 +30,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
if preparing {
pstream := <-channel
if pstream == nil {
return "", errors.New("could not transcode file. Try again later")
return nil, errors.New("could not transcode file. Try again later")
}
stream = *pstream
} else if !ok {
@ -48,7 +48,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
t.mutex.Unlock()
channel <- nil
return "", err
return nil, err
}
t.mutex.Lock()
@ -59,8 +59,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
channel <- &stream
}
return stream.GetMaster(), nil
return &stream, nil
}
// This method assume the lock is already taken.
@ -74,8 +73,20 @@ func (t *Transcoder) cleanUnused() {
}
}
func (t *Transcoder) GetMaster(path string, client string) (string, error) {
stream, err := t.getFileStream(path)
if err != nil {
return "", err
}
return stream.GetMaster(), nil
}
func (t *Transcoder) GetVideoIndex(path string, quality Quality, client string) (string, error) {
return "", nil
stream, err := t.getFileStream(path)
if err != nil {
return "", err
}
return stream.GetIndex(quality, client)
}
func (t *Transcoder) GetAudioIndex(path string, audio string, client string) (string, error) {