mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -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
|
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()
|
t.mutex.RLock()
|
||||||
stream, ok := t.streams[path]
|
stream, ok := t.streams[path]
|
||||||
channel, preparing := t.preparing[path]
|
channel, preparing := t.preparing[path]
|
||||||
@ -30,7 +30,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
|||||||
if preparing {
|
if preparing {
|
||||||
pstream := <-channel
|
pstream := <-channel
|
||||||
if pstream == nil {
|
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
|
stream = *pstream
|
||||||
} else if !ok {
|
} else if !ok {
|
||||||
@ -48,7 +48,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
|||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
channel <- nil
|
channel <- nil
|
||||||
|
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
@ -59,8 +59,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
|||||||
|
|
||||||
channel <- &stream
|
channel <- &stream
|
||||||
}
|
}
|
||||||
|
return &stream, nil
|
||||||
return stream.GetMaster(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method assume the lock is already taken.
|
// 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) {
|
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) {
|
func (t *Transcoder) GetAudioIndex(path string, audio string, client string) (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user