mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add video index generation
This commit is contained in:
parent
80d1b1af0f
commit
88406c6ee5
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user