How do I pipe an HTTP response like in NodeJS. Here is the snippet I am using in NodeJS:
request({
url: audio_file_url,
}).pipe(ffmpeg_process.stdin);
How can I achieve the same result in Go?
I am trying to pipe a audio stream from HTTP into an FFmpeg process so that it converts it on the fly and returns the converted file back to the client.
Just so its clear to everyone here is my source code so far:
func encodeAudio(w http.ResponseWriter, req *http.Request) {
path, err := exec.LookPath("youtube-dl")
if err != nil {
log.Fatal("LookPath: ", err)
}
path_ff, err_ff := exec.LookPath("ffmpeg")
if err != nil {
log.Fatal("LookPath: ", err_ff)
}
streamLink := exec.Command(path,"-f", "140", "-g", "https://www.youtube.com/watch?v=VIDEOID")
var out bytes.Buffer
streamLink.Stdout = &out
cmdFF := exec.Command(path_ff, "-i", "pipe:0", "-acodec", "libmp3lame", "-f", "mp3", "-")
resp, err := http.Get(out.String())
if err != nil {
log.Fatal(err)
}
// pr, pw := io.Pipe()
defer resp.Body.Close()
cmdFF.Stdin = resp.Body
cmdFF.Stdout = w
streamLink.Run()
//get ffmpeg running in another goroutine to receive data
errCh := make(chan error, 1)
go func() {
errCh <- cmdFF.Run()
}()
// close the pipeline to signal the end of the stream
// pw.Close()
// pr.Close()
// check for an error from ffmpeg
if err := <-errCh; err != nil {
// ff error
}
}
Error: 2014/07/29 23:04:02 Get : unsupported protocol scheme ""
Here's a possible answer using a standard http handler function. I don't have the programs to test this directly, but it does work with some simple shell commands standing in as a proxy.