-
-
Save Albinzr/d24110f0ff68e89a7fe822ec846c9d84 to your computer and use it in GitHub Desktop.
This file contains hidden or 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