diff --git a/transcoder/src/filestream.go b/transcoder/src/filestream.go index 57d7ca07..cda4282d 100644 --- a/transcoder/src/filestream.go +++ b/transcoder/src/filestream.go @@ -17,7 +17,8 @@ type FileStream struct { Keyframes []float64 CanTransmux bool Info *MediaInfo - streams map[Quality]*TranscodeStream + streams map[Quality]*VideoStream + // audios map[uint32]*AudioStream } func GetOutPath() string { @@ -56,7 +57,7 @@ func NewFileStream(path string) (*FileStream, error) { Keyframes: keyframes, CanTransmux: can_transmux, Info: info.info, - streams: make(map[Quality]*TranscodeStream), + streams: make(map[Quality]*VideoStream), }, nil } diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index e8ec0dbb..a2be4587 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -16,13 +16,13 @@ func Min(a int32, b int32) int32 { return b } -type Stream interface { +type TranscodeStream interface { getTranscodeArgs(segments string) []string getOutPath() string } -type TranscodeStream struct { - Stream +type Stream struct { + TranscodeStream file *FileStream Clients []string // true if the segment at given index is completed/transcoded, false otherwise @@ -33,18 +33,7 @@ type TranscodeStream struct { // TODO: add ffmpeg process } -func NewStream(file *FileStream) (*TranscodeStream, 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 { +func (ts *Stream) run(start int32, end int32) error { log.Printf( "Starting transcode for %s (from %d to %d out of %d segments)", ts.file.Path, @@ -90,7 +79,7 @@ func (ts *TranscodeStream) run(start int32, end int32) error { return nil } -func (ts *TranscodeStream) GetIndex(client string) (string, error) { +func (ts *Stream) GetIndex(client string) (string, error) { index := `#EXTM3U #EXT-X-VERSION:3 #EXT-X-PLAYLIST-TYPE:VOD diff --git a/transcoder/src/videostream.go b/transcoder/src/videostream.go index 284ca795..63cfb9c6 100644 --- a/transcoder/src/videostream.go +++ b/transcoder/src/videostream.go @@ -3,10 +3,24 @@ package src import "fmt" type VideoStream struct { - TranscodeStream + Stream 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 { return fmt.Sprintf("%s/segment-%s-%%03d.ts", vs.file.Out, vs.quality) }