diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 78136d1..a148923 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -3,6 +3,7 @@ package ffmpeg import ( "bytes" "context" + "log" "os" "os/exec" "strconv" @@ -17,7 +18,6 @@ type FFmpeg struct { Len time.Duration Title string Channel string - err chan error } func NewFFmpeg(uri string, sampleRate int, channels int) (ff *FFmpeg, err error) { @@ -35,12 +35,13 @@ func NewFFmpeg(uri string, sampleRate int, channels int) (ff *FFmpeg, err error) "-ar", strconv.Itoa(sampleRate), "-ac", strconv.Itoa(channels), "-af", "loudnorm=I=-16:LRA=11:TP=-1.5", + "-threads", "4", "pipe:1", ) ff.Cmd.Stderr = os.Stdin - ff.Out = bytes.NewBuffer(make([]byte, 4096)) + ff.Out = bytes.NewBuffer(make([]byte, 1024)) ff.Cmd.Stdout = ff.Out return @@ -48,16 +49,19 @@ func NewFFmpeg(uri string, sampleRate int, channels int) (ff *FFmpeg, err error) func (ff *FFmpeg) Start() error { err := ff.Cmd.Start() + if err != nil { + return err + } // We need to wait till the buffer starts filling up.. - for ff.Out.Len() == 4096 { + for ff.Out.Len() == 1024 { } ff.Started = true + go func() { - if err != nil { - ff.err <- ff.Cmd.Wait() - } + // Wait till this is empty.. + log.Println(ff.Cmd.Wait()) }() return err