Guest User

Untitled

a guest
Nov 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. func convertToOpus(rd io.Reader) (io.Reader, error) {
  2.  
  3. // Convert to a format that can be passed to dca-rs
  4. ffmpeg := exec.Command("ffmpeg", "-i", "pipe:0", "-f", "s16le", "-ar", "48000", "-ac", "2", "pipe:1")
  5. ffmpeg.Stdin = rd
  6. ffmpegout, err := ffmpeg.StdoutPipe()
  7. if err != nil {
  8. return nil, err
  9. }
  10.  
  11. // Convert to opus
  12. dca := exec.Command("./dca-rs", "--raw", "-i", "pipe:0")
  13. dca.Stdin = ffmpegout
  14. dcaout, err := dca.StdoutPipe()
  15. dcabuf := bufio.NewReaderSize(dcaout, 1024)
  16. if err != nil {
  17. return nil, err
  18. }
  19.  
  20. // Start ffmpeg
  21. err = ffmpeg.Start()
  22. if err != nil {
  23. return nil, err
  24. }
  25.  
  26. // Start dca-rs
  27. err = dca.Start()
  28. if err != nil {
  29. return nil, err
  30. }
  31.  
  32. // Returns a stream of opus data
  33. return dcabuf, nil
  34. }
Add Comment
Please, Sign In to add comment