Sometimes brain no work..
parent
e1de3e07e0
commit
ddf24071b0
|
@ -3,6 +3,7 @@ package ffmpeg
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -17,7 +18,6 @@ type FFmpeg struct {
|
||||||
Len time.Duration
|
Len time.Duration
|
||||||
Title string
|
Title string
|
||||||
Channel string
|
Channel string
|
||||||
err chan error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFFmpeg(uri string, sampleRate int, channels int) (ff *FFmpeg, err 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),
|
"-ar", strconv.Itoa(sampleRate),
|
||||||
"-ac", strconv.Itoa(channels),
|
"-ac", strconv.Itoa(channels),
|
||||||
"-af", "loudnorm=I=-16:LRA=11:TP=-1.5",
|
"-af", "loudnorm=I=-16:LRA=11:TP=-1.5",
|
||||||
|
"-threads", "4",
|
||||||
"pipe:1",
|
"pipe:1",
|
||||||
)
|
)
|
||||||
|
|
||||||
ff.Cmd.Stderr = os.Stdin
|
ff.Cmd.Stderr = os.Stdin
|
||||||
|
|
||||||
ff.Out = bytes.NewBuffer(make([]byte, 4096))
|
ff.Out = bytes.NewBuffer(make([]byte, 1024))
|
||||||
ff.Cmd.Stdout = ff.Out
|
ff.Cmd.Stdout = ff.Out
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -48,16 +49,19 @@ func NewFFmpeg(uri string, sampleRate int, channels int) (ff *FFmpeg, err error)
|
||||||
|
|
||||||
func (ff *FFmpeg) Start() error {
|
func (ff *FFmpeg) Start() error {
|
||||||
err := ff.Cmd.Start()
|
err := ff.Cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// We need to wait till the buffer starts filling up..
|
// We need to wait till the buffer starts filling up..
|
||||||
for ff.Out.Len() == 4096 {
|
for ff.Out.Len() == 1024 {
|
||||||
}
|
}
|
||||||
|
|
||||||
ff.Started = true
|
ff.Started = true
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err != nil {
|
// Wait till this is empty..
|
||||||
ff.err <- ff.Cmd.Wait()
|
log.Println(ff.Cmd.Wait())
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue