diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index 7fc1cd2d..ab660ac8 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -12,13 +12,13 @@ import ( "sync" ) -type TranscodeStream interface { +type StreamHandle interface { getTranscodeArgs(segments string) []string getOutPath() string } type Stream struct { - TranscodeStream + handle StreamHandle file *FileStream Clients []string // channel open if the segment is not ready. closed if ready. @@ -35,8 +35,9 @@ type Stream struct { lock sync.RWMutex } -func NewStream(file *FileStream) Stream { +func NewStream(file *FileStream, handle StreamHandle) Stream { ret := Stream{ + handle: handle, file: file, Clients: make([]string, 0), segments: make([]chan struct{}, len(file.Keyframes)), @@ -92,6 +93,12 @@ func (ts *Stream) run(start int32) error { } segments_str := strings.Join(segments, ",") + outpath := ts.handle.getOutPath() + err := os.MkdirAll(filepath.Dir(outpath), 0o644) + if err != nil { + return err + } + args := []string{ "-nostats", "-hide_banner", "-loglevel", "warning", "-copyts", @@ -100,7 +107,7 @@ func (ts *Stream) run(start int32) error { "-to", fmt.Sprintf("%.6f", ts.file.Keyframes[end]), "-i", ts.file.Path, } - args = append(args, ts.getTranscodeArgs(segments_str)...) + args = append(args, ts.handle.getTranscodeArgs(segments_str)...) args = append(args, []string{ "-f", "segment", "-segment_time_delta", "0.2", @@ -109,7 +116,7 @@ func (ts *Stream) run(start int32) error { "-segment_start_number", fmt.Sprint(start), "-segment_list_type", "flat", "-segment_list", "pipe:1", - ts.getOutPath(), + outpath, }...) cmd := exec.Command("ffmpeg", args...) diff --git a/transcoder/src/videostream.go b/transcoder/src/videostream.go index 7a7f322c..e692cb84 100644 --- a/transcoder/src/videostream.go +++ b/transcoder/src/videostream.go @@ -12,10 +12,10 @@ type VideoStream struct { func NewVideoStream(file *FileStream, quality Quality) *VideoStream { log.Printf("Creating a new video stream for %s in quality %s", file.Path, quality) - return &VideoStream{ - Stream: NewStream(file), - quality: quality, - } + ret := new(VideoStream) + ret.quality = quality + ret.Stream = NewStream(file, ret) + return ret } func (vs *VideoStream) getOutPath() string {