mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -04:00
Reduce playback start time by 100x (#945)
This commit is contained in:
parent
4a0e1aa72c
commit
f6a67341b6
@ -14,7 +14,11 @@ import (
|
|||||||
"github.com/zoriya/kyoo/transcoder/src/utils"
|
"github.com/zoriya/kyoo/transcoder/src/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const KeyframeVersion = 1
|
const (
|
||||||
|
KeyframeVersion = 1
|
||||||
|
minParsedKeyframeTime = 5.0 // seconds
|
||||||
|
minParsedKeyframeCount = 3
|
||||||
|
)
|
||||||
|
|
||||||
type Keyframe struct {
|
type Keyframe struct {
|
||||||
Keyframes []float64
|
Keyframes []float64
|
||||||
@ -192,6 +196,8 @@ func getVideoKeyframes(path string, video_idx uint32, kf *Keyframe) error {
|
|||||||
ret := make([]float64, 0, 1000)
|
ret := make([]float64, 0, 1000)
|
||||||
limit := 100
|
limit := 100
|
||||||
done := 0
|
done := 0
|
||||||
|
indexNotificationComplete := false
|
||||||
|
|
||||||
// sometimes, videos can start at a timing greater than 0:00. We need to take that into account
|
// 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
|
// and only list keyframes that come after the start of the video (without that, our segments count
|
||||||
// mismatch and we can have the same segment twice on the stream).
|
// mismatch and we can have the same segment twice on the stream).
|
||||||
@ -231,7 +237,8 @@ func getVideoKeyframes(path string, video_idx uint32, kf *Keyframe) error {
|
|||||||
|
|
||||||
ret = append(ret, fpts)
|
ret = append(ret, fpts)
|
||||||
|
|
||||||
if len(ret) == limit {
|
shouldNotifyIndexers := !indexNotificationComplete && fpts >= minParsedKeyframeTime && len(ret) >= minParsedKeyframeCount
|
||||||
|
if len(ret) == limit || shouldNotifyIndexers {
|
||||||
kf.add(ret)
|
kf.add(ret)
|
||||||
if done == 0 {
|
if done == 0 {
|
||||||
kf.info.ready.Done()
|
kf.info.ready.Done()
|
||||||
@ -241,6 +248,10 @@ func getVideoKeyframes(path string, video_idx uint32, kf *Keyframe) error {
|
|||||||
done += limit
|
done += limit
|
||||||
// clear the array without reallocing it
|
// clear the array without reallocing it
|
||||||
ret = ret[:0]
|
ret = ret[:0]
|
||||||
|
|
||||||
|
if shouldNotifyIndexers {
|
||||||
|
indexNotificationComplete = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kf.add(ret)
|
kf.add(ret)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user