Rename stream struct

This commit is contained in:
Zoe Roux 2024-01-14 03:50:12 +01:00
parent 95b1caeb26
commit 5d47a28ba6
3 changed files with 23 additions and 19 deletions

View File

@ -17,7 +17,8 @@ type FileStream struct {
Keyframes []float64 Keyframes []float64
CanTransmux bool CanTransmux bool
Info *MediaInfo Info *MediaInfo
streams map[Quality]*TranscodeStream streams map[Quality]*VideoStream
// audios map[uint32]*AudioStream
} }
func GetOutPath() string { func GetOutPath() string {
@ -56,7 +57,7 @@ func NewFileStream(path string) (*FileStream, error) {
Keyframes: keyframes, Keyframes: keyframes,
CanTransmux: can_transmux, CanTransmux: can_transmux,
Info: info.info, Info: info.info,
streams: make(map[Quality]*TranscodeStream), streams: make(map[Quality]*VideoStream),
}, nil }, nil
} }

View File

@ -16,13 +16,13 @@ func Min(a int32, b int32) int32 {
return b return b
} }
type Stream interface { type TranscodeStream interface {
getTranscodeArgs(segments string) []string getTranscodeArgs(segments string) []string
getOutPath() string getOutPath() string
} }
type TranscodeStream struct { type Stream struct {
Stream TranscodeStream
file *FileStream file *FileStream
Clients []string Clients []string
// true if the segment at given index is completed/transcoded, false otherwise // true if the segment at given index is completed/transcoded, false otherwise
@ -33,18 +33,7 @@ type TranscodeStream struct {
// TODO: add ffmpeg process // TODO: add ffmpeg process
} }
func NewStream(file *FileStream) (*TranscodeStream, error) { func (ts *Stream) run(start int32, end int32) error {
ret := TranscodeStream{
file: file,
Clients: make([]string, 4),
segments: make([]bool, len(file.Keyframes)),
}
// Start the transcode up to the 100th segment (or less)
ret.run(0, Min(100, int32(len(file.Keyframes))))
return &ret, nil
}
func (ts *TranscodeStream) run(start int32, end int32) error {
log.Printf( log.Printf(
"Starting transcode for %s (from %d to %d out of %d segments)", "Starting transcode for %s (from %d to %d out of %d segments)",
ts.file.Path, ts.file.Path,
@ -90,7 +79,7 @@ func (ts *TranscodeStream) run(start int32, end int32) error {
return nil return nil
} }
func (ts *TranscodeStream) GetIndex(client string) (string, error) { func (ts *Stream) GetIndex(client string) (string, error) {
index := `#EXTM3U index := `#EXTM3U
#EXT-X-VERSION:3 #EXT-X-VERSION:3
#EXT-X-PLAYLIST-TYPE:VOD #EXT-X-PLAYLIST-TYPE:VOD

View File

@ -3,10 +3,24 @@ package src
import "fmt" import "fmt"
type VideoStream struct { type VideoStream struct {
TranscodeStream Stream
quality Quality quality Quality
} }
func NewVideoStream(file *FileStream, quality Quality) (*VideoStream, error) {
ret := VideoStream{
Stream: Stream{
file: file,
Clients: make([]string, 4),
segments: make([]bool, len(file.Keyframes)),
},
quality: quality,
}
// Start the transcode up to the 100th segment (or less)
ret.run(0, Min(100, int32(len(file.Keyframes))))
return &ret, nil
}
func (vs *VideoStream) getOutPath() string { func (vs *VideoStream) getOutPath() string {
return fmt.Sprintf("%s/segment-%s-%%03d.ts", vs.file.Out, vs.quality) return fmt.Sprintf("%s/segment-%s-%%03d.ts", vs.file.Out, vs.quality)
} }