Sometimes brain no work..
parent
e1de3e07e0
commit
ddf24071b0
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue