Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func convertToOpus(rd io.Reader) (io.Reader, error) {
- // Convert to a format that can be passed to dca-rs
- ffmpeg := exec.Command("ffmpeg", "-i", "pipe:0", "-f", "s16le", "-ar", "48000", "-ac", "2", "pipe:1")
- ffmpeg.Stdin = rd
- ffmpegout, err := ffmpeg.StdoutPipe()
- if err != nil {
- return nil, err
- }
- // Convert to opus
- dca := exec.Command("./dca-rs", "--raw", "-i", "pipe:0")
- dca.Stdin = ffmpegout
- dcaout, err := dca.StdoutPipe()
- dcabuf := bufio.NewReaderSize(dcaout, 1024)
- if err != nil {
- return nil, err
- }
- // Start ffmpeg
- err = ffmpeg.Start()
- if err != nil {
- return nil, err
- }
- // Start dca-rs
- err = dca.Start()
- if err != nil {
- return nil, err
- }
- // Returns a stream of opus data
- return dcabuf, nil
- }
Add Comment
Please, Sign In to add comment