Created
July 20, 2014 19:49
-
-
Save tpanum/374ca0a415a5d94ffcd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"log" | |
"os" | |
"os/exec" | |
"io/ioutil" | |
"bytes" | |
) | |
func main() { | |
fi, _ := ioutil.ReadFile("noir.aif") | |
runFFMPEGFromStdin(populateStdin(fi)) | |
} | |
func populateStdin(file []byte) func(io.WriteCloser) { | |
return func(stdin io.WriteCloser) { | |
defer stdin.Close() | |
io.Copy(stdin, bytes.NewReader(file)) | |
} | |
} | |
func runFFMPEGFromStdin(populate_stdin_func func(io.WriteCloser)) { | |
cmd := exec.Command("ffmpeg","-i","pipe:0","-ab","128k","-f","mp3","pipe:1") | |
stdin, err := cmd.StdinPipe() | |
if err != nil { | |
log.Panic(err) | |
} | |
stdout, err := cmd.StdoutPipe() | |
if err != nil { | |
log.Panic(err) | |
} | |
err = cmd.Start() | |
if err != nil { | |
log.Panic(err) | |
} | |
populate_stdin_func(stdin) | |
fo, _ := os.Create("output.mp3") | |
io.Copy(fo, stdout) | |
err = cmd.Wait() | |
if err != nil { | |
log.Panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment