mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Create different index.m3u8 for audio and video
This commit is contained in:
parent
f6dab80a98
commit
9fad5da0a4
@ -36,3 +36,29 @@ func (as *AudioStream) getTranscodeArgs(segments string) []string {
|
|||||||
"-b:a", "128k",
|
"-b:a", "128k",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ts *AudioStream) GetIndex() (string, error) {
|
||||||
|
index := `#EXTM3U
|
||||||
|
#EXT-X-VERSION:7
|
||||||
|
#EXT-X-PLAYLIST-TYPE:EVENT
|
||||||
|
#EXT-X-START:TIME-OFFSET=0
|
||||||
|
#EXT-X-MEDIA-SEQUENCE:0
|
||||||
|
#EXT-X-INDEPENDENT-SEGMENTS
|
||||||
|
#EXT-X-MAP:URI="init.mp4"
|
||||||
|
`
|
||||||
|
index += fmt.Sprintf("#EXT-X-TARGETDURATION:%d\n", int(OptimalFragmentDuration)+1)
|
||||||
|
|
||||||
|
count := int32((float64(ts.file.Info.Duration) / OptimalFragmentDuration))
|
||||||
|
for segment := int32(0); segment < count; segment++ {
|
||||||
|
index += fmt.Sprintf("#EXTINF:%.6f\n", OptimalFragmentDuration)
|
||||||
|
index += fmt.Sprintf("segment-%d.m4s\n", segment)
|
||||||
|
}
|
||||||
|
|
||||||
|
last_ts := float64(count) * OptimalFragmentDuration
|
||||||
|
if last_ts > 0 {
|
||||||
|
index += fmt.Sprintf("#EXTINF:%.6f\n", float64(ts.file.Info.Duration)-last_ts)
|
||||||
|
index += fmt.Sprintf("segment-%d.m4s\n", count)
|
||||||
|
}
|
||||||
|
index += `#EXT-X-ENDLIST`
|
||||||
|
return index, nil
|
||||||
|
}
|
||||||
|
@ -114,24 +114,24 @@ func (fs *FileStream) GetMaster() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for _, audio := range fs.Info.Audios {
|
for _, audio := range fs.Info.Audios {
|
||||||
// master += "#EXT-X-MEDIA:TYPE=AUDIO,"
|
master += "#EXT-X-MEDIA:TYPE=AUDIO,"
|
||||||
// master += "GROUP-ID=\"audio\","
|
master += "GROUP-ID=\"audio\","
|
||||||
// if audio.Language != nil {
|
if audio.Language != nil {
|
||||||
// master += fmt.Sprintf("LANGUAGE=\"%s\",", *audio.Language)
|
master += fmt.Sprintf("LANGUAGE=\"%s\",", *audio.Language)
|
||||||
// }
|
}
|
||||||
// if audio.Title != nil {
|
if audio.Title != nil {
|
||||||
// master += fmt.Sprintf("NAME=\"%s\",", *audio.Title)
|
master += fmt.Sprintf("NAME=\"%s\",", *audio.Title)
|
||||||
// } else if audio.Language != nil {
|
} else if audio.Language != nil {
|
||||||
// master += fmt.Sprintf("NAME=\"%s\",", *audio.Language)
|
master += fmt.Sprintf("NAME=\"%s\",", *audio.Language)
|
||||||
// } else {
|
} else {
|
||||||
// master += fmt.Sprintf("NAME=\"Audio %d\",", audio.Index)
|
master += fmt.Sprintf("NAME=\"Audio %d\",", audio.Index)
|
||||||
// }
|
}
|
||||||
// if audio.IsDefault {
|
if audio.IsDefault {
|
||||||
// master += "DEFAULT=YES,"
|
master += "DEFAULT=YES,"
|
||||||
// }
|
}
|
||||||
// master += fmt.Sprintf("URI=\"./audio/%d/index.m3u8\"\n", audio.Index)
|
master += fmt.Sprintf("URI=\"./audio/%d/index.m3u8\"\n", audio.Index)
|
||||||
// }
|
}
|
||||||
return master
|
return master
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ type StreamHandle interface {
|
|||||||
getTranscodeArgs(segments string) []string
|
getTranscodeArgs(segments string) []string
|
||||||
getSegmentName() string
|
getSegmentName() string
|
||||||
getFlags() Flags
|
getFlags() Flags
|
||||||
|
GetIndex() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
@ -377,34 +378,6 @@ func (ts *Stream) run(start int32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *Stream) GetIndex() (string, error) {
|
|
||||||
// playlist type is event since we can append to the list if Keyframe.IsDone is false.
|
|
||||||
// start time offset makes the stream start at 0s instead of ~3segments from the end (requires version 6 of hls)
|
|
||||||
index := `#EXTM3U
|
|
||||||
#EXT-X-VERSION:7
|
|
||||||
#EXT-X-PLAYLIST-TYPE:EVENT
|
|
||||||
#EXT-X-START:TIME-OFFSET=0
|
|
||||||
#EXT-X-MEDIA-SEQUENCE:0
|
|
||||||
#EXT-X-INDEPENDENT-SEGMENTS
|
|
||||||
#EXT-X-MAP:URI="init.mp4"
|
|
||||||
`
|
|
||||||
index += fmt.Sprintf("#EXT-X-TARGETDURATION:%d\n", int(OptimalFragmentDuration))
|
|
||||||
length, is_done := ts.file.Keyframes.Length()
|
|
||||||
|
|
||||||
for segment := int32(0); segment < length-1; segment++ {
|
|
||||||
index += fmt.Sprintf("#EXTINF:%.6f\n", ts.file.Keyframes.Get(segment+1)-ts.file.Keyframes.Get(segment))
|
|
||||||
index += fmt.Sprintf("segment-%d.m4s\n", segment)
|
|
||||||
}
|
|
||||||
// do not forget to add the last segment between the last keyframe and the end of the file
|
|
||||||
// if the keyframes extraction is not done, do not bother to add it, it will be retrieval on the next index retrieval
|
|
||||||
if is_done {
|
|
||||||
index += fmt.Sprintf("#EXTINF:%.6f\n", float64(ts.file.Info.Duration)-ts.file.Keyframes.Get(length-1))
|
|
||||||
index += fmt.Sprintf("segment-%d.m4s\n", length-1)
|
|
||||||
index += `#EXT-X-ENDLIST`
|
|
||||||
}
|
|
||||||
return index, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ts *Stream) GetInit() (string, error) {
|
func (ts *Stream) GetInit() (string, error) {
|
||||||
// No need to lock, the channel won't change.
|
// No need to lock, the channel won't change.
|
||||||
select {
|
select {
|
||||||
|
@ -72,3 +72,31 @@ func (vs *VideoStream) getTranscodeArgs(segments string) []string {
|
|||||||
)
|
)
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ts *VideoStream) GetIndex() (string, error) {
|
||||||
|
// playlist type is event since we can append to the list if Keyframe.IsDone is false.
|
||||||
|
// start time offset makes the stream start at 0s instead of ~3segments from the end (requires version 6 of hls)
|
||||||
|
index := `#EXTM3U
|
||||||
|
#EXT-X-VERSION:7
|
||||||
|
#EXT-X-PLAYLIST-TYPE:EVENT
|
||||||
|
#EXT-X-START:TIME-OFFSET=0
|
||||||
|
#EXT-X-MEDIA-SEQUENCE:0
|
||||||
|
#EXT-X-INDEPENDENT-SEGMENTS
|
||||||
|
#EXT-X-MAP:URI="init.mp4"
|
||||||
|
`
|
||||||
|
index += fmt.Sprintf("#EXT-X-TARGETDURATION:%d\n", int(OptimalFragmentDuration)+1)
|
||||||
|
length, is_done := ts.file.Keyframes.Length()
|
||||||
|
|
||||||
|
for segment := int32(0); segment < length-1; segment++ {
|
||||||
|
index += fmt.Sprintf("#EXTINF:%.6f\n", ts.file.Keyframes.Get(segment+1)-ts.file.Keyframes.Get(segment))
|
||||||
|
index += fmt.Sprintf("segment-%d.m4s\n", segment)
|
||||||
|
}
|
||||||
|
// do not forget to add the last segment between the last keyframe and the end of the file
|
||||||
|
// if the keyframes extraction is not done, do not bother to add it, it will be retrieval on the next index retrieval
|
||||||
|
if is_done {
|
||||||
|
index += fmt.Sprintf("#EXTINF:%.6f\n", float64(ts.file.Info.Duration)-ts.file.Keyframes.Get(length-1))
|
||||||
|
index += fmt.Sprintf("segment-%d.m4s\n", length-1)
|
||||||
|
index += `#EXT-X-ENDLIST`
|
||||||
|
}
|
||||||
|
return index, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user